Event counting on TIOA1

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

Although it mentions "Event counting" the datasheet for SAM4E16E doesn't mention how to setup this case for Timer Counter peripheral. Would it be possible to count pulses on TIOA1 using timer capture? Unfortunately TCKL0 cannot be used as it was assigned to other peripherals and our schematic cannot be changed at the moment. I could setup an interrupt as input GPIO pin for the counting but I would like to avoid it if possible.

 

Thank you in advance,

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In section 38.6.3, Clock Selection, you see that you can take TCLK0, 1 or 2 for any of the 3 timers of TC0 Block.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Unfortunately the pulses come in via PA15 (TIAO1) input pin. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TIOA1 ca go to XC0 (figure 38-2), configurable in TC0XC0S bits of TC_BMR register

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TIOA1 ca go to XC0 (figure 38-2), configurable in TC0XC0S bits of TC_BMR register

Based on your suggestion I tried the following code:

 

        /* Configure TC0-1 timer counter */
        pmc_enable_periph_clk(ID_TC0);            
        
        //TIOA1
        ioport_set_pin_peripheral_mode(PIO_PA15_IDX, IOPORT_MODE_MUX_B);
        
        tc_set_block_mode(TC0, TC_BMR_TC0XC0S_TIOA1); 
        
        // Init TC to capture mode.
        tc_init(TC0, 0,  ((TC_CMR_TCCLKS_XC0 << TC_CMR_TCCLKS_Pos) && TC_CMR_TCCLKS_Msk);// Clock Selection from XC0 input  

        tc_start(TC0, 0);

 

Then I use tc_read_cv(TC0,0) to get the counter value but I get increasing pulses at much higher frequency (12000000) than the input frequency from signal generator (30Hz). I'm not using any other channels from Timer Counter so it appears some incorrect clock is applied to TIOA1. Any idea what I'm doing wrong here?

 

Last Edited: Fri. Jan 22, 2016 - 10:48 AM