I think Alain may have a point, I would try to skip the DIV32... let's say assign a fixed value there and let it run idle to see if the problem persist.
I think Alain may have a point, I would try to skip the DIV32... let's say assign a fixed value there and let it run idle to see if the problem persist.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Hi,
I don't know if DT-Ints have any impact on DIV32, I'd guess no but I don't know. The manual says that it's not recomended to have interrupts enbles if using ON INTERRUPT because the system variables that DIV32 relies on might get changed by the ISR. But DT-Ints saves the system variables so I don't think it should be an issue.
With that said I don't see the reason for calculating the interrupt frequency "all the time". If I read your code correctly your TMR0 interrupt executes at around 38Hz so it calculates the reload values 38 times per second. As long as the desired frequency isn't changed the reload value for TMR1 doesn't change so why keep calculating it?
Instead, do it in your Main-loop and even better calculatie it only when the desired frequency have changed.
Now, I think you think that you AREN'T calculating it "all the time" but look closely at your TMR0 interrupt service routine:That flag=%1 is NOT part of the IF-THEN statement so flag will get set every interrupt no matter if the frequency have changed or not and therfor the calculations of the reload values will get executed every interrupt.Code:' PWM calculation interrupt (Timer 0) calcint: ' Recalculations if flag=%1 THEN '<----Calculate only when Flag=1 ' Reload timer calculation dum=dum1*dum2 reload=Div32 freq reload=(65535-reload)+8 ' U/F calculation if freq<=500 then amp=(freq*131)+35 ELSE AMP=65535 ENDIF flag=%0 ENDIF ' Frequency reference control by potentiometer potsense=((potsense<<6)**maxfreq)+5 if potsense<>freq then freq=potsense:flag=%1 ' Frequency limits if freq<minfreq then freq=minfreq if freq>maxfreq then freq=maxfreq @ INT_RETURN
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 :
was removed and replaced with :dum=dum1*dum2
reload=DIV32 freq
reload=(65535-reload)+8
I've also applied Henrik tips, like this :reload=64594
And set the reload calculation routine into the main loop.Code:' Frequency reference control by potentiometer potsense=(potsense<<6)**maxfreq IF potsense<>freq THEN freq=potsense flag=%1 endif
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 :
How to replace the "DIV32" by an another thing? It is possible to use that : http://melabs.com/resources/fp.htm ? Or anything else?dum=dum1*dum2
reload=DIV32 freq
reload=(65535-reload)+8
Last edited by pxidr84; - 13th May 2011 at 17:28.
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 :
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.Code:reload=reload-1 if reload<40000 then reload=64600
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.
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.So the problem is clearly DIV32. Apparently this command disturbs DT Instant Interrupts.
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.
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 :
"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).Code:potsense=(potsense<<6)**maxfreq
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.
Bookmarks