Event Counter in C Propeller P8X32A - New user needs help
Sparko
Posts: 8
I would like to add an event counter to an existing C program I have written. Perhaps the simplest use of the Propeller counter but I am stuck on getting started.
I realize the counter modes need to be set first. Mode NEGEDGE %01110
The counter reading the pulse as it goes negative would be preferred.
The counter needs to know what input to look at.
Reading the tally, decrementing the tally and clearing the tally is necessary.
I found simpletools.h by Andy Lindsay. A great resource for the general idea but does not seem to cover this specific mode.
Any help with any of the above would be very much appreciated.
Thanks in advance
Sparko
I realize the counter modes need to be set first. Mode NEGEDGE %01110
The counter reading the pulse as it goes negative would be preferred.
The counter needs to know what input to look at.
Reading the tally, decrementing the tally and clearing the tally is necessary.
I found simpletools.h by Andy Lindsay. A great resource for the general idea but does not seem to cover this specific mode.
Any help with any of the above would be very much appreciated.
Thanks in advance
Sparko
Comments
Mode %01110 = hex 0E, so in your case a possible C snippet could look like:
Andy
Edit: you need to include <propeller.h> for that
Thanks, Andy, Ariba, Mike.
Please give me advice on the best way to debounce input PIN0 in this kind of application.
Thanks again
Sparko
A capacitor debouncer might also work for this. The circuit is simple, and you can either experiment with the component values, or arrive at it using standard RC tables.
First, welcome to the forum.
Next, it is better to post propeller questions in the propeller 1 forum. Many of us don't read the general forum as often because here is about other things no necessarily prop related.
Now to your question. You need to give us more info about what you are trying to count and speed.
It seems you are using a switch which are notoriously noisy, hence the need to denounce. If you need to count some form of mechanical switching, you wil either have to use a hardware denounce circuit, or use a software debounce and not use counters.
So we need more info to help.
I appreciate the information you provided. I brought the debounce help request over to propeller 1 as you suggested.
I am not sure what info might be needed but here is what I see and know about the requirements for speed ect.
The pulse goes from high to low (zero volts) and noise can be seen for about the first 1ms or less. After the 100ms the level returns to 3.5V and stays there for at least 50ms. No subsequent pulse can occur for at least 50ms.
I tried a capacitor first but did not get good results. Could have been that the value or type of capacitor was not correct.
I added a software loop that checks for a change in input level over a 50ms period and debounce was no longer a problem. However this ties up the uP for 50ms. There are other operations that must be ready to proceed and cannot be held up.
Your suggestion to not use a counter may be the way to go. One cog accepting the input and performing the debounce outside and independent of the main program may be best.
Thanks
Sparko