board: Arduino Mega (ATMEGA2560)
I want to generate pulses using timer1 configured as Fast PWM, this is my code which works fine:
#include <avr/io.h>
int main(void)
//void setup()
{
DDRB |= (1 << DDB5) | (1 << DDB6); // PWM outputs
ICR1 = 0x7FFF; // TOP
OCR1A = 0x3FFF; // 50% of ICR1
OCR1B = 0x3FFF; // 50% of ICR1
TCCR1A |= (1 << COM1A1) | (1 << COM1B1);
TCCR1A |= (1 << WGM11);
TCCR1B |= (1 << WGM12) | (1 << WGM13);
TCCR1B |= (1 << CS10);
}
void loop() {
}
I don't understand why it doesn't work if I use void setup() instead of int main(void). I'm working with arduino IDE 1.8.2 and always used void setup(), in this case I used int main(void) because it is used in some turorials I found like this one: https://www.youtube.com/watch?v=O_Yqf_cugwE
EDIT: When I say that it doesn't work, what happens is that instead of having PWM signals I just have a constant 5V output in both OC1A and OC1B pins
=instead of|=.=instead of|=I have now a 0V output instead of 5V. I tried to initializeTCCR1A = 0;andTCCR1B = 0;first.