I'm using Arduino UNO with 4 MOSFETS to drive speed and direction in a DC Motor through PWM (H-Bridge). Currently Pins 9 and 10 are my PWM pins which control the MOSFET pairs (pin 9 drives MOSFET pair 1,4. Pin 10 drives MOSFET pair 2,3) and so far every thing is working good with those pins which have a frequency of 490 Hz.
However I would like to try with pins 5 and 6 because of their 980 Hz frequency but I've read the warning that "it may result in a value of 0 not fully turning off the output on pins 5 and 6". The problem is, in such a case I will get a short circuit if i turn on the second pair (while the first pair is not fully turned off). Is there any way to turn this pins fully off ?
but I've read the warning that "it may result in a value of 0 not fully turning off the output on pins 5 and 6".
Where does this warning come from? Does it explain why?
analogWrite(pin,0) defaults to digitalWrite(pin,0).
This is the source code for analogWrite() and Timer0.
void analogWrite(uint8_t pin, int val)
{
// We need to make sure the PWM output is enabled for those pins
// that support it, as we turn it off when digitally reading or
// writing with them. Also, make sure the pin is in output mode
// for consistenty with Wiring, which doesn't require a pinMode
// call for the analog output pins.
pinMode(pin, OUTPUT);
if (val == 0)
{
digitalWrite(pin, LOW);
}
else if (val == 255)
{
digitalWrite(pin, HIGH);
}
else
{
switch(digitalPinToTimer(pin))
{
// XXX fix needed for atmega8
#if defined(TCCR0) && defined(COM00) && !defined(__AVR_ATmega8__)
case TIMER0A:
// connect pwm to pin on timer 0
sbi(TCCR0, COM00);
OCR0 = val; // set pwm duty
break;
#endif
#if defined(TCCR0A) && defined(COM0A1)
case TIMER0A:
// connect pwm to pin on timer 0, channel A
sbi(TCCR0A, COM0A1);
OCR0A = val; // set pwm duty
break;
#endif
#if defined(TCCR0A) && defined(COM0B1)
case TIMER0B:
// connect pwm to pin on timer 0, channel B
sbi(TCCR0A, COM0B1);
OCR0B = val; // set pwm duty
break;
#endif