Shop OBEX P1 Docs P2 Docs Learn Events
SX/B 16 channel PWM and/or SERVO controller — Parallax Forums

SX/B 16 channel PWM and/or SERVO controller

BeanBean Posts: 8,129
edited 2008-09-25 02:42 in Robotics
Here it is. A 16 channel PWM controller using the SX28 written in SX/B.
Please ask if you any questions.
If there is enough interest I could make a PCB for the project.

I set the baud rate to 2400 so BS1 user can use it. (EFX Prop-1 ?)

Note that it generates true "duty cycle" PWM so you can use it for motor control.
The PWM rate is about 195 Hz so there won't be any flicker for LED use.

Edit: PWM_SERVO16.SXB can control PWM or servos. The Servo control is a little rough (20uSec steps), this means that 50=Hard left(1.0mSec), 75=Centered(1.5mSec) and 100=Hard right. If your continuous servos are adjusted properly you should be okay.

Enjoy, Bean.

·

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012


Product web site: www.sxvm.com

"It's not getting what you want, it's wanting what you've got."


Post Edited (Bean (Hitt Consulting)) : 5/18/2005 1:22:25 AM GMT
«13

Comments

  • Russ FergusonRuss Ferguson Posts: 206
    edited 2005-05-14 14:11
    Bean:

    Thank you for posting this. I havn't worked with the SX parts yet, but this sneak peak is very helpful. It may be that I will be able to get the SX tool kit early this summer.

    I am currently using a dedicated BS2 OEM to do PWM on an h-bridge for two DC gearmotors. Don't use serial though, use 8 pins as a buss to control two PWM pins. The motors do not run smoothly at slow speed and so I have some reading to do about how others do PWM for motors.
  • BeanBean Posts: 8,129
    edited 2005-05-14 14:38
    Russ,
    Thanks, I hope it helps you get started. That's the whole purpose of these forums.

    The PWM that the BS2 generates is NOT intended for motor control.
    If you have ever looked at the PWM on a scope you will see what I mean. I looks like a bunch of random pulses. These pulses "average out" to whatever PWM value you have specified.
    But motors don't handle these random pulses, they want a single pulse with a duty cycle of whatever PWM value to have specified.
    That's why I specifically made this project so it could be used for motor control. If you look at the output of the SX on a scope you will see a nice pulse of varying duty cycle.

    It takes 20 bytes to set all 16 PWM outputs, at 2400 baud that's 240 characters a second. That's 12 times a second. So you can change the PWM values a maximum of 12 times a second.
    The project may be able to run at a higher baud rate, but because of the "fudge factor" caused by the interrupt, I didn't want to push it, and risk getting invalid data.

    I'm thinking about expanding this project to make each output programmable to be PWM OR Servo control (0.5 to 1.5mSec pulse every 20mSec). That would be sweet...

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video Display Module" Available Now.

    www.sxvm.com

    "Great people talk about great things, average people talk about average things, small people talk about other people."
    ·
  • Russ FergusonRuss Ferguson Posts: 206
    edited 2005-05-15 05:00
    Bean:

    We didn't spend much time working with the PBASIC PWM function.

    Simply wrote a loop with 'HIGH pin', 'PAUSE timehigh', 'LOW pin', and 'PAUSE timelow' after setting the values based on INA when it changed. A student and his father were doing most of the work. We were trying to get two PWM type pulses on two pins of the one stamp, so the timing of the math needed to be pretty good.

    The project is on the back of the bench right now and it has not been touched for a couple of weeks. We were aiming at having it ready for the Tanner Electronics Robot Show but did not have it ready. Our home schooling year has ended and I've got some big projects at work right now, so I probably won't look at it again until my 'TODO list' gets down to 'Learn basics of SX'.



    I agree with you that it would be great to have Servo control on this application of the SX.

    It would also be great to add the output pins to support 'forward' and 'reverse' on the h-bridges.

    Russ
  • BeanBean Posts: 8,129
    edited 2005-05-17 13:27
    A member asked for some comments in the interrupt section. So I added some and re-posted.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012


    Product web site: www.sxvm.com

    "It's not getting what you want, it's wanting what you've got."
    ·
  • steve_bsteve_b Posts: 1,563
    edited 2005-05-17 15:14
    Bean, you mentioned the PWM of this SX not being suitable for motor control.

    Would a mosfet (or like) attached to the output with a cap (in some arrangement) give enough of a buffer inbetween these random pulses to give you motor control?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://ca.geocities.com/steve.brady@rogers.com/index.html
    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-05-17 15:52
    No, what Bean was saying is that PWM from a *BS2* is not intended for motor control...

    The SX should do this just fine (as in Bean's code)-

    Bean, what is the easiest way to make this selectable for Servo/motor (like you stated above)? That is something that I would really be interested in. I've already started rough design for a PCB also [noparse];)[/noparse]

    Thanks again, I really learn alot from you guys.

    Ryan
  • BeanBean Posts: 8,129
    edited 2005-05-17 16:50
    Ryan,
    I have already started a version that allows each port (8 channels) to be configured as PWM·or·Servo lines.
    I will post it as soon as I can.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012


    Product web site: www.sxvm.com

    "It's not getting what you want, it's wanting what you've got."


    Post Edited (Bean (Hitt Consulting)) : 5/17/2005 6:16:09 PM GMT
  • BeanBean Posts: 8,129
    edited 2005-05-17 22:48
    Okay I posted a version that can do PWM and/or Servo control.
    Each port (8 channels) must be the same (PWM or Servo), so the options are
    16 channels of PWM
    8 channels of PWM & 8 channels of Servo
    16 channels of Servo control

    Any questions please ask.

    Gotta love SX/B man....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012


    Product web site: www.sxvm.com

    "It's not getting what you want, it's wanting what you've got."
    ·
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-05-17 22:55
    Thanks so much! I can't wait to get home and play with this code...

    Ryan
  • RickBRickB Posts: 395
    edited 2005-05-18 15:03
    Thanks, Bean
    This conversion may take a while since I am just learning the avr instruction set, but when I get it working, you will see it. Thanks again.

    Rick
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-18 15:24
    Rick,

    ·· What AVR conversion are you referring to?· I didn't see anything in this thread about that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • BeanBean Posts: 8,129
    edited 2005-05-18 17:03
    Chris,
    Rick is referring to a reply I made to a private message he sent me. I had said that I would like to see the code if he gets it working.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012


    Product web site: www.sxvm.com

    "It's not getting what you want, it's wanting what you've got."
    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-18 17:40
    Conversion to AVR?· Or SX?· that's where I was lost...· tongue.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • RickBRickB Posts: 395
    edited 2005-05-19 14:55
    Chris: Conversion to avr code and rvk basic.

    Rick
  • BeanBean Posts: 8,129
    edited 2005-05-19 15:11
    Rick,
    I'll be surprised if the avr has enough MIPS to do the job. Unless you add some additional hardware. That's the nice thing about the SX is so damn fast...
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012


    Product web site: www.sxvm.com

    "It's not getting what you want, it's wanting what you've got."
    ·
  • James NewtonJames Newton Posts: 329
    edited 2005-06-04 00:38
    Bean, how does your serial recieve routine work with the ISR? Isn't it possible for the ISR to disrupt the timing of the recieve? Or is it just too small an interruption to matter?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ---
    James Newton, Host of SXList.com
    james@sxlist.com 1-619-652-0593 fax:1-208-279-8767
    SX FAQ / Code / Tutorials / Documentation:
    http://www.sxlist.com Pick faster!



  • BeanBean Posts: 8,129
    edited 2005-06-04 00:46
    James,
    Your right, the interruption is quick and evenly spaced (that's why all paths of the ISR code MUST take the same number of cycles).
    And the baud rate is adjusted to account for the time spent in the ISR. Tricky...But greatly simplifies the ISR code.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012


    Product web site: www.sxvm.com

    "It's not getting what you want, it's wanting what you've got."
    ·
  • Daniel_NYCDaniel_NYC Posts: 3
    edited 2005-07-03 05:01
    Dear Mr. Bean et al.

    ·
    I am an artist that works in interactive electronic art.· It was interesting to read that others have found the same problem as I have when using the Basic stamp to control an RGB LED matrix.· My application calls for· 72 RGB LED clusters to control their brightness, the level of the R,G, and B LEDS to blend a color, and on top of all of that to chase the first second and third clusters so the there is a slight wavering rotating around the perimeter of the piece.· I saw your work with the SX chip could this be adapted to run a 6X 6 matrix to give me two 36 LED sections.· My current matrix is 9 X 12 but I can still adapt my circuit.· Any thoughts?
    ·
    Thanks for any help you can offer
    ·
    Daniel Nauke
  • BeanBean Posts: 8,129
    edited 2005-07-05 13:23
    There seems to be alot of interest in controlling RGB LED matrixes. I have sent an 8x8 PWM controller to some people, but I have not heard anything back yet. With the new SX52 proto boards I will experiment in making a 3x8x8 controller. The main problem is the amount of RAM required. 3x8x8 would require 192 bytes, which the SX52 has, BUT if you want the display to update instantly you need to buffer the new data until you receive it all. That would require another 192 bytes for a total of 384. The SX52 doesn't have that much RAM. Hmmm, maybe a 2x8x8 controller would be possible...

    I assume an 8x8 RGB LED matrix has 32 connections ?

    When I get my proto boards I will try some experiments.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    Product web site: www.sxvm.com

    "What's the difference between ignorance and apathy ?"
    "I don't know, and I don't care."
    ·
  • NauketecNauketec Posts: 51
    edited 2005-07-05 16:14
    Bean

    Thanks for the speedy answer!· I have several art pieces that will use a backlight effect.· To do this I would like to use 2 sets of 36 RGB LED "clusters"

    ·I would like to have control of the R, G, B LEDS so that I can blend them to make·various colors, and I would also like to be able to dim and brighten the entire set of LEDS.· The last effect is the one that adds the fun to the task - I would like to have the LEDs kind of quiver.· To do this I thought of chasing them either 123 - 123· - 123 or 1234 - 1234 - 1234 where one cluster would be just a bit brighter as it revolved around the 36 LED clusters.

    I built a circuit with a Basic Stamp 40 pin using a 9 x 12 matrix but it does have the blinking problem.· Your work with the SX chip sounds like it could be an answer.· Thanks for the help!

    Daniel Nauke

    Nauketec@nauke.org
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-07-05 19:30
    Bean, in my messing around with your PWM code to drive RGB LEDs, I found 8 bits/channel to be excessive. The optimal level (not really noticible) seems to be between 5 and 6 bits (32-64 color shades). I found 4 bits (16 shades) produced a noticible shift in color but almost tolerable for fluid color shifting. Anyways the point Im trying to make, is perhaps two color channels can be packed into each byte (one per nibble), producing a reduced color range but double the addressable elements.
  • BeanBean Posts: 8,129
    edited 2005-07-05 19:55
    Cool,
    That would make the project possible. Thanks for the info...
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    Product web site: www.sxvm.com

    "What's the difference between ignorance and apathy ?"
    "I don't know, and I don't care."
    ·
  • OakGraphicsOakGraphics Posts: 202
    edited 2005-07-08 14:11
    Bean - just to let you know, I would be interested in a pcb. smile.gif (you mentioned earlier you were thinking if anybody would be interested if you made a pcb for the project.)
  • StarManStarMan Posts: 306
    edited 2005-07-08 16:08
    I would also be interested in a board.· But even just a roughed out schematic as a starting point to make my own board would be really cool.

    BTW I just got my SX kit yesterday and I will be coming back for a few questions from time to time.· They will probably be very basic questions as I am way out of my comfort zone with this.

    Right now I have to hop on a plane.· I'll be taking Guenther's book with me.



    Thanks,

    Chris I.
  • BeanBean Posts: 8,129
    edited 2005-07-08 18:16
    I will make a PCB, I need to try-out my new pulsar PCB kit anyway. I should be able to make it single sided.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    Product web site: www.sxvm.com

    "One experiment is worth a thousand theories"
    ·
  • DigitalDjDigitalDj Posts: 207
    edited 2005-08-08 02:33
    Bean,
    1. Can this chip be addressable so it can be used for more than 16 pwm outputs, say i want 32 or 48 etc.?
    2. Could you explain or give an example by pic using led's in a matrix?
    3. The other thing that would be nice is the ability to change PWM!

    With my research i believe that true RGB is best handled by red, green and blue each having thier own PWM frequency because the color mixing as how the computer does it to how the LED's do it is not linear( if that's the proper word). I have not tried the different PWm for each color but that is my next project.

    Is the SX28 fast enough to process audio and turn the pwm outputs off and on? If you could get this chip to do 3 inputs of audio and allow you to choose what outputs you want those to·control you would definately have a great chip. The 3 audio inputs can be processed from filters for low, mid and high audio. Of coarse you would loose some pwm outputs for the audio input. Audio and making the chip addressable would be great.


    ·I have done alot of research with doing color mixing with led's using pulse width modulation i believe that true RGB is best handled by red, green and blue each having thier own PWM frequency because the color mixing as how the computer does it to how the LED's do it is not linear( if that's the proper word). I have not tried the different PWm for each color but that is my next project. Positioning led's within cubes etc. for proper illumination is also a task. I spent months developing some color cubes using red, green and blue led's and found out a couple of limitations. First if using a computer, the computer generates perfect examples of color but will not generate the same colors to the led's and of coarse you can not develope the color black. It is very important to use the proper wavelengths of red, green and blue led's to get true RGB. In some cases·you can use twice as many led's·to generate a brighter red otherwise your current limiting resistor values·will have to be increased because of green and blue are much brighter.

    Kevin


    Post Edited (DigitalDj) : 8/9/2005 2:05:22 AM GMT
  • OakGraphicsOakGraphics Posts: 202
    edited 2005-08-09 01:45
    Hey bean - hows the matrix 8x8 coming?
    I saw another post in the sandbox about making an 8x8 and I thought it would be cool to have some fun features for your 16 channel pwm controller. smile.gif

    How about being able to send a 'transition time' to them? Basically the pwm are being used to light led clusters - it would be cool to tell the channel to go from red to blue in so many seconds. Sure the pc or whatever that is talking to the board could do that as well, but I think it could be done smoother on the chipside. (and less things to send to the board - kinda like a 'target' pwm and time to get there. It would also be cool if there was a 'global' channel for the same thing. If all of the channels are on different locations/colors and a global command and transition value is sent, then they would all change from what they are to the target gradually - and independently.


    Might be too complex / too many variables. (shrug) I really gotta get into sx/b programming as you are really showing me the potential of whats available on this side of microcontrollers. smile.gif
  • BeanBean Posts: 8,129
    edited 2005-08-09 12:31
    I've been busy with the video overlay project, so I haven't done much with the PWM program.
    The next step will be to make a 8x8 multiplexed PWM program. For a single color LED matrix.
    Then a 8x8x3 multiplexed PWM program. For a RGB LED matrix.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    Product web site: www.sxvm.com

    "One experiment is worth a thousand theories"
    ·
  • hutdonhutdon Posts: 32
    edited 2005-08-09 15:50
    Bean, I would also be interested in a board(s).

    Don L.
  • OakGraphicsOakGraphics Posts: 202
    edited 2005-08-11 19:07
    Bean - that sounds cool. smile.gif

    say - how many LED's do you think we could string on each PWM channel? (or would this just be an 'attach a transistor/resistor/capaciter circuit to increase voltage' type of thing? (my first guess. smile.gif (Or would we use a fun chip like a ULN2803 to 8 of the PWM lines - which I see as totally do-able. smile.gif


    I understand about the overlay project taking priority - expecially since I want one of those too! smile.gif

    Did you get your sx52 boards yet?

    Daniel
Sign In or Register to comment.