Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to control more than one port in pic microcontroller?

Status
Not open for further replies.
Stupid design??? Hardly! Saves you the cost and PCB real estate of an external driver chip! If you can spare the pins then why not!?

If you only have a PIC with a single PWM output then sure...use a driver chip. But Microchip put the Enhanced PWM module on the PIC for a reason...and that reason is to provide 4 line H-Bridge control without the need for an external driver chip. If that design were so "stupid", I don't think the engineers at Microchip would've wasted their time with it. If your PIC has it then take advantage of it.
 
Saves you the cost and PCB real estate of an external driver chip!

You still need FET gate drivers. Why not use a single driver chip for all 4 FETs? Not very cost efficient to use discrete gate drivers and dedicated PWM output pins for every single FET.. and not very safe either. One software bug and the FETs are fried.

But Microchip put the Enhanced PWM module on the PIC for a reason.

The Enhanced PWM module is probably designed mainly for driving BLDC motors where you need 3 PWM outputs for 3 half-bridges to control a single BLDC. Would you control a BLDC with 6 PWM outputs and 6 gate driver chips.. that would be very stupid design.

...and that reason is to provide 4 line H-Bridge control without the need for an external driver chip.

You still need the external gate driver chip.. and you can't find gate drivers that take in 4 PWM signals and output 2 high side drives and 2 low side drives. You can't find an H-bridge IC with 4 PWM inputs either. You would have to use 4 external driver chips and somehow manage dead-time to prevent shoot-through. How does that save money and PCB real estate?
 
Last edited:
There is no need for PWM in driving steppers unless you are making a home brew current controlled type driver, which is not something I would recommend as there are ICs out there to do that for you.

All you need is a couple of timer interrupts and 4 pins per motor. Your driver IC for unipolar motors could be as simple as a ULN2003 etc or a nice current sensing chopping driver (to get more torque at high speeds) like the SLA7024M (you should really use the enable pin on this too, so 5 pins).

If you wanted you could reduce pins by using a smarter IC, like those from Allegro micro. You can make a full robot with an 18f452/16f877 sized device (pin wise) and have pins to spare so what's the problem with using pins to simplify the design? (removing the need for a L297 or equivalent).

I would do the following pseudo code wise:

* Set up two timers to produce interrupts on overflow
* On overflow read out the bit pattern for that particular step (out of a look up table) and output to it the appropriate stepper pins on your micro. Increment your step position index for that particular motor.
If the step position index == end, reset it to 0.
* reset the timer to the next step period and reset the timers interrupt flag (as PIC's have very few real interrupts and use flags in registers to determine which device caused the interrupt).

Hope that helps :)
 
Last edited:
  • Like
Reactions: 3v0
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top