PWM on a PIC18F4431
I'm currently trying to get 2 DC motors operating in forward and reverse mode.
To this end, I've gotten a SN754410 quad-half-bridge IC and a PIC18F4431.
However, I don't think that the pwm.h of microchip's C18 compiler
covers the 4431 family's PWM module (which is different from the much
more widely-used CCP/CCPx modules).
I'm having trouble understanding what to do.
This is for a micromouse robot, with the motors powering the wheels,
and I have been reading the datasheet for hours to try to figure out
some simple things.
I'm running at 40 Mhz (Fosc), and I believe I want to be using
Free-running mode with complementary outputs(for bi-directional
But the pre- and post- scalers are not making sense.
The prescaler influences the number of clockcycles used in the PWM
period, correct? So increasing the prescaler lengthens the period (and
duty cycle). Does this mean that the motor turns for longer,
generating a higher speed, or does it not really matter, as it will
still be off for a longer amount of time?
The Post scaler... I don't know. It seems to set the amount of 'dead
time' before an interrupt (that starts the PWM period over?), but
that's all I get out of it.
Then there's the duty cycle. While I understand this in terms of
percentages on and off, and when a change in the duty cycle is updated
to slow/speed the motor, I don't understand what they want me to put
in the duty cycle registers that I'll be using.
There's also the override registers/bits, but I'd like to take things
a step at a time.
Any help in answering these questions would be greatly appreciated.
This is the last major hardware interfacing piece to do, and getting
this done will let me start working on the final circuit.
- I just got a chance to look at your code carefully. A few things you might
- To set both PDC registers at the same time, first set the
PWMCON1.UDISbit. Then clear it when you are done writing.
- Use PWMCON0 = 0b00100111, since you are only using PWM0 and 1.
- Put in explicit initializations of the OVDCOND, OVDCONS, and FLTCONFIG
- Try taking out the dead band. I don't know the chip that well, but your
H-bridge may have logic to prevent shoot-through anyway.
Other than that, your code looks like it ought to work. I've used the '4431
to control servos before, but never in complementary mode.
[Non-text portions of this message have been removed]