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.
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.
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.
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.
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.
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:
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).
dlloyd:
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.
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.