Hi. Recently i'm working on the ov7670 camera and i need to supply it with a 8Mhz clock rate. I tried googling about that, and only found a solution on timer 1. I tried to look up the datasheet, but somehow my code fails to work.
const int
D0 = A0,
D1 = A1,
D2 = A2,
D3 = A3,
D4 = 4,
D5 = 5,
D6 = 6,
D7 = 7, // D0:8 are the output pins from ov7670
XCLK_pin = 6; // OC1A output pin for ATmega32u4 (Arduino Micro)
void setup()
{
/*
* TCCR0A Bits 7:0
* +-------+-------+-------+-------+-------+-------+-------+-------+
* | COM0A1| COM0A0| COM0B1| COM0B0| - | – | WGM01 | WGM00 |
* +-------+-------+-------+-------+-------+-------+-------+-------+
*/
/*
* TCCR0B Bits 7:0
* +-------+-------+-------+-------+-------+-------+-------+-------+
* | FOC0A | FOC0B | - | – | WGM02 | CS02 | CS01 | CS00 |
* +-------+-------+-------+-------+-------+-------+-------+-------+
*/
pinMode(XCLK_pin, OUTPUT);
TCCR0A = TCCR0B = 0;
// toggle mode
TCCR0A &= ~bit(COM0A0);
TCCR0A |= bit(COM0A1);
// don't use timer B
TCCR0A &= ~bit(COM0B0);
TCCR0A &= ~bit(COM0B1);
// fast PWM mode with TOP = OCR0A
TCCR0B |= bit(WGM02);
TCCR0A |= bit(WGM01);
TCCR0A |= bit(WGM00);
// not using force output
TCCR0B &= ~bit(FOC0A);
TCCR0B &= ~bit(FOC0B);
// not using prescaler
TCCR0B &= ~bit(CS02);
TCCR0B &= ~bit(CS01);
TCCR0B |= bit(CS00);
OCR0A = TCNT0 = 0;
Serial.begin(9600);
}
void loop() {
Serial.println(F("hello"));
delay(1000);
}
The serial monitor just printed "he" and stopped. I cannot figure why this happened. Any help is much appreciated. Thanks.