Wonder if someone can help. I'm trying to track down an issue with a board I've put together which after a while 'appears' to stop all together
CPU is Atmega328P connecting to a TLC5940 with SPI. External clock running at 20mHz
I've using some sample code (michael cousins's TLC5940 class) and I've realised that the problem might be that I don't have the prescaler settings for 20mHz as the sample is for 16.
However for the life of me, I can't figure out what needs changing for the higher clock speed
cli(); // user timer 1 to toggle the gs clock pin TCCR1A = 0; TCCR1B = 0; TCCR1C = 0; TIMSK1 = 0; // toggle OC1A (pin B1) on compare match event TCCR1A |= (1 << COM1A0); // set the top of the timer // PS = 1, F_CPU = 16 MHz, F_OC = F_CPU/(2 * PS * (OCR1A+1) // gs edge gets sent every 32*2=64 clock ticks OCR1A = 31; // put the timer in CTC mode and start timer with no prescaler TCCR1B |= ( (1 << WGM12) | (1 << CS10) ); // set up an isr for the serial cycle to live in // let it live in timer 0 TCCR0A = 0; TCCR0B = 0; TIMSK0 = 0; // set waveform generation bit to put the timer into CTC mode TCCR0A |= (1 << WGM01); // set the top of the timer - want this to happen every 4096 * gs clocks = every 8192 clock ticks // set top to 255 for an interrupt every 256 * 1024 = 64 * 4096 clock ticks OCR0A = 255; // start the timer with a 1024 prescaler TCCR0B |= ( (1 << CS02) | (1 << CS00) ); // enable the interrupt of output compare A match TIMSK0 |= (1 << OCIE0A); sei();