I am trying to enable PWM on an Arduino Mega ( ATmega2560 ), but I ran into some problems.
Firstly, I am trying to program this in Ada . I want to use three Timer3 channels with FastPWM, so I wrote
procedure Main is
begin
-- Nullify Timer3 buffers
TCCR3A := 0;
TCCR3B := 0;
TCCR3C := 0;
-- Waveform Generation Mode
-- Fast PW, 8-bit, TOP = 0x00FF, Update OCR3x at BOTTOM, TOV3 Flag Set on TOP
-- => WGM33|WGM32|WGM31|WGM30 = 0|1|0|1
TCCR3A := TCCR3A or TCCR3A_WGM30;
TCCR3B := TCCR3B or TCCR3B_WGM32;
-- Compare Output Mode:
-- Fast PWM, non-inverting mode
-- => COM3A1|COM3A0|COM3B1|COM3B0|COM3C1|COM3C0 = 1|0|1|0|1|0
TCCR3A := TCCR3A or TCCR3A_COM3A1 or TCCR3A_COM3B1 or TCCR3A_COM3C1;
-- Clock Select: clk/1024 => CS32|CS31|CS30 = 1|1|1
TCCR3B := TCCR3B or TCCR3B_CS32 or TCCR3B_CS31 or TCCR3B_CS30;
-- Set Timer3 pins as output :
-- Channel A : Digital Pin 5 / Chip Pin 5 (PE3/OC3A/AIN1)
-- Channel B : Digital Pin 2 / Chip Pin 6 (PE4/OC3B/INT4)
-- Channel C : Digital Pin 3 / Chip Pin 7 (PE5/OC3C/INT5)
DDRE := DDRE_DDE3 or DDRE_DDE4 or DDRE_DDE5;
OCR3AH := 0;
OCR3AL := 250;
OCR3BH := 0;
OCR3BL := 250;
OCR3CH := 0;
OCR3CL := 250;
end Main;
Hardware connections are OK; I tested it using simple code on the Arduino IDE. Therefore, it is very clear to me that there is something missing in the code or something is wrong, and this should be caused by the problem of PWM initialization. Can someone explain to me where I made such a mistake?
Thanks in advance.
Update
Ada , C ( AS6, , .. ):
int main(void){
TCCR3A = 0;
TCCR3B = 0;
TCCR3C = 0;
TCCR3A = TCCR3A|(1<<WGM30);
TCCR3B = TCCR3B|(1<<WGM32);
TCCR3A = TCCR3A|(1<<COM3A1)|(1<<COM3B1)|(1<<COM3C1);
TCCR3B = TCCR3B|(1<<CS32)|(1<<CS31)|(1<<CS30);
DDRE = DDRE|(1<<DDE3)|(1<<DDE4)|(1<<DDE5);
OCR3AH = 0;
OCR3AL = 250;
OCR3BH = 0;
OCR3BL = 250;
OCR3CH = 0;
OCR3CL = 250;
}