Darrel's Multiple Software PWM


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Jan 2007
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    I have these files somewhere. if I can find them I will post them (if that's OK with Darrel)

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


    Did you find this post helpful? Yes | No

    Default

    I've uploaded the whole package few weeks ago
    http://www.picbasic.co.uk/forum/show...&postcount=210
    Steve

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

  3. #3
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Steve

    Thank you for pointing me in the right direction!

    I just realized that Darrel's code is a slow SPWM and cannot handle high frequencies (e.g. up to 20KHz).

    I would like to generate two frequencies simultaneously where the one is a
    multiple of the other, e.g Freq 1 = 10 kHz, Freq 2 = 20KHz
    I do not need to vary the duty cycle. I only need a duty cycle of 50%, thus
    either on or off.

    Darrel's code would have been perfect if it could handle higher frequencies.

    I cannot use the hardware PWM because all PICs with multiple PWM outputs that I know of, share the same timebase.
    Thus the frequency must be the same on all the outputs, but the duty cycles are individually controllable. I don't know of a PIC that's an exception

    In short, I am looking for a software PWM that is capable of handling 2 different frequencies simultaneously, where each frequency may vary up to 20KHz. I have looked everywhere but could not find any example code to this.

    I will appreciate any help or suggestions.
    Last edited by passion1; - 31st May 2007 at 07:16.

  4. #4
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    Are the two fequencies always a factor of 2X apart? (10kHz and 20kHz)
    What else does this PIC need to do?
    Do the two PWM need to be in phase?
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  5. #5
    Join Date
    Jan 2007
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    PWM and maybe a programmable divider OR a divider and a MUX to select the appropriate frequency multiple.

    Whats your application btw please??

  6. #6
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Thank you guys.
    I got the following clever code from MeLabs support, that solves my problem. It produce simultaneous frequencies of 20KHz, 10KHz, and 5KHz:

    DEFINE OSC 20 ' Use a 20MHz crystal for best results

    freq_delay VAR WORD

    freq_delay = 25 ' 25uS for 20KHz top frequency ((1/20K)/2)
    TRISB = %11111000 ' freq pins to outputs

    ' Output 20KHz on RB0, 10KHz on RB1, 5KHz on RB2
    ' Adjust freq_delay to compensate for loop overhead
    loop:
    PAUSEUS freq_delay
    PORTB = (PORTB & %00000111) + 1 ' count binary 000 to 111
    GOTO loop

Similar Threads

  1. Software PWM
    By muqasim in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2009, 14:21
  2. Software PWM using Timer1
    By muqasim in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2009, 11:49
  3. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  4. Variable PWM on 2 Channels using software.
    By Tissy in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd September 2006, 01:34
  5. Software PWM Problems
    By surfer0815 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th November 2005, 13:53

Members who have read this thread : 0

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