Hi, I have modified the code from following thread (http://www.tinyclr.com/forum/10/1458/#/2/)
My Problem is now that I want to use the Counter of the Timer1, Timer2 works without any problems.
May any body know which register is set wrong.
For Timer1 I want to use IO16 and for Timer2 IO0.
I have written an Abstract Class to use the counter.
using GHIElectronics.NETMF.Hardware.LowLevel;
public abstract class S0
{
public static Config Timer2 = new Config()
{
PCONP = 0xE01FC0C4,
PCONP_mask = (1 << 22), // enable timer2
PINSEL = 0xE002C000,
PINSEL_mask = (3 << 8), // Select IO0 on EMX CAP2.0
CCR = 0xE0070028,
CCR_mask = 0x07, // should be 0 for a counter
CTCR = 0xE0070070,
CTCR_mask = (2 << 0 | 0 << 2), // count on falling edge and use CAPn.0, (2<<0)|(0<<2)
MCR = 0xE0070014,
MCR_mask = 0, // Don't do anything on match
PR = 0xE007000C,
PR_mask = 0, // set prescale to 0
TC = 0xE0070008,
TCR = 0xE0070004,
TCR_mask = 1 // To enable timer/counter
};
public static Config Timer1 = new Config()
{
PCONP = 0xE01FC0C4,
PCONP_mask = (1 << 2), // enable timer1
PINSEL = 0xE002C00C,
PINSEL_mask = (3 << 7), // Select IO16 on EMX CAP1.1
CCR = 0xE0008028,
CCR_mask = 0x38, // should be 0 for a counter
CTCR = 0xE0008070,
CTCR_mask = (2 << 0 | 1 << 2),
MCR = 0xE0008014,
MCR_mask = 0,
PR = 0xE000800C,
PR_mask = 0,
TC = 0xE0008008,
TCR = 0xE0008004,
TCR_mask = 1
};
private Config configuration;
public S0(Config configuration)
{
this.configuration = configuration;
this.InitCounter();
}
protected void ResetCounter()
{
Register tcr = new Register(this.configuration.TCR);
// To reset the counter
tcr.SetBits((1 << 1));
tcr.ClearBits((1 << 1));
}
protected uint GetCount()
{
Register tc = new Register(this.configuration.TC);
return tc.Read();
}
private void InitCounter()
{
Register pconp = new Register(this.configuration.PCONP);
pconp.SetBits(this.configuration.PCONP_mask);
Register pinsel = new Register(this.configuration.PINSEL);
pinsel.SetBits(this.configuration.PINSEL_mask);
Register tcr = new Register(this.configuration.TCR);
tcr.Write(this.configuration.TCR_mask);
Register pr = new Register(this.configuration.PR);
pr.Write(this.configuration.PR_mask);
Register ctcr = new Register(this.configuration.CTCR);
ctcr.Write(this.configuration.CTCR_mask);
Register ccr = new Register(this.configuration.CCR);
ccr.ClearBits(this.configuration.CCR_mask);
Register mcr = new Register(this.configuration.MCR);
mcr.Write(this.configuration.MCR_mask);
this.ResetCounter();
}
public struct Config
{
public uint PCONP;
public uint PCONP_mask;
public uint PINSEL;
public uint PINSEL_mask;
public uint TCR;
public uint TCR_mask;
public uint PR;
public uint PR_mask;
public uint CTCR;
public uint CTCR_mask;
public uint CCR;
public uint CCR_mask;
public uint MCR;
public uint MCR_mask;
public uint TC;
}
}