I am trying to generate a 1KHz square wave output via timer1 in CTC Mode but no matter what I try I am not generating any signal on Pin11 which according to the schematic is OC1A pin.
My code is as follows:
#include <avr/io.h>
#include <avr/interrupt.h>
void setup()
{
pinMode(11, OUTPUT);
TCCR1B |= (1 << WGM12); // Configure timer 1 for CTC mode
TCCR1A |= (1 << COM1A0); // Enable timer 1 Compare Output channel A in toggle mode
OCR1A = 250; // Set CTC compare value to 1KHz at 16MHz AVR clock, with a prescaler of 64
TCCR1B |= ((1 << CS10) | (1 << CS11)); // Start timer at Fcpu/64
}
void loop()
{
}
I also had an error in my Math so for the sake of anyone reading this thread if the future I include the corrected code to generate 1KHz signal on pin 11 of the Mega2560:
#include <avr/io.h>
#include <avr/interrupt.h>
void setup()
{
pinMode(11, OUTPUT);
TCCR1B = (1 << WGM12); // Configure timer 1 for CTC mode
TCCR1A = (1 << COM1A0); // Enable timer 1 Compare Output channel A in toggle mode
OCR1A = 124; // Set CTC compare value to 1KHz at 16MHz AVR clock, with a prescaler of 64
TCCR1B |= ((1 << CS10) | (1 << CS11)); // Start timer at Fcpu/64
}
void loop()
{
}
I whant to work with an Stepper Motor Driver. But this is working only till 1000Hz. But inside the data sheeds means till 200KHz. Do we need an other Profil for such an Stepper Motor Driver??