Can you use 2 PWM's simultaneously?


Closed Thread
Results 1 to 10 of 10
  1. #1

    Default Can you use 2 PWM's simultaneously?

    Hello Everybody. I need to output 2 PWM's at 15KHZ (approx) simultaneously and control the duty cycles independently. The PBP manual says you can do it on PIC's with more than 1 channel. However, the PIC I want to use is 16F684. According to the datasheet, the PWM module is multiplexed among 4 possible outputs. There was also a note that changing something while the PWM is running will "cause a glitch". Will this PIC work? I need a small PIC with more than 1 PWM and if I can't use the 'F684, do I have to move up to a 28 pin PIC? Thank you.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Thumbs down bad chip ... for that purpose ( ! )

    You DO need 2 CCP or ECCP modules ... an ECCP as the 684 just drive many pins from 1 CCP.

    look for a PIC that has 2 CCP's ...

    I think you need a 28 pin package ... at least. maybe 18F series in 18 pins: 18F1230/1330, if you find some !!!

    Do a search on the µChip site for 2 CCP's ... you'll see what's possible.

    Alain

    see also here: http://melabs.picbasic.com/Scripts/perl/pic.pl
    Last edited by Acetronics2; - 29th June 2006 at 19:37.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    I'm not sure of the answer however there are two ways to produce PWM in PICBASIC. One is PWM the other is HPWM. HPWM is dependant on the pics hardware, however PWM is software based.

    Couldn't you do one output HPWM and one PWM or both PWM?

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by DynamoBen
    I'm not sure of the answer however there are two ways to produce PWM in PICBASIC. One is PWM the other is HPWM. HPWM is dependant on the pics hardware, however PWM is software based.

    Couldn't you do one output HPWM and one PWM or both PWM?
    Hi, Dynamoben

    A soft 15 kHz PWM ...??? ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    I'm not sure if it would work or not. I haven't done much PWM work. I'm just throwing the topic out for discussion.

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Thanks guys. Seems the smallest PIC with more than 2 CCP's has 28 pins. I just hate to waste about 20 i/o's - have them sit there and do nothing! As for the PWM command Ben, I want to use HPWM because once started, the HPWM constantly runs in the backround while the PIC is doing something else, until it's cancelled. This will drastically help me simplify the code.

  7. #7
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    I'm not sure what’s out there but how about using external circuitry to get the second PWM.

    http://www.edn.com/article/CA305484.html
    Last edited by DynamoBen; - 29th June 2006 at 20:32.

  8. #8
    Join Date
    Apr 2006
    Location
    Michigan
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    I have done this before. You just need to put the 2 PWM commands side by side in a for next and do it for one cycle. Adjusing the 3 that I have there will keep the same duty cycle for longer or shorter. Your eye can't tell the difference. This circuit would brighten with the push of one button and dim with the push of another. It would time out after the counter got to 1200 and they would both go out. Not energy efficient but this was one of the first programs I wrote for my thesis. It was on a 16f84a

    DUTY VAR BYTE
    sleeptime VAR WORD
    i VAR BYTE

    Input PORTB.0 'Decrease light and time button
    Input PORTB.1 'Increase light and time button

    DUTY = 127 'Set LED to half brightness
    sleeptime = 0 'Set sleeptime to 0

    START:
    For i = 1 to 3 'Go through each duty cycle 3 times or 30ms in time
    PWM PORTB.4,DUTY,1 'Output to LED
    PWM PORTB.5,DUTY,1 'Output to LED
    Next i

    IF (PORTB.1 = 1) AND (DUTY > 0) Then 'Check to see if light decrease is pushed
    Duty = Duty - 1 'Make LED dimmer by 1 count
    EndIF

    IF (PORTB.2 = 1) AND (DUTY < 255) Then 'Check to see if light increase is pushed
    DUTY = DUTY + 1 'Make LED brighter by 1 count
    EndIF

    GoSub testsleep 'Check to see if sleep creteria is met; no inputs for delay time
    GoTo START 'Return to start

    testsleep:
    IF (PORTB.1 = 1) AND (sleeptime = 1200) Then
    sleeptime = 0 'Reset sleeptime if an input is high and sleeptime is already at max
    duty = 127 'On input set the LED's to half brightness
    EndIF

    IF (PORTB.2 = 1) AND (sleeptime = 1200) Then
    sleeptime = 0 'Reset sleeptime if an input is high and sleeptime is already at max
    duty = 127 'On input set the LED's to half brightness
    EndIF

    IF (PORTB.1 = 0) AND (PORTB.2 = 0) AND (sleeptime < 1200) Then
    sleeptime = sleeptime + 1 'Increment sleeptime if no inputs
    EndIF

    IF sleeptime = 1200 Then 'If sleeptime gets to 1200 turn off LED's
    Duty = 0
    EndIF

    Return

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Another idea, even if not the best, having a 2XHPWM frequency, fed the HPWM output on a INT pin, enable the interrupt, and play with the duty in the Interupt handler... in my head it's working but i know i miss something in it....

    OR create your own with a Timer interrupt.. but geez, a little bit more tricky if you really need it 100% stable.

    Or, a double I2C DAC could be intereting... something like MAX518 if you can deal with a 8 bit resolution. They're not too cheap but great and simple to use.

    There's still the Digital pot way, or, or ,or... man it's incredible how many ways you can do it )


    What is the purpose of those PWMs?

    EDIT: Darrel already done a SSPWM solution bellow but the frequency range is probably out of what you need
    http://www.pbpgroup.com/modules/wfse...p?articleid=12
    Last edited by mister_e; - 29th June 2006 at 23:15.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10


    Did you find this post helpful? Yes | No

    Default

    Hi Steve. The purpose is for motor control. I already made a circuit using the pulsout command. It works but, if I can have HPWM running the motors in the backround, it frees-up the PIC to do other things like checking battery voltage, turn on lights, monitor the motor FET's for shorts, etc. I've pretty much decided I'll have to use a 28 pin PIC such as 16F73.

Similar Threads

  1. How to drive the Vinculum VDIP1 in UART mode
    By BrianT in forum Code Examples
    Replies: 41
    Last Post: - 23rd May 2013, 12:34
  2. USB-FTDI[UM232R] with PIC16f877a
    By bjox in forum USB
    Replies: 1
    Last Post: - 23rd February 2008, 22:40
  3. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. having problems with Hantronix 20x4 lcd
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 22nd December 2005, 12:22

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts