Hello,
I am quite new to programming for Arduino. I need to generate varying clock frequencies on pin PA 21 ranging from 500 kHz down to 3906.25 Hz.
I have tried to generate code for 500 kHz but as of now I cannot make it work.
Here is my code,
void setup()
// Setup the program
{
GCLK->GENCTRL.reg = GCLK_GENCTRL_OE | // Enable GCLK5 output
GCLK_GENCTRL_IDC | // Improve duty-cycle to 50%
GCLK_GENCTRL_GENEN | // Enable generic clock
GCLK_GENCTRL_SRC_OSC8M | // Select 8 MHz as source \
GCLK_GENDIV_DIV(16) // Divide by 16 to produce 500 kHz
GCLK_GENCTRL_ID(5); // Set the GCLK ID to GCLK5
while (GCLK->STATUS.bit.SYNCBUSY); // Wait for synchronization
PORT->Group[PORTA].PINCFG[21].bit.PMUXEN = 1; // Switch on port pin PA21's multiplexer
PORT->Group[PORTA].PMUX[21 >> 1].reg |= PORT_PMUX_PMUXE_H; // Switch the PA21's port multiplexer to GCLK IO
}
void loop()
{
}
For some reason, testing this with an oscilloscope doesn't produce anything. It only produces noise.
Chip used is ATSAMD21G18A for Spark fun Dev