DIV32 only has a problem with ON INTERRUPT.
ASM interrupts and DT_INTS has no problem with it.
DIV32 only has a problem with ON INTERRUPT.
ASM interrupts and DT_INTS has no problem with it.
DT
Hello,
I was trying to experiment with HankMcSpank's comparator interupt code. But am having problems getting it to compile.
I am using,
PIC18f4480
PBP 2.60A
DT_INT-18 3.3
ReEnter-18 v?
MPASM 5.2
It is giving me "missing argument", Interupt(FlagReg,Flagbit) not found etc
Error ("Int_handler"..... Error (Int_Enable
If anyone has any ideas, I would be greatfull.
Thanks
The 18F4480 only has 1 interrupt flag for both comparators.
You would use CMP_INT, then check the C1OUT/C2OUT bits in CMCON to determine which one triggered the interrupt.
DT
Be warned...it's still very much a work in progress, I've just revisited this one & noticed a whopping proble. On the basis that a picture is worth a thousand words, I just posted up a youtube video, which illustrates my last remaining problem - there appears to be bit of an ssue measuring smaller phase shifts...
Have a look at my video on this thread...
http://www.picbasic.co.uk/forum/show...4382#post94382
Last edited by HankMcSpank; - 25th September 2010 at 14:28.
Hank,
I got my code working last night , thanks to Darrel. The pic chips I am using only have one comparator interupt. By reading the output bits on each comparator and putting an IF statement in the ISR, I can read the frequency and phase like your code. My test so far is with a fixed 180 deg. I need to wire up a variable phase shifter, so that I can compare my results with yours. Not sure why you can't read below 33 deg? Maybe phase locking between the two comparators or interupt house keeping? What happens if you halve the frequency?
It all works well above a certain phase shift (depending on the signal frequency)...just when you get to the lower regions that this quirk kicks in.
I'm sure you're sorted for a phase shift cct, there's a simple one here....
http://www.werewoolf.org.je/graphics/apf1.gif
....make R1 & R2 the same value -I used 10k - the cap about 100nf & R4 a 10k pot (wired with the wiper to the ground end)....this gives about 90 degrees of phase shift @ 159Hz...if you want more phase shift,cascade a few together & use this designer http://www.aleph.co.jp/~takeda/radio/psDesigner.swf
just be sure that the signals into your PIC comparator are identical (I square them up first - remember ...different edge 'slopes' equals different triggering points for the PIC comparators which translates into a phase measurement error - and I also check on a scope to make sure there aren't any edge timing errors intrduced prior to the PIC)
If I half the incoming frequency (or double it), the Comp2 count remains the same (ie it won't go below 336, as I phase shift to the lower regions)...so I'm inclined to think it's housekeeping 'can't avoid' timing issue of some sort.
there maybe one fly in my particular ointment - my PIC supply is 4V...the datasheet says that 4.5V is the minimum when using a 20Mhz External clock. (& annoyingly, I don't appear have any 5V regulators handy so now looking at dropping the clock back to 8Mhz)
I look forward to your results so get a move on!
Last edited by HankMcSpank; - 25th September 2010 at 19:05.
Thats strange that halving the frequency does not change the minimum phase reading. The interupt process of saving and restorring variables should take the same amount of time weather your input frequency is 1hz or 1khz. So halving your frequency, should double your count on tmr1 while the interupt processing time remains constant. As a ratio, the lower the input frequency, the less effect processing delays have on your final value.
Example
Input 500Hz = 2ms or 5.5us/deg with a 33 degree lag = 183us
Then at 250Hz = 4ms or 11.1us/deg with a 33 degree lag = 366us
So for argument sake, lets say it takes minimum of 183us to process the interupt (not likely). If
we plug this into the 250hz case, we get 183us/11.1us or a minimum of 16.4 degrees.
I think there is something else going on, 183us is a long time. The power supply is pretty important and could cause havic in the analog circuits (Vref) if not regulated. If you're feelin lucky you can get 5v regulated off your USB port.
Bookmarks