PinCapture

I don’t actually need the up button. I’m just learning/experimenting how I can use this to capture a specified amount of pulses on any IO. I use the up button to simulate pulses by clicking. This is easier than hooking up a real device that generates pulses to an IO.

According to the manual CAP3(0) for timer 3 is on P0.23 – IO8 on the cobra…But its AD0 connected to the touch panel and the CAP3(1) is connected to AD1…connected to… touch panel
so you can’t use Timer 3

Timer 2 (The one you’re using) CAP2(0) is on P0.4 " down button "
CAP2(1) is on PO.5 " Right button "

PINSEL0 10,11

Cheers Ian

Hi, I still don’t know how and if I can use the UP button in this scenario. Could anyone tell me how and if it is possible to use any interruptable IO. Thanx!

Digging in processor registers is very advanced topic usually. Why not just use the code as is?

Hi Gus, Thank you for your reply.

The managed driver code example is great but only works for P0.4 (IO0) as far as I know. Could you please tell how make this code work for any other suitable IO? I tried changing the PINSEL register and BITS. I just can’t get any other IO to work.

Thanx!

It will not work on any io. This codecdepends on a hardware inside the processor as explained in the book. Hay not just use that pin?

Hi,

I think my intentions are not entirely clear. Let me clarify.

I want to hook up external devices that generate pulses to any suitable IO pin. When a device has generated an x amount of pulses I want to do something else. I was hoping to be able to use the following code example:


//Start counting 100 pulses from pin IOx within 20000 ms while max time between pulses is 1000 ms

CountPulses(IOx, 100, 20000, 1000);

//Wait for all pulses to be counted or timeout to expire

ThenDoSomethingElse();


Surely this can’t be that difficult. But I can’t seem to get it to work.

Ok, why not use the code provided with the pin that is capable of counting pulses? You can not use any pin, it has to be a specific pin.

If your pulses are slow, then you can use InterruptPort and count pulses that way on any IO

Hi Gus,

Thank you for the reply.

I do know to what pins the pulse devices are connected. I just can’t get any other IO to work other than the IO0 in the example. I just need to know what needs to be changed in the example code and into what it has to be changed. How do i change the code to count pulses on these pins IO9, IO17, IO19, IO21, IO23, IO30, IO33, IO35, IO36, IO38??

Thanx!

Are you saying this can only be used on a single pin and no other pin can ever be used? So you would only be able to count pulses of one device? I can hardly imagine that. If so that would be a real pity.

No, we just saying that the code you are using will work with specific pin only. But as Gus said:

I know that the code will only work for a specific pin. I just want to know how I change the code to work with another pin. My pulses are fast so I want to use the example code.

Thanx!

How fast?

Somewhere between 10 and 500 per second.

10 and 500 is not fast. That can be done using InterruptPort and you can do it on any pin and on multiple pins simultaneously.

Ok thanx. I tried the following while loop but it blocks my program and interrupts are never hit. Any ideas?



void Count(int count)
{
   while (count < pulses)
   {
      Thread.Sleep(100);
   }
}

void _interruptPort_OnInterrupt(uint port, uint state, DateTime timestamp)
{
   pulses++;
}

how did you initialise the interrupt?

@ burningwheels. Should this be reversed? Wait until pulses exceed count.

void Count(int count)
{
   while (pulses < count) // change here.
   {
      Thread.Sleep(100);
   }
}

This is how I initialised the interrupt.


InterruptPort buttonUp = new InterruptPort(EMX.Pin.IO4, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
buttonUp.OnInterrupt += new NativeEventHandler(OnInterrupt);

The event gets hit normally when I don’t have a loop running that keeps track of pulses. When the loop is running the interrupts never get hit. Seems that the loop is using all resources somehow. While I still use thread.sleep.

Any ideas?