Hello everyone,
I am using a Arduino Mega2560 to control a 3 phase brushless DC motor via the 3 PWM outputs available from Timer1. Two of the outputs (OC1A/B, digital Pins 11/12) are providing the correct 20KHz output, however I am not getting any output from OC1C (Digital Pin 13, defined in my code as PWM), it just sits at 0 volts.
I am aware that Digital Pin 13 is shared with the output from OC0A, section 19 of the data sheet (Output Compare Modulator) indicates that the output on Pin 13 is determined by the relevant COMnx pins. Unless all my Arduino are broken there must be a problem with my configuration of the device however I cannot see it.
I have stripped my code down to the bare essentials as shown below and removed all connections other than the USB cable thus eliminating any other potential issues and still it does not work, can anyone see where I have gone wrong?
#include <avr/wdt.h> //Include for Watchdog Timer
#define PWM_SPARE 11
#define DCM_PWM 12
#define PWM 13
void setup() {
TCCR0A = TCCR0A & 0x3F; //Disconnect Timer OCOA output from Digital Pin 13 (PB7)
TCCR1A = (TCCR1A & 0x00) | 0xAA; //Ensure TCCR1A is clear then Set for Phase Correct PWM, TOP = ICRn, output = A, B & C (1010 1010)
TCCR1B = (TCCR1B & 0x00) | 0x11; //Clear TCCR1B then set for PWM, no Prescaling 0001 0001 - DO NOT CHANGE bit 7:3
TCCR1C = (TCCR1C & 0x00); //Ensure TRRC1C is clear, TCCR1C not used, just belt & braces code
ICR1 = 0x0190; //Use IRCn to Set TOP for a 20KHz PWM Frequency = 400 ($0190)
Serial.begin(19200);
digitalWrite(PWM_SPARE, LOW); //No PWM - Output in Tristate condition
digitalWrite(DCM_PWM, LOW); //No PWM - Output in Tristate condition
digitalWrite(PWM, LOW); //No PWM - Output in Tristate condition
pinMode(PWM_SPARE, OUTPUT);
pinMode(DCM_PWM, OUTPUT);
pinMode(PWM, OUTPUT);
analogWrite(PWM, 100); //25% Modulation depth
analogWrite(DCM_PWM, 100); //25% Modulation depth
analogWrite(PWM_SPARE, 100); //25% Modulation Depth
WDTO_2S; //2 Second Time out (Watchdog Timer enabled at power up)
}
void loop() {
wdt_reset();
}
Stephen