Unstable sine PWM output


Closed Thread
Results 1 to 30 of 30

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: Unstable sine PWM output

    Thanks for your help.

    So I've tried first to set a fixed reload value (64594) without calculations (to obtain 120Hz sine, the max. frequency). The sine wave was perfectly stable on the oscilloscope.

    This :
    dum=dum1*dum2
    reload=DIV32 freq
    reload=(65535-reload)+8
    was removed and replaced with :

    reload=64594
    I've also applied Henrik tips, like this :

    Code:
    ' Frequency reference control by potentiometer
    potsense=(potsense<<6)**maxfreq
    IF potsense<>freq THEN 
    freq=potsense
    flag=%1
    endif
    And set the reload calculation routine into the main loop.

    Results : it's more stable, but the glitches still appears when I change the frequency of the sine (so the reload calculation routine is executed during this time).

    I'm pretty sure that the problem is caused by DIV32. However this routine is needed :

    dum=dum1*dum2
    reload=DIV32 freq
    reload=(65535-reload)+8
    How to replace the "DIV32" by an another thing? It is possible to use that : http://melabs.com/resources/fp.htm ? Or anything else?
    Last edited by pxidr84; - 13th May 2011 at 17:28.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Unstable sine PWM output

    Hi,
    It might be the DIV32, we'll have to get Darrel to answer that or have someone dig into the ASM code and figure out if the PBP registers used by DIV32 are being saved by DT-Ints or not (I still think they are).

    My guess is that it isn't actually DIV32 that is causing it but something else with the way the frequency is changed. Why not try constantly ramping the frequency up and down in your main loop? Don't use DIV32, just "sweep" the reload value up and down between your MIN and MAX values. Does it still glitch? If so we know that it's not DIV32 that's causing it but something else.

    If it turns out that it IS DIV32 then we can look at other solutions. The DIV32 thing was in response to your request of directly calculating the reload value based on the desired output frequency scaled in Hz. Simply rescaling to some arbitrary "unit" might allow the calculations to be done without DIV32 but it comes with a couple of commitments which I won't go into until we know that that DIV32 is the problem.

    Can you explain to me where the values 34696 and 32 comes from?

    /Henrik.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Unstable sine PWM output

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    It might be the DIV32, we'll have to get Darrel to answer that or have someone dig into the ASM code and figure out if the PBP registers used by DIV32 are being saved by DT-Ints or not (I still think they are).

    My guess is that it isn't actually DIV32 that is causing it but something else with the way the frequency is changed. Why not try constantly ramping the frequency up and down in your main loop? Don't use DIV32, just "sweep" the reload value up and down between your MIN and MAX values. Does it still glitch? If so we know that it's not DIV32 that's causing it but something else.

    If it turns out that it IS DIV32 then we can look at other solutions. The DIV32 thing was in response to your request of directly calculating the reload value based on the desired output frequency scaled in Hz. Simply rescaling to some arbitrary "unit" might allow the calculations to be done without DIV32 but it comes with a couple of commitments which I won't go into until we know that that DIV32 is the problem.

    Can you explain to me where the values 34696 and 32 comes from?

    /Henrik.
    I've done like you said a simple ramp in the main loop :

    Code:
    reload=reload-1
    if reload<40000 then reload=64600
    The sine frequency ramped down, and after many cycles, no glitch appeared on the oscilloscope. During this time I've played with the potentiometer to vary the amplitude and also I navigate into the inverter menu, the sine wave was not disturbed at all.

    So the problem is clearly DIV32. Apparently this command disturbs DT Instant Interrupts.

    I've already changed the "34696" and "32" dummy values to "1120" and "1000", it's far better to understand.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Unstable sine PWM output

    So the problem is clearly DIV32. Apparently this command disturbs DT Instant Interrupts.
    Or the other way around, or there's a problem with the actual values being calculated like overflow/ underflow/whatever. I'm still not convinced but it seems you are so lets go with that for now.

    OK, you're using an analog input to set the desired output frequency, the ADC have a resolution of 10 bits giving you a value of 0-1023. If we're going to try to come up with an alternative way to calculate the reload value (not using DIV32) can you tell us:

    A) What is your minimum output frequency, ie what frequency should an ADC value of 0 give and what TMR1 reload value does that frequency require?

    B) What is your maximum output frequency, ie what frequency should an ADC value of 1023 give and what TMR1 reload value does that frequency require?

    /Henrik.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Unstable sine PWM output

    Maybe it isn't DIV32... I don't know, but when I remove it, the glitches disapppears. I've also already tried to change the dummy values.

    My min. frequency is 1Hz (freq=10), reload value=about 0
    and my max. frequency is 120Hz (freq=1200), reload value=about 64600

    And I don't directly use the 0-1023 potentiometer value, first I convert it to the "freq" variable :

    Code:
    potsense=(potsense<<6)**maxfreq
    "maxfreq" correspond to the maximum frequency defined by the user. Here, "maxfreq"=1200. So here "freq" variable varies between 0 and 1200. Note I'm using an additional number to have the 0.1Hz accuracy (for exemple, 50.2Hz frequency equals freq=502).

    I have to said, your timer reload routine with DIV32 was pretty accurate and provides very good results. In terms of accuracy, I really had a 0.1Hz precision, both in low and high frequencies.
    Last edited by pxidr84; - 14th May 2011 at 10:52.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Unstable sine PWM output

    Hi,
    OK, so when Freq is 10 you want Reload to be 0 and when Freq is 1200 you want Reload to be 64600. That's 64600 over 1190 or a reload value of 54.286 per unit Freq.
    Code:
    Reload = (Freq */13897) - 542
    When Freq is 10 you'll get (10*13897/256)-542 = 0
    When Freq is 1200 you'll get (1200*13897/256)-542 = 64600
    Do not allow Freq to be less than 10, you'll end up with a negative value.

    This is not perfect but it might work, at least you'll get rid of DIV32. If you use the exact reload values for Freq=10 and Freq=1200 instead of the aproximate ones it might get a bit better in between the two extreme ends.

    By the way, the lowest possible interrupt frequency, when running at 40Mhz and without changing the prescaler is 152.588Hz which equals an output frequency of 1.69Hz so Freq should really only be allowed to range from 17 to 1200 for 1.7 to 120Hz.

    /Henrik.

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: Unstable sine PWM output

    Unfortunately, it doesn't work as expected but there is no glitch when I played with the potentiometer.

    For example, at 100.0Hz I obtain an 9.5Hz output,
    at 110.0Hz -> 17.6 Hz
    at 90.0Hz -> 6.5Hz...

    And there is no way to use this? http://www.picbasic.co.uk/forum/showthread.php?t=12433

    or this?
    http://melabs.com/resources/fp.htm

    (just a suggestion)

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