- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I'm trying to learn how to use a counter, I would like to fire an interrupt (set on and then off a RGB LED) after pushing for three times an external switch.
I can't understand what's wrong. Sometimes the interrupt fires after three times,sometimes after twice or one time I push the switch. I think that should be some problems with the parameters I set on the counter.
Please help me.
This is the code:
#include "project.h"
CY_ISR(ISR_COUNTER_HANDLER){
LED_BLU_Write(1);
LED_RED_Write(1);
CyDelay(500);
LED_BLU_Write(!LED_BLU_Read());
LED_RED_Write(!LED_RED_Read());
Counter_ReadStatusRegister();
}
int main(void){
CyGlobalIntEnable;
Counter_Start();
ISR_COUNTER_StartEx(ISR_COUNTER_HANDLER);
for(;;)
{ }
}
Solved! Go to Solution.
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your mechanical switch will definitively deliver some spikes that the counter will see. Reducing the counter clock to 100Hz will help.
It is easier for us to help when you provide us with your complete project workspace archive. Use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting .zip.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your mechanical switch will definitively deliver some spikes that the counter will see. Reducing the counter clock to 100Hz will help.
It is easier for us to help when you provide us with your complete project workspace archive. Use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting .zip.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
marcogiorio,
Since it is low-speed requirement (manually pushing a button), it is better to use software-defined debouncer and counter instead of UDB components, which are intended for high-speed operation (MHz). Consider using a button-switch debouncer component for this purpose:
ButtonSw32: button switch debouncer component
Just add a counter in the main loop, which increments on each button pressed event.
/odissey1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content