so I have been having trouble getting an IC to interface with my mega and I've more or less concluded I have a clock problem. My IC is rated up to 33mhz, and I know the clock on the mega is 16mhz. I found the following code to generate an 8mhz clock (which should be fine for the IC) on the forums- can anyone verify this as a reasonable method to get an 8mhz clock signal from the board?:
pinMode(11, OUTPUT); // select Pin as ch-A
TCCR1A = B01000011; // Fast PWM change at OCR1A
TCCR1B = B11001; // System clock
OCR1A = 0; // 8 MHz
so I have been having trouble getting an IC to interface with my mega and I've more or less concluded I have a clock problem
What is the problem you are having and how have you concluded the clock speed of the Mega is the issue? I don't see how the core clock speed of two separate ICs really relate to each other. Especially when you are looking to change one of the clocks by a multiple of itself.
I am using an Avago 2022 quadrature counter IC. I need to use the arduino mega to provide a clock signal to the IC at a max speed of 33mhz. Using a DMM I verified power to the IC and a good quadrature signal to the A and B pins. However, when I take readings from the up/down pins or any of the 8 bit digital pins on the IC I get nothing. I have been told that my circuit is good so the next thing I want to verify is the inout clock signal from the arduino. does the following code accomplish this?
pinMode(11, OUTPUT); // select Pin as ch-A
TCCR1A = B01000011; // Fast PWM change at OCR1A
TCCR1B = B11001; // System clock
OCR1A = 0; // 8 MHz
I know that at ATMega chip is clocked at 16mhz. The max clock output speed I could find while rooting around the forums was 8mhz (using the code listed). I'd gladly take the full 16mhz or even something marginally slower so long as the IC still worked, but frankly I think I've got it mucked up and I don't have anything at all!
TCCR1A = 0xF2 ; // WGM1 = 0b1110 (mode 14) (use 0xC2 for pin 9 only, 0x32 for pin 10 only)
TCCR1B = 0x19 ; // CS1 = 0b001
ICR1 = 0x0001 ; // TOP = 0x0001
TCNT1 = 0x0000 ;
OCR1A = 0x0000 ; // omit for pin 10 only
OCR1B = 0x0000 ; // omit for pin 9 only
pinMode (9, OUTPUT) ; // omit for pin 10 only
pinMode (10, OUTPUT) ; // omit for pin 9 only
Which outputs on both pins 9 and 10 (but not on Mega), to turn off one of the pins clear the relevant two bits in TCCR1A as described.
Timer2 does not have a mode controlled by an ICR2 register so you have to use channel A's output compare register and mode 0b111 -
thus only channel B (pin 3) can be toggled at 8MHz: