- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
There could be many approach to this.
I tried a couple of samples with CY8CKIT-059.
(1) Using a timer component (timer_intr_200226A)
(2) Using a SysTick (timer) (timer_intr_200226B)
I imagine that what you intended was (1), but as a timer is a precious resource
it may be smarter to use ARM core built-in "SysTick" which can be used without consuming a timer component.
(1) Using a timer component
schematic
pins
main.c
================
#include "project.h"
volatile int pit_flag = 0 ;
CY_ISR(timer_isr)
{
Timer_ReadStatusRegister() ;
pit_flag = 1 ;
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
isr_timer_ClearPending() ;
isr_timer_StartEx(timer_isr) ;
Timer_Start() ;
for(;;)
{
if (pit_flag) {
pit_flag = 0 ;
LED_Write( !LED_Read() ) ;
}
}
}
================
Note: You could do "LED_Write( !LED_Read()) inside the isr,
but in general, I would recommend to make an isr as short as possible.
(2) Using a SysTick (timer)
schematic
pins
main.c
==============
#include "project.h"
#define PIT_PERIOD 500 // 500ms = 0.5 sec
volatile int pit_flag = 0 ;
volatile int tick_count = 0 ;
CY_ISR(timer_isr)
{
tick_count++ ;
if (tick_count >= PIT_PERIOD) {
tick_count = 0 ;
pit_flag = 1 ;
}
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
CySysTickStart() ;
CySysTickSetCallback(0, timer_isr) ;
for(;;)
{
if (pit_flag) {
pit_flag = 0 ;
LED_Write( !LED_Read() ) ;
}
}
}
==============
Note: In the default configuration, the interrupt of SysTick comes every 1ms,
so I needed to count it up to the required time. This time 500 = 0.5 sec.
moto