Hello world (Post#1 mandatory catchphrase ).
Or more accurately Arduino Forum World.
As a newcomer I’m trying to get a MOS6581 working with my brand new Arduino kit, and I would like to use the OC1A pin as a clock for the chip.
Hence, based on a Arduino Uno, I’ve been digging in the forum to find the way to configure accurately the registers to have this pin behave like a 1Mhz clock, assuming a 16Mhz crystal on the Arduino Board.
… and eventually copy/pasted the following code from another guy, and then modified it to my need:
// === Setup of the CLK for MOS 6581 === // ===================================== // 1MHz generation on OC1A - Clk 16 MHz // set pin 9 as output pinMode(9,OUTPUT); // reset settings of Timer/Counter register 1 TCCR1A &= ~((1<<COM1A1) | (1<<COM1A0) | (1<<WGM11) | (1<<WGM10)); TCCR1B &= ~((1<<WGM13) | (1<<WGM12) | (1<<CS12) | (1<<CS11) | (1<<CS10)); // set compare match output A to toogle TCCR1A |= (0<<COM1A1) | (1<<COM1A0); // set waveform generation mode to CTC (Clear Counter on Match) TCCR1A |= (0<<WGM11) | (0<<WGM10); TCCR1B |= (0<<WGM13) | (1<<WGM12); // set clock select to clock/1 (from prescaler) TCCR1B |= (0<<CS12) | (0<<CS11) | (1<<CS10); // set output compare register A to 8 (i.e. OC1A Toggle every 8 Clk pulses) OCR1A = 8;
This is my understanding of the whole thing:
to set the prescaler to divide by 1 ( CS10 = 1)
set output compare register A to 15624
OCR1A = 15624
==> to reset the counter at 8 counts,
To put the output in Toggle mode
As far as I understand it, this would make the OC1A output to toggle every 8 clock pulses at 16MHz, which makes a 1Mhz clock.
Do you agree with this assumption? Am I correct?
I’m mainly wandering if I’m doign the good asumptions from counter point of view, the main issue is that I do not have any scope to check, and I have only ONE former MOS6581 from the first generation, and my worst nightmare would be to destroy the chip…
Thanks in advance for your kind help on this topic.