+ Reply to Thread
Results 1 to 23 of 23
  1. #1
    Join Date
    May 2007
    Posts
    66

    Default Darrel's Multiple Software PWM

    I just came across Darrel Taylor's multiple software PWM at http://www.darreltaylor.com/DT_INTS-14/SPWM.html

    EXCELLENT piece of coding!!
    However, I cannot find the file "DT_INTS-14.bas".
    His site allows one to download SPWM_Int.bas and Test_SPWM.pbp
    These files call the include file DT_INTS-14.bas which I can find nowhere?
    Thus I cannot compile and test the example Test_SPWM.pbp.
    Please help! Thank you!

    Passion1

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

    Smile

    http://www.picbasic.co.uk/forum/showthread.php?t=3251

    Edit: you are right - not there .. Darrel's site was hacked recently and he probably has not got it all back together.
    Last edited by paul borgmeier; - 30th May 2007 at 13:20. Reason: update
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    Join Date
    Jan 2007
    Posts
    24

    Default

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

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

    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.

  5. #5
    Join Date
    May 2007
    Posts
    66

    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.

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

    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
    __________________

  7. #7
    Join Date
    Jan 2007
    Posts
    24

    Default

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

    Whats your application btw please??

  8. #8
    Join Date
    May 2007
    Posts
    66

    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

  9. #9
    deanjhon530's Avatar
    deanjhon530 Guest

    Default Re: Darrel's Multiple Software PWM

    This program allows you to have MANY Pulse Width Modulation's being generated as an interrupt driven Background process with PicBasic Pro. It's a complete Re-Write of the original Multi-SPWM with new features added. So be sure to read this article before trying to use it.
    Features:

    Multiple Slow Speed PWM outputs simultaneously on 1 chip, limited only by the processor speed, and SPWM frequency/resolution configuration.
    Works on just about any chip. 18F or 14-bit core's.
    Each SPWM output can be assigned to ANY General I/O pin on any Port
    PWM has a maximum resolution of 8-bit (0-255) 0=Always Low, 255=Always High, but lower resolutions are also available.
    It's an Include file, for easy implementation in your program.
    Some Error checking is built in, and supplies Messages detailing the problems. Although it won't find everything you can mess up.

  10. #10
    johnson123's Avatar
    johnson123 Guest

    Default Re: Darrel's Multiple Software PWM

    Sorry, this program will only produce PWM with all channels having the same phase. I'm sure it can be done, but just not with this program.

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Re: Darrel's Multiple Software PWM

    You can get DT_INTS-14 from here ... http://www.darreltaylor.com/DT_INTS-14/intro.html
    DT

  12. #12
    Join Date
    Feb 2013
    Posts
    546

    Default Re: Darrel's Multiple Software PWM

    http://dt.picbasic.co.uk/INT14/SPWMINT

    There is written - "For instance, with a Frequency of 100hz, and a resolution of 256, it takes 25,600 interrupts per second. With each output using around 11 instructions per interrupt, it adds up to about 281,600 instructions per second, per output. Yowsa. Needless to say, you probably won't want to run this on a 4Mhz processor, although it is possible."

    Can this be translated into real world numbers? Say I want to have 4 channel pwm, with frequency 1khz, can I use above numbers to calculate actual oscillator speed needed?

  13. #13
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,259

    Default Re: Darrel's Multiple Software PWM

    So, if you want 1kHz PWM and 8 bit resolution it means the PIC needs to interrupt 1000*256=256,000 times per second. Each interrupt each channel uses 11 instructions and you want 4 channels so that's 44 instructions per interrupt. 44*256,000 = 11,264,000 instructions per second needed for the PWM generation.

    Now you need to multiply that number by 4 since one instruction cycle is Fosc/4 so somewhere around 45MHz, probably a bit more since some instructions need TWO cycles. And THEN, you won't have ANY time left to do ANYTHING else in the foreground.

    In practice, anything lower than 64MHz would be useless in that scenario and even then the PWM engine would consume somewhere around 70% of the available cycles.

    It says in the text that if you don't need the full 8 bit resolution you should specify what you actually need as it will lower the load on the poor PIC.

    /Henrik.

  14. #14
    Join Date
    May 2013
    Location
    australia
    Posts
    1,716

    Default Re: Darrel's Multiple Software PWM

    or use a real chip like PIC16F18875

    that has 5x cppm and two pwm modules so you can have 7 pwn signals on pps assignable pins
    This is more entertaining than Free to Air TV

  15. #15
    Join Date
    Sep 2009
    Posts
    774

    Default Re: Darrel's Multiple Software PWM

    Also take look at MIBAM...

  16. #16
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    308

    Default Re: Darrel's Multiple Software PWM

    In combination with multiple CCP/PWM modules, modern PICs have DSM and CLC engines that can combine multiple PWM cycles (at differing frequencies & DC%) into a single output signal.
    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.

  17. #17
    Join Date
    Feb 2013
    Posts
    546

    Default Re: Darrel's Multiple Software PWM

    Thanks a lot. I don't need 8 bit resolution, 16 levels (4 bit) will be fully enough. This will be used to drive RGBW led. Regarding the "stronger" PICs, I've tried to use some with 4 PWM channels, but as it seems, you can't control them independently - max 2 channels at the same time. So I did a workaround - "master" 16F870 was driving "slave" 12F683's, and they were generating PWM as needed (16 channels total). Then I bought LT8500 chip, for 48 channel PWM, but was not able to program it with PBP.....

  18. #18
    Join Date
    Sep 2009
    Posts
    774

    Default Re: Darrel's Multiple Software PWM

    Why not?

    Take look at MIBAM it is designed for driving LEDs, and you can have 256 levels of intensity with just 16 interrupts per cycle. That is far less than SPWM.

  19. #19
    Join Date
    Mar 2005
    Location
    CROATIA
    Posts
    40

    Default Re: Darrel's Multiple Software PWM

    mibam rocks ! i used it on small 16f pic with 12 ch, it work like a charm, with lot "lighting rules" in software, no flickering at all....

  20. #20
    Join Date
    May 2013
    Location
    australia
    Posts
    1,716

    Default Re: Darrel's Multiple Software PWM

    Quote Originally Posted by CuriousOne View Post
    Thanks a lot. I don't need 8 bit resolution, 16 levels (4 bit) will be fully enough. This will be used to drive RGBW led. Regarding the "stronger" PICs, I've tried to use some with 4 PWM channels, but as it seems, you can't control them independently - max 2 channels at the same time. So I did a workaround - "master" 16F870 was driving "slave" 12F683's, and they were generating PWM as needed (16 channels total). Then I bought LT8500 chip, for 48 channel PWM, but was not able to program it with PBP.....

    not if you do it properly
    http://www.picbasic.co.uk/forum/show...light=16F18875
    This is more entertaining than Free to Air TV

  21. #21
    Join Date
    Feb 2013
    Posts
    546

    Default Re: Darrel's Multiple Software PWM

    I'm doing studio RGBW led illumination, so I have no idea whenever MIBAM will be seen by camera as flicker. Contrary to that, I've tested "normal" PWM and 1Khz is enough for camera not to "see" it.

  22. #22
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    308

    Default Re: Darrel's Multiple Software PWM

    I just happen to be doing a project with the PIC18F46K42 so it's fresh on my mind. It has 4 CCP channels capable of outputting PWM, plus it has 4 PWM channels. All 8 channels can be controlled independently, all 8 can be assigned TMR2/4/6 independently for up to 3 different frequencies. I recall PICs with more CCP/PWMs and more TMR2/4/6/8/10 timers for even more flexibility. Check Microchip's part finder:

    http://www.microchip.com/ParamChartS...branchID=30048
    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.

  23. #23
    Join Date
    Sep 2009
    Posts
    774

    Default Re: Darrel's Multiple Software PWM

    I didn't test with multiple camera, but flicker should be much less than PWM at same freq.

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 : 16

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