Modifying Darrel's SSPWM resolution?


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1

    Default Modifying Darrel's SSPWM resolution?

    This is probably a question for Darrel.

    Anyway i'm using his excellent SSPWM to generate a 2khz pwm output on a 16F88 pic running at 8mhz.

    The 1% Duty resolution available as standard works fine.
    But can that be increased to 0.1% resolution? Or perhaps 0.5% resolution.

    What would I need to change? I see DutyCycle is a byte variable so that needs to be a word if DutyCycle was going to be expanded to 1000 units. It looks like simply a matter of the maths to calculate the TMR1 duty periods but that's not my strong point

    http://www.pbpgroup.com/modules/wfse...d.php?fileid=3

    Thanks Peter

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Modifying Darrel's SSPWM resolution?

    Still looking for a bit of advice/guidance re this if possible please.

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


    Did you find this post helpful? Yes | No

    Default Re: Modifying Darrel's SSPWM resolution?

    The CalcSPWM: routine calculates the prescaler and ON/OFF times for the PWM.
    Then the Timer interrupts do the rest.

    You can calculate those times any way you want.
    SSPWM calculates for different OSC frequencies, PWM frequencies and dutycycles.
    But if you know the OSC and PWM frequency ahead of time, it will be easier for you to do the math.
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Modifying Darrel's SSPWM resolution?

    In my application the osc is always 8mhz and the frequency is always 2khz, the duty changes from 10-90%.
    Your routine works very well I just want to try and increase the resolution to 0.1%

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Modifying Darrel's SSPWM resolution?

    I'm going to try using a few different values for the duty and get my software to display your calculated values for T1CON, TICKS, TMR1_ON_TICKS, TMR1_OFF_TICKS. Then I will use TICKS & T1CON as constants and remove all the calculation stuff does that sound reasonable? My maths & pic knowledge is not good enough to see how all your calculation routines work

    I'll just leave the final duty calculation part in

    W1 = Ticks * DutyCycle ' Calc # of Ticks for ON and OFF periods
    TMR1_ON_TICKS = div32 100
    TMR1_OFF_TICKS = Ticks - TMR1_ON_TICKS

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Modifying Darrel's SSPWM resolution?

    I tinkered around and found that with my 8mhz int clock and 2khz pwm the prescaler was being set to 1 and ticks was 1000 per cycle. 50% duty Time on/off was 500 ticks each. This suggests that resolution can be increased to 0.1% by changing DutyCycle to a word variable and using 500 instead of 50 to represent 50% duty. I have adjsted the calculation so it now ranges from 0-1000 in steps of 1 instead of steps of 10. I also removed all the calculation routines as ticks are now known as is prescaler etc. That save quite a few bytes as well

    Darrel any comments?

    Peter

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