Spin Help
Hello,
I modified Beau's inductive proximity1 code and used the new object for the Prop BOE. My program works great where I find the resonant frequency using the calibrate procedure. In the code below, i put in some debug code using the Propeller Serial Terminal plus object to see what ad values and frequencies were reported. When the values for ad reach 1023, I get several values and the frequency that is chosen is the last of the list. How do I get it to pick the first one that is 1023?
Thanks,
Cenlasoft
I modified Beau's inductive proximity1 code and used the new object for the Prop BOE. My program works great where I find the resonant frequency using the calibrate procedure. In the code below, i put in some debug code using the Propeller Serial Terminal plus object to see what ad values and frequencies were reported. When the values for ad reach 1023, I get several values and the frequency that is chosen is the last of the list. How do I get it to pick the first one that is 1023?
Thanks,
Cenlasoft
OBJ
system : "Propeller Board of Education" ' PropBOE configuration tools
pst : "Parallax Serial Terminal Plus" ' Terminal communication tools
adc : "PropBOE ADC" ' A/D Converter on PropBOE
time : "Timing" ' Timing convenience methods
CON
FPin = 7 'Frequency Synthesizer OUTPUT pin
New_Freq = 261_000
StartFrequency = 100_000 'Start Frequency to Sweep ... 0 kHz to 500 kHz
StopFrequency = 400_000 'Stop Frequency to Sweep ... .0 kHz to 500 kHz
SweepStep = 1_000 'Sweep increment used in auto calibration
VAR
long ad ' Stores A/D conversion Result
long Frequency,FMax,ADCMax
PUB Go ' Program starts here
system.Clock(80_000_000) ' Propeller system clock -> 80 MHz
Calibrate
repeat
Synth(FPin,FMax)
ad := adc.In(0) ' Get AD0 analog to digitla conversion
time.Pause(50) 'Delay 50ms
pst.Home
pst.Str(String("ADC Val = "))
pst.Dec(ad)
pst.Str(String(" , "))
pst.Dec(FMax)
pst.ClearEnd
PUB Calibrate
FMax~
ADCMax := 1023
repeat Frequency from StartFrequency to StopFrequency step SweepStep 'Sweep frequency range
Synth(FPin,Frequency)
ad := adc.In(0)
waitcnt(cnt+clkfreq>>10) 'Allow ADC to settle
if ad => ADCMax
ADCMax := ad
FMax := Frequency
pst.dec(ad)
pst.Str(String(", "))
pst.Dec(Frequency)
pst.NewLine
PUB Synth(Pin, Freq) | s, d, ctr, frq
{{
##########################################################################################
##########################################################################################
Section used to Synthesize a specific frequency on an I/O pin:
##########################################################################################
##########################################################################################
}}
Freq := Freq #> 0 <# 500_000 'limit frequency range
ctr := constant(%000100 << 26) '..set NCO mode
s := 1 'determine shift
frq := fraction(Freq, CLKFREQ, s) 'Compute FRQB value
ctr |= Pin 'set PINA to complete CTRB value
CTRB := ctr 'Set CTRB
FRQB := frq 'Set FRQB
DIRA[Pin]~~ 'make pin output
PRI fraction(a, b, shift) : f
if shift > 0 'if shift, pre-shift a or b left
a <<= shift 'to maintain significant bits while
if shift < 0 'insuring proper result
b <<= -shift
repeat 32 'perform long division of a/b
f <<= 1
if a => b
a -= b
f++
a <<= 1

Comments
You might get more replies if you attach an archive of your project with your post.
I personally don't have all the objects listed in your program and I didn't want to go hunt them down.
I'm not sure I understand your question.
Do you want the loop to stop as soon as the variable "ad" equals 1023?
You mentioned Beau's code. Is there more information about his code? Do you have a link?
Your right, but all I want is to stop the loop as soon as "ad" equals 1023. This will give me the first resonant frequency value. I have tried to change the "=>" to "==" and then use "Next" in the loop. I need to know where to put the "Next" statement to exit the loop as soon as it hits 1023.
Thanks
Cenlasoft
You'd use quit to break out of the loop.
You could also use return to stop the method you are presently in and return to the calling method.