Loading ...
Sorry, an error occurred while loading the content.

Re: [SeattleRobotics] Re: PWM on a PIC18F4431

Expand Messages
  • Chris Parker
    I have been having some good experiences with the NJM2670 dual h- bridges. These are dip-22 chips (.4 wide), and each bridge can supply 1.5A. They also have
    Message 1 of 39 , Jul 31, 2007
    • 0 Attachment
      I have been having some good experiences with the NJM2670 dual h-
      bridges. These are dip-22 chips (.4" wide), and each bridge can
      supply 1.5A. They also have on-board thermal protection and short
      circuit protection. The only downside is that it is hard to find a
      heatsink for them. That being said, the middle four pins are ground
      and are attached directly to the internal substrate's heatsink, so
      soldering on some copper wings will make a good heatsink for my needs.


      On 31-Jul-07, at 10:01 PM, dan michaels wrote:

      > --- In SeattleRobotics@yahoogroups.com, "Ben Estroff"
      > <birdinhand@...> wrote:
      >> Yes. Thank you very much, that information about the simple method
      > of PWM
      >> control is really going to be of great help. Heh... This means that
      > I don't
      >> have to use the 18F4431 after all. I think I'll stick with it,
      > though. Just
      >> because I know it works, and it has plenty of memory for the
      > purpose of the
      >> project, and it'll teach the CSE major a valuable lesson in resource
      >> management.
      > The popular 16F877 chips have 2 hardware PWM peripherals and plenty
      > of code space.
      >> Is it safe to do 1,1 on the SN754410? Seems to me that's trying to
      > short the
      >> h-bridge.
      > First thing is, you need to take a look at the 754410 datasheet. The
      > problem you mention is only a booby trap on poorly designed
      > transistor h-bridges. Actually the 754410 has 4 separate driver
      > channels, each is push-pull, and they're designed for no shoot-
      > through during switching.
      >> But thank you again. No doubt I'll have more questions, but this is
      > exactly
      >> what I needed to hear about.
      >> For the application of a micromouse, would it be best to have the
      > highest
      >> possible resolution and frequency?
      > This depends purely on what's best for the particular motor you're
      > using.
      >> On 7/31/07, dan michaels <oric_dan@...> wrote:
      >>> --- In SeattleRobotics@yahoogroups.com<SeattleRobotics%
      > 40yahoogroups.com>,
      >>> "Ben Estroff"
      >>> <birdinhand@> wrote:
      >>>> Hello.
      >>>> 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.
      >>> I'll tell you one way to do this - I think the simple way. With a
      >>> chip like the 754410, you don't need the fancy PWM module with
      >>> complementary outputs, all you need are 2 simple PWM outputs,
      > plus 4
      >>> digital I/O pins. The 2 PWMs go to the two 754410 enable pins to
      > set
      >>> the motor speeds. The other 4 pins go to the 754410 IN1-IN4 pins
      > to
      >>> set the motor directions, plus stop and brake. Set the IN1-IN4
      > hi/low
      >>> according to the truth table in the 754410 datasheet [you did
      >>> download it, right?]. 0,0 = off; 0,1=cw [depending on motor
      >>> polarity]; 1,0=ccw; 1,1=brake. The enhanced PWM module in contrast
      >>> would normally be used to directly control the gates of a h-bridge
      >>> with 4 discrete MOSFETs.
      >>> Regards programming, you first select the period register to give
      > you
      >>> the required PWM frequency. If you want F=2000-hz PWM, you set the
      >>> period for 1/F. With the PICs you can actually get almost any PWM
      >>> period you want, since PR2 = 8-bit register. The prescaler selects
      >>> the range F can vary over. I don't believe you use the postscaler
      > for
      >>> PWM'ing.
      >>> Then use the duty cycle value to set the motor speeds. Here PWM
      > duty
      >>> goes 0-100% by setting the duty register = 0 up to [value in PR2]-
      > 1,
      >>> chosen previously.
      >>> Does this make sense?
      >>> - dan michaels
      >>> ====================
      >>>> 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
      >>>> control).
      >>>> 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.
      >>>> Thanks.
      >> [Non-text portions of this message have been removed]
      > Visit the SRS Website at http://www.seattlerobotics.org
      > Yahoo! Groups Links
    • Tom Capon
      I just got a chance to look at your code carefully. A few things you might try: - To set both PDC registers at the same time, first set the PWMCON1.UDISbit.
      Message 39 of 39 , Aug 17, 2007
      • 0 Attachment
        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.

        --Tom C.

        [Non-text portions of this message have been removed]
      Your message has been successfully submitted and would be delivered to recipients shortly.