so I am using my timers to create pulse trains on 1 and 2 using ctc. I am using an arduino ethernet, cause it is the spare I have lying around right now. I suchessfully created a pulse on pin 3 as expected, but on D10 or D9, I can not get it to work. now I understand D10 should be used for ethernet stuff, but I am not using the ethernet functionaity of this board, so that doesn't matter, right? on D9 it also does not work however. the pin does not change state. Now I made a typo in my code initially and did see a pulse on pin 9, but of the wrong frequency, so I am not sure what is up. below is the code.
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
#define STEPPER1 5
#define STEPPER2 10
#define STEPPER1_DIR 11
#define STEPPER2_DIR 12
#define STEPPER1_MICRO 16
#define STEPPER2_MICRO 16
#define STEPPER1_PPR 200
#define STEPPER2_PPR 200
#define LCD_SERIAL Serial
int stepper1Hz = 0;
int stepper2Hz = 0;
void setup(){
LCD_SERIAL.begin(19200);
LCDOn();
LCDClear();
LCDBLOn();
LCD_SERIAL.print("Setup done");
TCCR1A = 0;
TCCR1B = 0;
TCCR1C = 0;
TCCR2A = 0;
TCCR2B = 0;
// DDR_OC1B = B1; //not defined in scope
pinMode(9, OUTPUT); //D9 1A cheating, will it set output compare?
pinMode(3, OUTPUT); //D3 2B
//get timers ready for pulse duty, set to CTC mode and set prescaler set output
TCCR1A |= (1 << COM1A0); // set to toggle
TCCR1B |= (1 << WGM12); // set to CTC
TCCR1B |= (1 << CS12); // prescale 256
TCCR1B |= (0 << CS11); // prescale
TCCR1B |= (0 << CS10); // prescale
TCCR2A |= (1 << COM2B0); // set to toggle
TCCR2A |= (1 << WGM21); // SET TO CTC
// TCCR2B |= (1 << WGM21); // this instead of ^ causes a 31uS pulse on pin 9, but WGM21 is in TCCR2A, this likely changes the prescaler, which is accidentally fixed below
TCCR2B |= (1 << CS22); //256
TCCR2B |= (1 << CS21);
TCCR2B |= (0 << CS20);
OCR1A = 20; //chan2
OCR2B = 20; //chan1 issues
}
void loop(){
}
my mistake, which i included as a comment, results in the timer being in normal mode isntead of CTC, not sure why that should work and not CTC.