Shop OBEX P1 Docs P2 Docs Learn Events
Background PWM — Parallax Forums

Background PWM

wcumminswcummins Posts: 12
edited 2013-04-08 07:22 in BASIC Stamp
hi, I'm new to Basic Stamp. I've been looking at the commands and was wondering if it is possible to get a background PWM. That is a continuous PWM without the restraint of Duration?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-04-07 07:29
    No. The Basic Stamp is a single threaded microprocessor. It can do only one thing at a time. When the PWM statement is executing, it produces a pulse stream whose average on time is what is specified. When the duration period is over, the pulse stream ceases. It's intended to be used with an RC network to charge the capacitor to a desired voltage (Digital to Analog Converter). To get a continuous true PWM signal, you'd need to use some kind of external device, something like a 556 dual timer or another microprocessor.

    The Propeller, because it's a multiprocessor (8 independent cores), can do this. It's possible for a Basic Stamp to approximate this in some circumstances, by interleaving code for generating the pulses with other things. Servo motors are slow enough for this. They only need a PWM pulse about once every 20ms and the pulse width ranges typically from 1ms to 2ms. That leaves about 18ms for the Stamp to do other things.
  • wcumminswcummins Posts: 12
    edited 2013-04-07 07:35
    Thanks Mike for explaining that! Wayne
  • CuriousOneCuriousOne Posts: 931
    edited 2013-04-07 09:57
    Actually, multi-core and number of threads often have nothing to do with PWM. A lot of MCUs contain separate PWM circuit, which could be run on it's own, but I never heard any of manufacturers calling such MCU's "multi-core" devices :D
  • Mike GreenMike Green Posts: 23,101
    edited 2013-04-07 10:20
    No, they're not "multi-core" devices because things like a PWM circuit (or UART or timer or ADC or ...) are peripheral devices with no real "intelligence". They usually have a simple state machine in them and are controlled otherwise by the single microprocessor. Parallax's Propeller uses software-defined peripherals by design. Although the Propeller has 8 identical "cores" ... full microprocessors, in most applications several are used as peripheral processors containing a serial UART or complete video generator for TV or VGA (as opposed to the video generation hardware which is just a smart shift register) or servo motor controller or general PWM generator or whatever.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-04-07 11:02
    Another alternative for the BASIC Stamp is to use a coprocessor. Parallax used to sell one called the PWMpal, but I think that is retired. There is still the Motor Mind, or the HB25, which both generate the continuous PWM and power to drive a DC motor (if that is what you want to do!). Or take a look at Solutions Cubed. Al Williams, at one time a regular participant here, still seems to have available a PAK5/PWM Coprocessor with 8 simultaneous outputs. All of those are controlled by sending serial commands from the BASIC Stamp.
  • CuriousOneCuriousOne Posts: 931
    edited 2013-04-07 22:06
    Or another alternative is to use picbasic pro, which in syntax is quite close to basic stamp, but offers hardware pwm control. Sure, price may be prohibitive for most users, but student edition might be affordable.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-04-08 07:00
    I've used PICBasic Pro. Yes, it has PWM that runs continuously in the background, but I wouldn't recommend it for beginners. It's a good product, but not for beginners. I had a lot of trouble with some of its features and could never get some of them to work properly despite being familiar with PIC assembly language. I'd use a coprocessor like the PAK5/PWM.
  • wcumminswcummins Posts: 12
    edited 2013-04-08 07:22
    Thank you for all your comments, I have been using PICBasic Pro for some time now and have an application using a PIC16F866 to drive a large scrolling display. The display requires a continuous square wave for timing. I have started doing some work with local high schools that use BASIC Stamp ( which I’ve never used before) on Home Work Boards and Boe-Bots. I wanted to use the Home Work Board for a demonstration to drive the display for the students. That is why I ask the question about Background PWM. I have decided to use a 555 timer on the Home Work Board to generate the needed 1k square wave for the display. I asked the question about Background PWM because I wasn’t sure if Basic Stamp had hardware PWM.
Sign In or Register to comment.