8mhz Clock Signal on Mega

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

thanks!

I'm having one heck of a time debugging this circuit without verifying that I have a real clock signal here.

can anybody verify the above or perhaps offer another solution? thanks!

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

http://www.avagotech.com/pages/de/motion_control_encoder_products/integrated_circuits/decoder_ic/hctl-2022/

I don't understand where the 8MHz is coming from. If the IC can tolerate up to 33MHz, why does it matter what frequency you clock it at?

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!

You can generate a clock signal using the buffered clock output (CLKO or PE7)...oh wait, another useful pin not brought out on the Mega :0

OCR1A = 0; // 8 MHz

This may divide by 65k, as the counter might increment then compare, try 1.


Rob

hello

Iam also using this HCTL 2022 quadrature decoder, can you please share your codes as Iam stuck on the coding part.

The processors have a fuse setting to output the clock. So you can get the full 16 MHz on an output pin.

For timer1 I'd use this code:

  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:

  TCCR2A = 0x33 ;  // WGM2 = 0b111
  TCCR2B = 0x09 ;  // CS2 = 0b001
  OCR2A = 0x01 ;   // TOP = 0x01
  OCR2B = 0x00 ;
  TCNT2 = 0 ;
  pinMode (3, OUTPUT) ;

And its not mhz, its MHz - milli hertz would be impossible to program with Arduino timers!!!