Hi I am trying to get a 12 Mhz clock out of the Board in the title. I am trying to follow this post but I am not getting anything from my program. Here is my code, I am a bit lost so perhaps you guys can help me see what I am doing wrong. I am using pin 34 because the PA19 thing they use in their example is mapped to 34 on grand central (I think ) but otherwise I have no preference on pin.
void setup()
{
pinMode(35, OUTPUT);
// Activate timer TC3
// CLK_TC3_APB
MCLK->APBBMASK.reg |= MCLK_APBBMASK_TC3;
// Set up the generic clock (GCLK7)
GCLK->GENCTRL[7].reg =
// Divide the 48MHz clock source by divisor 1: 48MHz/1 = 48MHz
GCLK_GENCTRL_DIV(4) |
// Set the duty cycle to 50/50 HIGH/LOW
GCLK_GENCTRL_IDC |
// Enable GCLK7
GCLK_GENCTRL_GENEN |
// Select 48MHz DFLL clock source
GCLK_GENCTRL_SRC_DFLL;
// Select 100MHz DPLL clock source
//GCLK_GENCTRL_SRC_DPLL1;
// Select 120MHz DPLL clock source
// GCLK_GENCTRL_SRC_DPLL0;
// Wait for synchronization
while (GCLK->SYNCBUSY.bit.GENCTRL7);
// for PCHCTRL numbers have a look at Table 14-9. PCHCTRLm Mapping page168ff
// http://ww1.microchip.com/downloads/en/DeviceDoc/60001507C.pdf#page=169&zoom=page-width,-8,696
GCLK->PCHCTRL[26].reg =
// Enable the TC3 peripheral channel
GCLK_PCHCTRL_CHEN |
// Connect generic clock 7 to TC3
GCLK_PCHCTRL_GEN_GCLK7;
// Enable the peripheral multiplexer on pin D9
PORT->Group[g_APinDescription[34].ulPort].
PINCFG[g_APinDescription[34].ulPin].bit.PMUXEN = 1;
// Set the D9 (PORT_PA19) peripheral multiplexer to
// peripheral (odd port number) E(6): TC3, Channel 1
// check if you need even or odd PMUX!!!
// http://forum.arduino.cc/index.php?topic=589655.msg4064311#msg4064311
PORT->Group[g_APinDescription[34].ulPort].
PMUX[g_APinDescription[34].ulPin >> 1].reg |= PORT_PMUX_PMUXE(4);
TC3->COUNT8.CTRLA.reg =
// Set prescaler to 1, 48MHz/1 = 48MHz
// Set prescaler to 1, 120MHz/1 = 120MHz
// TC_CTRLA_PRESCALER_DIV1 |
// Set prescaler to 8, 48MHz/8 = 6MHz <-- Not This FOUR 48/FOUR = 12Mhz
TC_CTRLA_PRESCALER_DIV4 |
// Set the reset/reload to trigger on prescaler clock
TC_CTRLA_PRESCSYNC_PRESC;
// Set-up TC3 timer for Normal Frequency Generation (NFRQ)
// TC3->COUNT8.WAVE.reg = TC_WAVE_WAVEGEN_NFRQ;
// Set-up TC3 timer for Match Frequency Generation (MFRQ)
TC3->COUNT8.WAVE.reg = TC_WAVE_WAVEGEN_MFRQ;
// Wait for synchronization
// while (TC3->COUNT8.SYNCBUSY.bit.WAVE)
// Set-up the PER (period) register 50Hz PWM
TC3->COUNT8.PER.reg = 000;
// Wait for synchronization
while (TC3->COUNT8.SYNCBUSY.bit.PER);
// // Set-up the CC (counter compare), channel 1 register for 50% duty-cycle
TC3->COUNT8.CC[1].reg = 0;
// // Wait for synchronization
while (TC3->COUNT8.SYNCBUSY.bit.CC1);
// Enable timer TC3
TC3->COUNT8.CTRLA.bit.ENABLE = 1;
// Wait for synchronization
while (TC3->COUNT8.SYNCBUSY.bit.ENABLE);
}
void loop() {
}```