Many main control chips have timers. The use of timers is nothing more than setting a timer, generating an interrupt when the time is up, and then doing something in the interrupt. If you follow this line of thought, it seems that the C6000 timer cannot escape this pattern. Of course, the C6000 timer can also count the number of external events and generate pulse signals. The difference in what the timer does lies in the configuration of the control register, which is configured according to the functional requirements and the tasks that can be completed.
In my project, it is also used as an ordinary timer, and so many functions are not developed. The implementation method is as follows:
First, it needs to be initialized. The initialization process has been introduced in the previous section. The code is as follows:
void TIMER_Init(void)
{
TIMER_Config myTimerConfig;
hTimer = TIMER_open(TIMER_DEV0, TIMER_OPEN_RESET);
TIMER_getConfig( hTimer, &myTimerConfig);
myTimerConfig.ctl &= 0xff3f;
myTimerConfig.ctl |= 0x3c0;
myTimerConfig.prd = 0x200;
myTimerConfig.cnt = 0x00000000;
TIMER_config(hTimer, &myTimerConfig);
IRQ_enable(TIMER_getEventId(hTimer));
}
The timing period register prd can modify the timing period as needed.
Then complete the tasks that need to be completed in the timing interrupt interrupt void timer0_isr().
Finally, it should be noted that this interrupt should be added to the interrupt vector list.
In the main control chip, the timer interrupt is an important content, but it does not seem to be so troublesome to implement it in C6000. However, if you want to see the interrupt effect, using printf will have a certain time delay. If you also consider the influence of other factors in the system, the interrupt time is not only affected by prd. The specific situation needs to be reflected in the actual program.
|