Motor control help/ considerations

Thread Starter

MCrowe

Joined May 29, 2011
69
Hi all,

Im trying to find a good way to drive a few motors from a Pic16F877a.
Speed and position aren't critical, I would like a resonable resolution of speeds but nothing over the top. Lets say im using 8 bits for speed control so maybe 256 bits of resolution for speed.

I have quite a lot of other code running, (serial com, ADC converters, button monitoring and such) so I dont want it to be time critical, which is why I've kind of ruled out PWM. That and I may want to drive 4 or 5 motors and only have 2 pwm modules.

I think the best option I have found is stepper motors but with a controller that allows you to send a digital speed value to it. It only had four bits so 15 speed resolution, * 2 as you can switch to half step. And im happy with this but can't actually find the IC anywhere...

Does any one have any good options for controlling a motors speed without using PWM. I would much prefer to just output say 4 bits for speed and have them latch until I get around to changing it again. Is this possible?? Brushed, brushless, stepper or servo...

Thanks in advance for any considerations.
 

ErnieM

Joined Apr 24, 2011
8,377
Have you considered using multiple processors? You could configure & code a small device as a PWM loop and have it latch these 4 bits for speed.

My record is 11 PICs running together, 1 master and 10 slaves. Master runs the display (graphic touchscreen) and each slave performs a test and reports back to the master on command.
 

Thread Starter

MCrowe

Joined May 29, 2011
69
Yeah, That was kind of the conclusion I came to., that it might be best to use another Pic. If i do, what is the best way to communicate between them? I already have a Serial connection to another pic. So they one handling the motor control is already receiving its data from a different pic that is handeling button presses and ADC conversions.

Im not really sure what to do about communication. I could link each slave pic to its own four bit data channel, OR, possibly address each contro (slave pic). If I was to link them all to the same set of control bits, how would I go about addressing them. Do you just send an address as a string. Say, send MOTOR1, and then that pic waiting for MOTOR1 will respond? I assume you cant just send 1, for pic number 1 because there is a fair chance it could receive a 1 any way in the course of receiving its speed and motor direction data. AND what communication would work best? Any ideas?
 

MrChips

Joined Oct 2, 2009
30,712
Are you planning on controlling each PIC and hence each motor from a PC?
If so I can assist in building the communications network.
 

Thread Starter

MCrowe

Joined May 29, 2011
69
No, not from the PC,

Im I have two 16F877a's that communicate between each other using USART. So, im sending all the data from buttons and switches and such from one pic to another. The second pic is the one I want to control the motors. Im happy for the second pic to have peripheral pics coming from that for motor control if necessary. I just like the idea of distrubuting it all from the second pic. Although in reality its probably unnecessary. I could probably just have the peripheral pics (motor control pics) communicating directly with the first one. Think tethered robot...

Do I have multiple pics for motor control? and if so, whats the best way to communicate with them?
 

ErnieM

Joined Apr 24, 2011
8,377
Do I have multiple pics for motor control?
That depends on the overhead on a single processor to keep the "serial com, ADC converters, button monitoring and such" running while supplying possible fast timing into to the PWMs. I don't know that is impossible so I would try it that way in the name of hardware simplicity.

You would need to make 4 software PWMs, but they can all run off the same timer so it may be possible.


whats the best way to communicate with them?
A parallel load needs 4 data and 1 control line per slave so an 8 pin device would work. That needs 4 data and 4 control lines on the master.

Some serial data would keep lines to a minimum, "ttl-232" (logic level serial) would keep the comm down to a single line on both master and slave but I believe you are already using the serial on the master, so you may have to add "soft" serial code.

My 11 device monstrosity used I2C to communicate. Each slave ran identical code that got it's address from EEPROM,but getting the I2C engine to work is not simple nor well documented (that may have changed in the 2-3 years since I did this). The master would also need a soft driver as I believe it shares the IO pins with the serial hardware.
 

nickelflipper

Joined Jun 2, 2010
280
No, not from the PC,
....
...
...
Think tethered robot...

Do I have multiple pics for motor control? and if so, whats the best way to communicate with them?
If a bunch of brushed dc motors are in the mix then a do all chip, like the 18f46k22 chip, could be a solution. It has 3 ECCP (read H-bridge control), and 2 CCP, for up to 5 hardware PWM's.

I have fooled with the 18f1330, and it could do 3 hardware servo PWM's. Maybe a possible slave chip, but who knows at this point?. It has a Power PWM module, which can operate at 50-60Hz. Once it is set up, just feed it the duty cycle. It can have about 500 steps of resolution, at a system clock of 4MHz.
 

nickelflipper

Joined Jun 2, 2010
280
Just to add to previous post, I have forgot about the 18fxx31 series. The 18fxx31's have the same power control PWM module that the 18f1330 has. Also the 40 pin model has 4 independent duty cycle generators.

The data sheet clearly states the ability of 50Hz PWM, at max system clock of 40Mhz or 10Mips. When checking my 18f1330 servo code, my prescale value was only 1:16, with the 1:64 still available for faster clock rates.
 

John P

Joined Oct 14, 2008
2,025
Software PWM for several motors at once is quite feasible, but you have to accept some limitations, notably that the frequency won't be very high, and the resolution of duty cycle may be rather coarse. I've designed an 8-output PWM system which runs at 60Hz and 0-99 duty cycle, and it works OK. You just have to set up a 6KHz timer with a 0-99 counter, start all non-zero outputs at count 0, and at every interrupt, decide whether to turn each output off. That's all there is to it.

My preference would be to do all the other periodic stuff in the same interrupt, maybe divided down to a lower rate, i.e. check the pushbuttons and the comm port, fire/read the ADC etc. That way you never get one interrupt blocking another.
 

MMcLaren

Joined Feb 14, 2010
861
Does any one have any good options for controlling a motors speed without using PWM. I would much prefer to just output say 4 bits for speed and have them latch until I get around to changing it again. Is this possible?? Brushed, brushless, stepper or servo...
Huh? There's quite a big difference between those types of motors? What is the application?
 

Thread Starter

MCrowe

Joined May 29, 2011
69
The data sheet clearly states the ability of 50Hz PWM, at max system clock of 40Mhz or 10Mips. When checking my 18f1330 servo code, my prescale value was only 1:16, with the 1:64 still available for faster clock rates.
But this interest me... I'm resonable sure I can't get 50Hz from my 16f877a. Unless I've interpreted it completely wrong, there is no way to get that slow. Even with only a 4Mhz crystal. If I am wrong, could someone please let me know!

Damn, looks like maybe a 18f46k22 is on the card. Seems to do everything I want. Actually maybe I should figure out exactly what it is I want first...
 

Thread Starter

MCrowe

Joined May 29, 2011
69
Im got my setup going with a master Pic controling a Slave, can any one tell me how you would usually go about sending data to the slave.

I actually have it set up and working but I don't think its quite right. What I wanted to do was send something unique, like the string 'D' 'A' 'T' 'A' followed immediately by the value (speed and direction) for each motor. Problem is, it won't recognise all four characters. But it does work if I just send 'D' and then the values. BUT, 'D' isn't really that unique. The master Pic could easily transmit the a 'D' as a speed (it uses 0 to 256). Then the Slave will take the next lot of values starting from the wrong place. Does that make sense.

So, aside from all the explaining of what I have and haven't done, is there a way to do this that makes more sense?? Or is more accurate?
 
But this interest me... I'm resonable sure I can't get 50Hz from my 16f877a. Unless I've interpreted it completely wrong, there is no way to get that slow. Even with only a 4Mhz crystal. If I am wrong, could someone please let me know!

Damn, looks like maybe a 18f46k22 is on the card. Seems to do everything I want. Actually maybe I should figure out exactly what it is I want first...
The quoted post was a continuation of my previous post, which discussed the 18f1330. Look up the data sheet of the 18f1330, or the 18f4431, and peruse the Power Control PWM module chapter to see what I mean about the minimum PWM frequency.
 

Thread Starter

MCrowe

Joined May 29, 2011
69
OK, Not entirely sure why, but it works perfect now... As long as my method of addressing / (starting the serial transfer) is a good way of doing it. I just send two bytes, I decided on d'1' and d'1' as you can never get two 1's in a row sending servo positions, then if both 1's have been received it stores the next 4 bytes of data in set registers. (servo0H, servo0L, serovo1H & servo1L, as well as anything else I might want to transmit.)

Im sure there are other ways of doing it but as no one has chimed in and this seems to work, ill go with it. Thanks heaps for all the help on my mirad of questions guys. Cheers.
 
Top