SX28 and PWM
Could someone just verify that the PWM output is just plain-old regular PWM (you know, a square wave with varying duty-cycle)?· I know this is a stoopid question, but most of the examples I have looked at on the web are using PWM to create analog voltages.· I just want to drive a MOSFET for a simple dc motor controller.
Larry
Larry
Comments
The SX/B PWM command is intended for use in creating analog output voltages. For example, with a 50% duty cycle setting the result is a stream of high and low pulses of equal durations during the time interval specified. If you want to control the speed of your motor this might work for you. However, if you want to create just a single pulse output (which you can repeat to make a pulse stream) where you determine how long the pulse is high and how long it is low you will probably want to use the PULSEOUT command instead.
The PULSEOUT command will create a pulse with a single transition within the time period specified. The PWM will likely generate many transitions during the time period specified.
Example outputs where H = HIGH, L = LOW
PULSEOUT: HHHHHLLLLL at 50%
PWM: HLHLHLHL at 50%
NOTE: The SX48 has two internal timers you can use to set up two pulse streams in hardware that continue to run on their own once configured. These are very nice for motor control! If you are using an SX48 be sure to consider them!
I hope this helps.
- Sparks
Here's what I want to do and it's real simple: Footswitch depresses and motor goes fast.· Press again and motor goes slow.· This action will toggle between fast and slow until the footswitch is held for more than 2 seconds. At this point, the motor goes off.· I'm trying to simulate the action of my Leslie 2101 Treble unit (you know, the speaker that rotates).· I made a bass unit with a rotating drum, but the ac motor is single-speed.· I would like to convert the motor to a dc motor and adjust the speed via a pwm system.· Since I already coded the footswitch in SX/B to light LEDs for fast and slow and off, I was hoping to just add some pwm code to drive a MOSFET and a motor.
I bought a couple of IRF510s and couple of heatsinks (I only need one - I'm not making an H-bridge) and I'm ready to burn something out <g>.· Luckily everything I'm playing with is cheap. And no, I don't have the final motor yet.· All I have is a Radio Shack hobby motor for testing.
Larry
· There are a couple options.
· One would be to use the SX48 timers.
· Another would be to create an interrupt driven PWM routine (this is fairly easy).
· Note that the SX/B PWM command is meant to generate an analog output. It doesn't work well for motor control because the PWM pulses are narrow.
· If you post your current code, I will show you how to modify it for an interrupt·generated PWM output.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
Post Edited (Bean (Hitt Consulting)) : 3/21/2008 12:08:52 AM GMT
Thanks to everyone who replied.
Larry
I've got a vintage Leslie 122 here (together with a Hammond B3), and I also was thinking to replace the old two-speed AC motor units by something new in the future. I did some testing with brushless DC motors available from Papst, a German company. These motors come with integrated driver electronics, and their speed can be controlled over a wide range by applying a DC voltage from 0 to 5V to an input.
Although these motors are way more expensive than simple hobby motor, there is no need for any gears, or capstan drives as on the olt original units, and these motors are very silent.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
It's pretty easy to create "background" PWM with an interrupt -- that would save you the trouble of external circuitry.
as JonnyMac said, PWM signals can be generated with any type of SX using a timed interrupt. The "larger" SX48 offers the additional "luxury" of two multi-purpose timers/counters that can be configured to generate PWM output. Nevertheless, the "smaller" SXes are powerful enough to generate one or more PWM signals with an interrtupt routine.
For one of my commercial applications, I'm using an SX28 to generate three independent PWM outputs for controlling three DC motors. This design works "rock-solid", and there are over 800 units out in the field so far. So why using 555s and logic gates - the SX can handle all the tasks you are looking for - PWM, and reading the footswitches.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
And can I do it with SX/B instead of SASM? I've lost my assembly-language skills way back in 1980 when I learned 'C' <g>.
Larry
Thanks again.
Larry
When using interrupts in SX/B any time-based processes are affected; you'll see that this example has a replacement for PAUSE that uses cycles through the interrupt for timing.
(File removed -- replaced with update below)
Post Edited (JonnyMac) : 3/23/2008 5:29:17 PM GMT
L
I actually found a small error (I just got home from a trip and have my scope packed -- sorry). Give the version attached to this message a try.
Post Edited (JonnyMac) : 3/23/2008 5:32:09 PM GMT
By running at 4MHz instead of 20, the ISR is still run 153000 times per second, but all the other timing is off, right? The one second pauses are now 5 seconds (of course). So did the pwm frequency go down to 100Hz then? Doesn't really matter, I guess. And I think I'm getting a scope on Monday (a real Tektronix (sp?), not a usb). That'll help me make sense of it all.
Thanks again,
Larry
Sorry to resurrect an old thread, but this is my first post here and I'm not sure how else to ask directly about this code of yours..
I works well, but I have two questions:
1. Why do you use the DELAY_MS subroutine?
2. Would it be possible to incorporate SPI into this ISR?
My SX28 is going to be a slave device running 50MHz, and I want to send duty cycle (as well as other commands) via SPI
Thanks
2. I'm sure it is but I've never done it (I'll bet my pal, Gunther, has). Why use SPI? Can you use serial? -- easier to implement (one wire versus 3) and many of use have a lot of code that is ready to use. Bean has done some work turning the SX into an SPI slave -- you might do a search.
[noparse][[/noparse]Edit] Found Bean's SPI code -- though it uses edge-triggered interrupts which won't help you with the PWM stuff.
-- http://forums.parallax.com/showthread.php?p=671517
Post Edited (JonnyMac) : 2/16/2009 11:32:07 PM GMT
The reason for SPI is that I have an entire bus of various devices (digital pots, 14bit ADCs, etc) that are all being controlled via USB --> SPI.
I am integrating the PWM and digital I/O capabilities of the SX as a further development (without starting from scratch).
I think I had found that SPI code, but thank you. I will try my hand at integrating the two into one interrupt unless this seems like something good for TASKs.
My PWM cycle is only 60 Hz, so accuracy should be easy to attain.