Setting PWM Frequency for LMD18200 Motor Controller

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
liam.zbasic
Posts: 163
Joined: 24 March 2008, 23:33 PM
Location: Southern California (Blue)

Setting PWM Frequency for LMD18200 Motor Controller

Post by liam.zbasic »

I purchased the LMD18200 H-Bridge motor controller and attempted to run a DC motor with my ZX-40a chip and the PWM function. When I set the frequency to 10,000Hz using OpenPWM(), I noticed that the ZX-40a would not output a PWM signal. At 50Hz, it worked fine. In fact, anything at or below 225Hz worked fine. Now I need 10,000Hz or more. According to the ZBasicSysLib.pdf document, I should be able to set the frequency up to half the CPU speed with mode=zxFastPWM. This can't be right. Then I read through the AN216.pdf file, and it appears that I need to change the "prescale" value via "CPU Registers". I'm somewhat apprehensive about meddling with "CPU Registers" just like I'm apprehensive about configuration files in Microsoft Windows. Is setting the "CPU Register" reversible? How many registers need to be changed to simply increase the max allowable PWM frequency for my LMD18200 motor controller? Thank you.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Setting PWM Frequency for LMD18200 Motor Controller

Post by dkinzer »

liam.zbasic wrote:When I set the frequency to 10,000Hz using OpenPWM(), I noticed that the ZX-40a would not output a PWM signal.
That is a known problem for which there is a workaround. See this post.
liam.zbasic wrote:I'm somewhat apprehensive about meddling with "CPU Registers" just like I'm apprehensive about configuration files in Microsoft Windows. Is setting the "CPU Register" reversible?
While it is true that you can cause a ZX to malfunction by inappropriate modification of some registers, it is unlikely that you'll cause permanent damage. Direct register modification is simply a useful tool. As with any tool, when used carefully for the intended purpose, good things can result.
- Don Kinzer
liam.zbasic
Posts: 163
Joined: 24 March 2008, 23:33 PM
Location: Southern California (Blue)

Post by liam.zbasic »

Thank you. The post you cited and the following line made all the difference.

"Register.TCCR1B = Register.TCCR1B Or &H01"

I noticed the workaround has to go just after the call to OpenPWM(), not before at the top of the main program where I initialize variables and constants.

Also, I fried my ZX-40a when driving a couple of motors with a couple of LMD18200 devices. The only link between the ZX and the LMDs is a common ground, the PWM signal, and 2 "direction inputs" enabled with PutPin(). Any suggestions as to how I can further shield the ZX from motor controllers? Thanks.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

liam.zbasic wrote:I noticed the workaround has to go just after the call to OpenPWM(), not before at the top of the main program where I initialize variables and constants.
That is because the call to OpenPWM() also sets that same timer control register, causing the previous value to be lost. The issue that that above 225Hz it sets it to the wrong value. It should be noted that for frequencies of 225Hz and below, OpenPWM() sets the timer control register correctly and the workaround should not be used in those cases.
liam.zbasic wrote:Also, I fried my ZX-40a when driving a couple of motors with a couple of LMD18200 devices.
Perhaps the best solution is to use opto-isolators. However, at the frequency that you're using that may not be a practical solution. You'll have to check the specifications of some optos to see if they'll work. Lacking that, it may be useful to employ some series resistors to limit the current flow in over-voltage and under-voltage situations. It may also make sense to add external clamping diodes (all of the I/O lines have internal clamping diodes) and you may want to look at transient suppression techniques.
- Don Kinzer
GTBecker
Posts: 616
Joined: 17 January 2006, 19:59 PM
Location: Cape Coral

Post by GTBecker »

liam.zbasic wrote:Also, I fried my ZX-40a when driving a couple of motors with a couple of LMD18200 devices.
Did you also fry the H-bridge or did it survive the incident that killed the processor?
Tom
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Post by mikep »

liam.zbasic wrote:Also, I fried my ZX-40a when driving a couple of motors with a couple of LMD18200 devices. The only link between the ZX and the LMDs is a common ground, the PWM signal, and 2 "direction inputs" enabled with PutPin(). Any suggestions as to how I can further shield the ZX from motor controllers?
Are you sure it is fried? Under normal circumstances the LMD18200 should behave itself. Did you accidentally connect the motor power supply to the ZX40a? Are all of the I/O pins kaput or just single bits? Is it just program downloads that are failing? I have blown the receiver part of a USART before - I later used the BX35 chip (precursor to ZBasic) as a AVR controller (AT90S8535) for my daughter's tic-tac-toe game.

I have used opto-isolators before with my motor controller for noise protection although ultimately I did not need them. See the projects page. I also found that there is too much high pitch whine with the higher frequencies and used a much lower PWM frequency (80Hz).
Mike Perks
liam.zbasic
Posts: 163
Joined: 24 March 2008, 23:33 PM
Location: Southern California (Blue)

Post by liam.zbasic »

The LMD18200 chips were not destroyed when I ran the motors at 100% duty cycle. My circuit has 2 of these chips, one for each 1-Amp motor. The LMD's are robust, effective and cheap parts, but require at least 12V to function, so I have several AA batteries (12 total for 18V) powering the motors. Running them at 100% duty cycle was a mistake.

My ZX-40a is powered by a separate 9V battery with a 5V regulator per Zbasic's suggested circuitry. I did not mix power supplies. "Fried" means that I was unable to download programs after the mishap. When I replaced it with a new chip (and changed the duty cycle to 35%) , all worked fine.

Mistakes are the best teachers.
GTBecker
Posts: 616
Joined: 17 January 2006, 19:59 PM
Location: Cape Coral

Post by GTBecker »

liam.zbasic wrote: Running them at 100% duty cycle was a mistake. [] When I replaced it with a new chip (and changed the duty cycle to 35%) , all worked fine.
I'm still puzzled by what you believe cooked the processor. What is it about 100% PWM that's risky?
Tom
liam.zbasic
Posts: 163
Joined: 24 March 2008, 23:33 PM
Location: Southern California (Blue)

Post by liam.zbasic »

I can say for certain that I over-powered the 1A motors. The LMD's have an 18V source (12 AA batteries) and 12Amp-Hour capacity. The LMD is rated at 3A continuous. When I drove the circuit at 100% duty cycle, I'm sure I went over LMD's 6Amp peak.
GTBecker
Posts: 616
Joined: 17 January 2006, 19:59 PM
Location: Cape Coral

Post by GTBecker »

liam.zbasic wrote:I can say for certain that I over-powered the 1A motors. [] When I drove the circuit at 100% duty cycle, I'm sure I went over LMD's 6Amp peak.
Well, that still doesn't explain a processor failure. My experience has been that most brushed DC motors can take overvoltage fine for a good while - and, when they have had enough of it, they spin the commutator solder joints apart and stop abruptly. Even that doesn't kill the processor.
Tom
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Post by mikep »

liam.zbasic wrote:I can say for certain that I over-powered the 1A motors. The LMD's have an 18V source (12 AA batteries) and 12Amp-Hour capacity. The LMD is rated at 3A continuous. When I drove the circuit at 100% duty cycle, I'm sure I went over LMD18200's 6Amp peak.
Going over the peak current for the LMD18200 shouldn't be a problem because it has a current limiter. The output side of the LMD18200 is completely separate from the input side. The input side is low voltage, low current.

Did you just swap out the ZX40a or both the chip and EEPROM? What happens if you just switch out the processor chip?
Mike Perks
liam.zbasic
Posts: 163
Joined: 24 March 2008, 23:33 PM
Location: Southern California (Blue)

Post by liam.zbasic »

Yes, I simply swapped out the ZX-40a and I was able to download programs again. Everything else (EEPROM, MAX232, voltage regulator, breadboard layout, etc.) was the same. I've had this issue with Picaxe 28X1 chips using the SN754410 motor controller and overloading it.

One thing I did notice was that the 9V battery powering the microcontroller chip was significantly depleted after overloading the motor controller, even though the 9V batterly was separate from the motor power source. After shutting everything down, the 9V battery's voltage would increase on its own (+0.1V every 2 seconds). I'm not an electrical engineer, but maybe the overloaded motor controller drew too much current from he ZX-40a?

I want to emphasize that I am thoroughly happy with the Zbasic chips and the visual basic programming language. My mishap in no way has reduced my admiration for the ZX-40a. Thanks.
Post Reply