PinCapture

Hi,

Is it possible to do a PinCapture on EMX? I want to accurately read a fixed set of pulses and after that let the program continue.

Thanx!

Hi BurningWheels

You can, but you have to manipulate the processor registers with the GHI Register class. See page 2 (arround the middle of the page) in this post:
[url]http://www.tinyclr.com/forum/10/1458/#/2/[/url]

Also you should read up on the processor, regarding the match(MAT) registers.

And finally get the the beta firmware from this post:
[url]http://www.tinyclr.com/forum/10/1661/#/1/[/url]
If you don’t use this firmware you might notice some delays in you sampling.

I my self am using this approach and it works great.

Seems like a bit of a workaround. Why is there no PinCapture method for EMX while there was one for Embedded Master? Seems like a step backward. :frowning: I’ll try the register class never the less. Thanx! :wink:

That is not EM vs EMX, it is 3.0 vs 4.0 firmware…it was dropped in 4.0 due to the fact that it is a blocking and not favorable option for many users. We may replace it with a non-blocking class or put it back but for now you can use the hardware to count pulses.

It would be nice to see a non blocking version of PinCaputure. Thanks for the response!

Could I somehow use the blocking pincaputure version from 3.0 on a 4.0 firmware? Do you have the code for the class so I can use this. I don’t necessarily need a non blocking version.

It was developed natively so it is nothing that you can just drop in.

Have you seen this? I bet you haven’t :wink:

Hi,

I’m trying to use the following code from the managed drivers example. What would be the value of the register for the up button on EMX? I know it’s EMX IO4 and LPC2478
H/W Name P2.30. How does this translate to a register? In short what should be the value of 0xE002C000 for IO4?

// Select IO0 on EMX CAP2.0
Register PINSEL0 = new Register(0xE002C000);
PINSEL0.SetBits((3 << 8));//set bits 8 and 9

Thanx!

You need to look at LPC2478 user manual. It has addresses information for all registers:

http://ics.nxp.com/support/documents/microcontrollers/pdf/user.manual.lpc24xx.pdf

Page 185.
PINSEL5
0xE002C014 bits 29.28

Ah. I see! Thank you!

And how do i translate the bits part?

PINSEL0.SetBits((3<<8));//set bits 8 and 9

What does 3<<8 mean? How do I set e.g. 28 and 29??

(3<<8) Means you are taking the number 3 and shifting it left by 8 bit positions.

PINSEL0.SetBits((1<<28) | (1<<29));

This is explained in the book, did you look? :slight_smile:

Decimal - Binary
0-00000000
1-00000001
2-00000010
3-00000011

Shift
3<<1 - 00000110
3<<2 - 00001100

You need to set bits 28 and 29:
3<<28 - 0011 0000 0000 0000 0000 0000 0000 0000

Thank for your replies. I can’t get it to work. I tried the next code to count the presses on the up button (IO4) on EMX Dev board.

Not working:


                Register PCONP = new Register(0xE01FC0C4);
                PCONP.SetBits(1 << 22);//enable timer2 

                // Select IO4 on EMX
                Register PINSEL5 = new Register(0xE002C014);
                PINSEL5.SetBits((1 << 28) | (1 << 29));
                //PINSEL5.SetBits((3 << 28)); Also tried this

                
                // To enable timer/counter
                Register T2TCR = new Register(0xE0070004);
                T2TCR.Write(1);

                // set prescale to 0
                Register T2PR = new Register(0xE007000C);
                T2PR.Write(0);

                Register T2CTCR = new Register(0xE0070070);
                T2CTCR.Write(2 << 0 | 0 << 2);//count on 
                // should be 0 for a counter
                Register T2CCR = new Register(0xE0070028);
                T2CCR.ClearBits(0x07);

                // Don't do anything on match
                Register T2MCR = new Register(0xE0070014);
                T2MCR.Write(0);

                // To reset the counter
                T2TCR.SetBits((1 << 1));
                T2TCR.ClearBits((1 << 1));

                Register T2TC = new Register(0xE0070008);
                uint count = 0;
                while (count < ticks)
                {
                    count = T2TC.Read();
                    Thread.Sleep(100);
                }

It does work for button down (IO0) when using this code:


Register PINSEL0 = new Register(0xE002C000);
PINSEL0.SetBits((3 << 8));//set bits 8 and 9

What am I doing wrong?

I’m looking at the manual for the chip and I don’t think 28,29 on PINSEL5 corresponds to IO4… GPIO 2.5 relates to PINSEL4 10 ,11…

Can someone else check this…

Cheers Ian

PINSEL5 28,29 is for P2.30 of the processor. But I see what you mean:

  1. Cobra schematic shows that it is P2.5
    http://www.tinyclr.com/downloads/Cobra/FEZ%20Cobra_sch.pdf

  2. EMX brochure shows it as P2.30
    http://www.ghielectronics.com/downloads/EMX/EMX_Broch_Pinout.pdf

Gus can you clarify which one is correct?

According to the different documentation:

  1. EMX_DevSys_sch.pdf. IO4 = P2.5
  2. EMX_Broch_Pinout.pdf IO4 = P2.30

I am using a EMX development board.

I tried the following:


//PINSEL4 BITS 10 & 11
Register PINSEL4 = new Register(0xE002C010);
PINSEL4.SetBits((1 << 10) | (1 << 11));

And


//PINSEL5 BITS 28 & 29
Register PINSEL5 = new Register(0xE002C014);
PINSEL5.SetBits((1 << 28) | (1 << 29));

Both pieces of code don’t work.

Any ideas?

In the LPC2478 manual it has P2(5) as having a second function PWM6… But on the cobra it has none… so can you cross check with the emx dev board.

Very confusing.

Also on the EMX dev board 1.3 … its the same pinout as the cobra.
In the PDF (pinouts ) IO4 is still up button

Cheers Ian

I notice in the manual of the processor that P2.30 is not specified as a Capture input for any Timer. Could this be the problem? Can I only use IO’s which are a capture input? I also notice that each timer has multiple channels. How do I choose a different channel? I thinks it’s all a bit confusing. A function like PinCapture would be a God’s gift.

Lets go back a little bit.

Why do you need register for the UP button at the first place?