News :
I've made some experiments, it's not an oscilloscope trigger problem.
I think it comes from my code. But where?
News :
I've made some experiments, it's not an oscilloscope trigger problem.
I think it comes from my code. But where?
Hi, Pxidr84
Something caught my attention ... in the reloading, you use DIV32; are you sure there's no possible interrupt while DIV32 works ???
as timer0 is a low priority interrupt ... I'd check that two or three times.
... just an idea after a very quick browse ...
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Hi,
Timer0 interrupt is used for the calculation of the inverter paramaters (like the V/F ratio, the timer reload variable, etc.) It's a low priority interrupt because the Timer1 interrupt (used for the PWM generation) is very critical and must be
executed all of the time.
The DIV32 is used for calculate the timer reload value (the timer routine is from Henrik). However this routine is needed for output the desired sine frequency. This routine directly controls the Timer1 interrupt frequency. It is possible to avoid this DIV32 command (because it seems to take a LOT of ressources)?
Maybe it's better to use Timer0 as a high priority interrupt?
Maybe a PWM register is misconfigured?
I don't know![]()
Not sure of a solution yet, but from watching the posted video, I am guessing the problem is some kind of timing issue. I don't think you have things configured wrong as the output looks great most of the time. Rather I think there are some times when a counter gets reset of an interrupt gets interrupted. It glitches then goes right back to perfect wave.
If you watch it and don't alter the frequency, does the glitch happen at regular intervals, or is it random in nature?
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
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
Bookmarks