I may test this later when I get a chance. I only write this incomplete code to get you started.
Please let me know how it goes…
You need these files
Manual: http://www.keil.com/dd/docs/datashts/philips/lpc23xx_um.pdf
Datasheet: http://www.nxp.com/documents/data_sheet/LPC2478.pdf
EMX pinout: http://www.ghielectronics.com/downloads/EMX/EMX_Broch_Pinout.pdf
First, select a free timer. I know GHI used timer0 and possibly timer1 so 2 and 3 should be free. I will just use 3 and leave 2 for a sec.
Now, we need to select what pin on the processor to use for timer3 pin capture feature. According to datasheet, the pins are same as analog0 and analog1 but these are used for touch screen on FEZ Cobra(EMX). These pins would be perfect for Domino so maybe keep 2 options in your class where the user will select to use these pins on those devices.
Now for cobra, we will need to check timer2 which looks like it is connected to P0.4 and p0.5. What a good luck we have as P0.4 (IO0) is connected to the down button on FEZ Cobra. This means I can use the button to test what I am writing.
Here is some sample code and also take a look at datasheet please
Before you do anything, you need to enable power to the timer you are suing. I would say just enable both timer2 and timer3 anyways.
Register PCONP = new Register(0xE01FC0C4);
PCONP.SetBits((1 << 22) | (1 << 23));//enable timer2 and timer3
Timer Control Register
Register T2TCR = new Register(0xE0070004);
// To enable timer/counter
T2TCR.Write(1);
// to reset the counter
T2TCR.SetBits((1 << 1));
T2TCR.ClearBits((1 << 1));
Count Control Register
Register T2CTCR = new Register(0xE0070070);
T2CTCR.Write((0<<2) | (2<<0));//count on falling edge and use CAPn.1
if you want o use rising edge then change it to
T2CTCR.Write((0<<2) | (1<<0));//count on rising edge and use CAPn.1
So timer is powered on and configured but we still need to map the pin to the timer function. Note that this code now is directly related to what processor pin is used. We are using P0.4 and we want to set it to CAP2.0
Register PINSEL0 = new Register(0xE002C000);
PINSEL0.SetBits((3<<8));//set bits 8 and 9
We are done but where do we read the count?
Register T2TC = new Register(0xE0070008);
uint count = T2TC.Read();
================
Again, I only explained this while looking at datasheet but I never tested any of this code and possible put the wrong register address so double check everything please.
Waiting to hear how it went … ![:slight_smile: :slight_smile:](https://forums.ghielectronics.com/images/emoji/twitter/slight_smile.png?v=12)