I have a Ti DRV10970 motor control IC connected to an atmega328PB. The OC3B (timer 3 compare output) is wired to the DRV10970 PWM control input. The problem is that the spec's on this chip require a 15-100khz pwm waveform. The atmega is being used with the internal RC clock. I currently have it set at 1mhz, but can change the fuses to run at 8mhz. I can't seem to get timer 3 to run in Fast PWM mode with output on OC3B.
Here is a code siglet I've tried:
TCCR3A = (1 << COM3B1) | ( 1 << WGM30); //set FPWM mode 5 top = 0xFF output on B pin (COM3B1)
TCCR3B = (1 << WGM32) | ( 1 << CS30); // set prescaler to 1x
OCR3B = motorSpeed;
TIMSK3 = 1<<TOIE3; //to generate an interrupt on overlfow, ISR can reload OCR3B to change duty cycle (is this needed?)
ISR(TIMER3_OVF_vect)
{
OCR3B = motorSpeed;
}
Motor speed is an 8 bit variable, a value of 0 should generate narrow pulses, 127 a 50% duty cycle, and 255 a flat line high.
No mater what I set the OCR3B to I only get a low output. The OC3B pin was set to output low before running this code.
Right now I'm experimenting on the Arduino IDE, using the minicore board base set to the atmega328pb. The Arduino analogWrite function on this pin DOES work, but outputs a 300hz waveform (at 1mhz clock) which is WAY too low to meet spec, even if I change the clock fuses to go to 8mhz.
Any ideas?