# Ideas for motor speed control

I have an idea of how to do a electronic speed control for some DC motor (H-bridges).
I built this circuit and it works pretty well.  Its a PWM generator based on this great tutorial .  I had to convert it to a NE556 instead of a NE555 but it works well with a 100K linear pot..

So, the Pot is mechanical ! - I wanted the bot to be able to control its own speed, not manually set it.  So, I came up with this - its a 12 bit binary counter (only using 6 bits), which should give me 64 speed settings. (specs)

PRO
1. I have the mc14040B on hand and I hate waiting for mail
2. 64 seems like a decent number of speed settings
3. 1 chip 6 resistors and 6 npn bipolar transistors does not seem like a huge number of components
4. stopping would be as simple as hitting the reset line
5. incrementing the speed would be just sending another clock pulse to the mc14040b

CON
1. In order to decrement the speed I would need to reset the whole chip and "quickly" increment to a lower speed (seems sloppy)
2. I have a feeling that this could be done with fewer components.

I'm going to build it anyway and will keep this post updated - (if anyone is interested), but since there are so many great "techies" out there - some could tell me "ha ha GroG - my granny used to build that circuit with vacume tubes, now its a single solid state speed control package ZX115 ! "

UPDATE 20081007

Well it all went together pretty smoothly.  I had a little trouble remembering on how to interface with other subchannels of the dio. But, luckly I mapped the hole thing out here .

The circuit currently has 330 Ohm resistor for all the bridges - but I will change this to Rik's suggestion of R/2 setup where each resistor is half its neighbor.  This should allow for a binary step through a full 64 different speed values.  Since I did not have the full resistor set the different values I can get with a 330 are as follows:

dio line - ohms
d0 - 330
d1 - 165
d2 - 110
d3 - 82.5
d4 - 66
d5 - 55

Yeah I know its messy - but it's a prototype :P

Circuit Diagram

I did not reach 100% duty cycle - but I think I should be able to get it when I have lower resistor values.

Here are some of the results:

d0 high - 330 ohms

d0 & d1 high 165 ohms

all on 55 ohms

TODO:

1. find other resistor values beside 330 so I can get 100% duty cycle when all inputs are high
2. connect the input to one of the large drive motors on loki
3. work on the web interface motor module to accept a speed value

UPDATE 20081008

DRAT DRAT DRAT DRAT DRAT !   I connected the large motors to the speed controller and all was working fairly well.  With 7 speed control positions using 6 x 330 ohm resistors. When all the DIO ports were off there was still an irratating noise of the PWM.  I wanted to see if I could turn this off completely.  Unfortunately, I continued to experiment with the large motors - when I was going through a sequence of turning 100% duty cycle off, the H-bridge fried.  And it looks like this time it took the computer with it.  Yes, I know I should have them completely electrically isolated with opto-couplers,  but I wanted to have the computers battery charged by the wheelchair charger.  It was my intention to have a relay in the system which would connect the two power systems together only when charging... but now I will suffer for charging ahead.. DRAT!  I have not yet assesed all the damage, the computer does not boot, I'm hoping i can re-initialize the bios - or at the least the CPU or memory is still good.  Did is say DRAT?

Lessons Learned

1. ISOLATE THE CONTROL ELECTRONICS FROM THE POWER SYSTEM (EXPECIALLY HIGH CURRENT SYSTEMS)
DUH ! I know this - now I should actually DO IT !  I'll probably be using the DIO card (if its not fried too) and this will be a bit of a pain to create 96 opto couplers for it - but I'll do it to save the computer.

2. The H-bridges I'm using I believe are not heavy duty enough - they are supposed to have current protection - but I think they are a bit underbuilt for the wheelchair - I will be looking into options of geting or building a larger H-bridge that can handle 80 amps -  the spike of dropping the speed from 100% down to a lower value seems to be frying it.

Crap, back to the drawing board. :P

## Comment viewing options

There is a chip called a digital pot, in several flavors that can be "talked to" differently. Analog Devices has a digital pot selection, and I think the AD5220 is closest to the implementation you have above, but giving 128 steps. Cost is about \$2 or possible "sample rates".

I believe there are also some PWM chips (L297 to go with the L298, others) too, but not sure what your application is.

I'm curious why you are generating PWM this way, rather than programming a micro to do it?

Thanks robologist!  I vaguely remember BOA mention something of the sorts in a different context.  Yes, that seems just the ticket.  I'll look into the PWM chips too.

Glad you asked, my project already has a computer - the computer  has a PCI-DIO-96 to control 96 digital lines. Controlling the large motors digitally has been a challenge. In the process i realized that i need a large range for speed control (the thing is wicked fast @100% duty).  First, I tried PWM from the computer, but it was not very satisfactory - it was pretty jerky - it might have been the way i hooked it all up but i think the computer was getting interrupted to do other processing.  Even if it was smooth, it seemed a poor use of resources, i dont want it tied up sending a constant stream of signal to a motor, it's going to be busy with other things like vision.

I've never had a microcontroller, but after watching this site, i've come to the conclusion that it would be fun.  in the future of my project i could see the possibility of adding a micro-controller connected to the computer.. kind of like your cerebellum & cerebrum talking to one another :P  the micro-controller could be in charge of managing a funtionally related set of IO, but at the moment it seems a bit overblown to do speed control - and a bit pricey...

i'll keep working on this circuit - thanks for the info - i like that the up/down is symmetric on the digital pot.

Something like an Atmel Tiny2313 could take the place of both the 555 and digital pot, and has 4 lines of PWM available if needed. It could be signaled with 1 wire or 4 wires or however you chose, from the PCI-DIO-96 card you have. I've wired up a predecessor of this (90S2313) on a small board that was around \$8 of parts at the time (maybe \$11 now) including the 2313. Programming would involve a little bit of learning, but shouldn't be too bad.

In more complex robots, I'd always hoped to have a fairly capable micro for low level real time requirements, with an upper PC based brain that handled tasks like vision (object recog, ranging, navigation), speech recognition, and overall task planning. I'd estimated it would command and receive data from the micro, that handled PWM, odometry, analog sensor data, timer sensor data, and any other tasks that required direct attention and constant updates in a real time sense. Each device to it's own specialty, essentially.

you got it robologist !  i started a little experimenting with RTT but i believe trying to process video and handle mapping and motor control might be a bit much for one computer - again, i'm pretty ignorant of micro-controllers, but everyone here seems to be having great fun with them.  i imagine i could turn a computer into a extremely capable "microcontroller" with RTT, but i thought i could get on by adding just a few discreet circuits.  (funny how you can't even get a 500 Mhz computer on ebay any more - not worth the shipping)

you would recommend the Atmel Tiny2313 because of 4 PWM lines and personal experience?   Is it a microcontroller without a bootloader? - most here seem familiar with PicAx, Arduino and such.

The Tiny2313 is one of the smaller micros, that would be suited to a few tasks. It is capable of more than your current requirements. And I've only done a simple "Hello World" program on a similar AVR. There are some devices that use similar small devices to serve up data to others, like the many sonar rangers out there. I had a small programmer that consisted of a number of resistors on lines to the parallel port for mine, no bootloader, though those can be had for the device. In this case, the programmer was so simple, a bootloader wasn't really needed.

The Arduino uses another micro of the AVR family, a bigger brother essentially, but with a bootloader.

Thanks for the info robologist,

I'll look into the details. Your suggestion is helpful.  I've definately would be interested in integration of micros in the future - seem much faster than building  circuits from scratch.  This time, however, I'll be making the circuit since i have parts near by..  and i hate waiting...

Go for it Grog! First make it work, then make it work elegantly. For varying interpretations of elegant.

I have a question about the design. The only diff between the pot-design and the counter-design seems to be in the Diode/Diode/Pot (DDP) circuit in the top left of the first diagram. You propose to replace the DDP by some sort of DA convertor made of the counter, 6 transistors with matching (pull down) resistors (CTR6).

I (think I) can see how the CTR6 might replace a pot, but how is it replacing two countering diodes?

thanks for the support rik! - good rule to follow - although my concept of elegant needs alot of interpretation, more like make it work or watch the smoke :)

Good catch! - i was just trying to digitize the pot - i was hoping to rip it all out (refactor?) but the diode & diode of the DDP seems to be critical - so now i'll wire it this way..

It seems to work(ish), although i don't have the mc14040b wired in yet - just testing it with a bunch of resistors .... kindof irratating noise :P - but the 555 seems to have an operating range there

What a marooon, as bugs bunny would say ...  the answer (or at least an answer) was staring me in the face - i've got 96 bits of control, about time i start using them...  just use 6 bits from it and turn the resistor bridge off or on in any sequence. I think i might be in the habit of trying to conserve data ports.. i'll keep updating this with my progress - thanks for the ideas.

And I now understand better what a 555 pwm generator is.

Please redraw your circuit. I did it on a piece of paper. Just focus on the R/C oscilator.

Pin 9 [output] intermittently acts as a source (charging C1) and as a sink (discharging C1). That's why there are two diodes. In your first diagram D1 (right hand) brings the current  from a sourcing [output] to C1. D2 (not numbered, but on left hand) does the opposite: takes current from C1 sinking it into [output].

The state of [output] switches each time either:
- [trigger] falls below 1/3 VCC or
- [threshold] rises above 2/3 VCC.

Pot R1 is acting as a combo of two resistors. The charging current goes through the right hand side. The discharging current through the left hand side. But always connected throug the middle hand to [output]. Alas, not in your latest diagram (Bugs Bunny version). The diodes and amputated pot act as an electronics cul-de-sac, a dead end! The only possible source/sink for C1 remaining are [trigger] and [threshold].