Go Down

Topic: Arduino Due: Configuring TC2 to CPCS IRQ When External Clock Fed into TCLK8 (Read 3023 times) previous topic - next topic


Salute Arduinisti,

     I'm trying, to no avail, to configure the ATSAM3X8E's Timer Counter 2 to use an external clock source (XC2 via TCLK8) to perform that RC compare feature (in other words, generate the CPCS interrupt when REG_TC2_CV2 reaches the value REG_TC2_RC2).  I'm using a function generator attached to PD9 (Arduino pin 30) as the external clock.

    I've attached code.  Any ideas?

    Thanks in advance!



Just for fun I connected the external timer pins for TC0, TC1, and TC2 together (that's PA4, PA22, and PD9 in series (Arduino pins 59, 57, and 30, respectively)).

I see no CPCS interrupts for any of TC0, TC1, or TC2, though I do see ETRGS at the function generator frequency.

Code and log are attached.


So for posterity, I've not been able to generate a CPCS interrupt with the external clock.  The only workaround I've found is to use the corresponding PIO interrupt to count down in software what would have been the value loaded into RC.

Code and log attached.

Similar issues that have gone unresolved are:



TCLK8 is on channel 2. However, CPCS can only generate an interrupt with channels 0 or 1.

From 37.6.13
A compare function (using TC_RC register) is available on channel 0 (speed/position) or channel 1 (rotation) and can generate an interrupt by means of the CPCS flag in the TC_SR registers.


Thanks for the reply!

I guess your answer would make sense if I were using the quadrature decoder, but I'm using the "waveform" mode shown in Figure 36-6 of the 23-Mar-15 version of the data sheet that Atmel uploaded about two weeks ago (see http://www.atmel.com/Images/Atmel-11057-32-bit-Cortex-M3-Microcontroller-SAM3X-SAM3A_Datasheet.pdf)

Figure 36-6 clearly shows all three XC0, XC1, and XC2 external clock sources feeding into two multiplexers (in the upper left hand corner of the diagram if you've oriented the sheet "landscape") for which the signals are selected by TCCLKS and BURST.

I'd love to hear about the setup and results of your experimentation with the timer counters.


Thanks for the datasheet update link.

Well, hopefully it could work with all channels while using the waveform mode (I haven't done any testing with this mode yet, only PWM). At the beginning of my PWM setup, I needed to work with these registers:
Code: [Select]
  REG_PIOC_PDR = 0x3FC;  //B1111111100, PIO Disable Register
  REG_PIOC_ABSR = REG_PIOC_ABSR | 0x3FCu; //B1111111100, Peripheral AB Select Register
  REG_PMC_PCER1 = REG_PMC_PCER1 | 16; //Peripheral Clock Enable Register 1 (activate clock for PWM, id36, bit5 of PMC_PCSR1)
  REG_PWM_ENA = REG_PWM_SR | B1111; //PWM Enable Register | PWM Status Register (activate channels 0,1,2,3)

Not sure, but you may need to set the appropriate bits in REG_PMC_PCER0 and REG_PMC_PCER1 (re instance ID 27-35 for TC0-8).


Not sure, but you may need to set the appropriate bits in REG_PMC_PCER0 and REG_PMC_PCER1 (re instance ID 27-35 for TC0-8).
The libsam call pmc_enable_periph_clk(ID_TC8) already takes care of this.

For those who wonder what libsam is, it is the Atmel library that used to be under hardware/arduino/sam/system/libsam in the Arduino distribution, but in the true tradition of making things more complicated than they need to be, it moved to %USERPROFILE%/Application Data/Arduino15/packages/arduino/hardware/sam/1.6.2/system/libsam in 1.6.2. 



So it appears to be operator error:  Remove TC_CMR_BURST_XC2 from TC2UsingExternalClock.ino and the sketch works as intended.

I guess I don't feel so bad given that the sample code has been downloaded by nine people who missed this detail as I did.


I am trying to measure the clkout signal from codec WM8731 on the pin30 as mentioned above but I get no updates in the print statement. Everything reads zero. Could some one help me solve this. The CLKOUT signal is a 11Mhz (mega hz) signal.


I gave pin 30 a signal high from pin 13 which toggles every second but still all that the printf statements reads is 0.

Go Up