void loop(){
int value = analogRead(potenciometer);
int Freq_speed = value/4;
analogWrite(Freq,Freq_speed);
analogWrite(Freq2, Freq_speed); // same value for both
TCCR1A |= bit (COM1A0); // inverting mode
Serial.println(Freq_speed);
}
Btw, I think for a lot of applications it's not necessary to drive both the Hi and the LOW side. Just fixing the LOW and PWM the HIGH will work as well. Only the load stays connected to the GND/LOW side.
Do a similar thing to Timer 2. You know, reading the datasheet can be very helpful.
int Freq = 3;
int Freq2 = 11;
int potenciometer = A0;
void setup(){
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(A0,INPUT);
}
void loop(){
int value = analogRead(potenciometer);
int Freq_speed = value/4;
analogWrite(Freq,Freq_speed);
analogWrite(Freq2, Freq_speed); // same value for both
TCCR2A |= bit (COM2A0); // inverting mode
}
Thanks for these great examples so far. I'm writing some code for a brushless motor controller and I have a couple of questions.
Why is the line of code to enable inverting mode called after the analogWrite commands for both the inverted and regular pins? Wouldn't the inverting mode code want to be called first before the analogWrite lines?
I am using an Arduino Uno with the Atmel 328P. What would each line of code look like for pins 5, 6 and 9 to make them have inverted PWM? Ie: The equivalent of " TCCR2A |= bit (COM2A0); //inverting mode " in your example.
How would I write a line of code to restore the PWM of each pin back to non-inverted?
I'm trying to fix some bad behavior that the analogWrite function has when it is at 0 duty cycle, it calls digitalWrite instead.