I am new to SAM4S and ASF. I am hoping that somebody can help me to implement a quadrature decoder on my SAM4S Xplained Pro board. So far I have confirmed that TC's work in general, I have been able to create interrupts, interrupt handling routines, and have confirmed that I can use TIOA and TIOB as inputs to a TC. But I am struggling to find the correct ASF functions to implement the correct registers in the correct order for a quad decoder. Here is a code snippet that I have been playing with.
isr_counter and CV_Q are static uint32's. isr_counter increments so I know that the ISR is called. CV_Q never changes though.
Code: Select all
// Configuration function for the quadrature decoder.
static void tc_config_quad(void) {
tc_set_block_mode(TC0, TC_BMR_QDEN | TC_BMR_POSEN);
tc_init(TC0,0,TC_CMR_TCCLKS_XC0);
tc_sync_trigger(TC0);
tc_start(TC0,0); // is this required? what about CLKEN in CCR?
}
// Interrupt service routine
void TC_Handler(void)
{
CV_Q = TC0->TC_CHANNEL[0].TC_CV;
isr_counter++;
}
forum/viewtopic.php/p,40421/#p40421
I would be grateful for any advice, tutorials, examples. Do I need to call the ASF functions in some order (e.g. tc_sync_trigger() before tc_start() )? I have found examples in the API documentation for XMEGA, but not SAM ... am I missing something?
Thanks.