![]() |
Forum Index : Microcontroller and PC projects : error : argument list
Author | Message | ||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1993 |
I am getting the above error and can't work out why. I have a SUB and I get the error when the SUB is called. error:argument list Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
Hi Paul, I think you need some brackets around the PIN command & functions. Just looked in a few of mine & all have brackets around the vairables. Phil [Code]GetCL more lines of code here. Sub GetCL pin(RelayPin) = 0 'make sure RLY1 is off (for C1 only) FCount = Pin(OscPin) ' get frequency Freq1 = Fcount ' copy into Freq1 Pin(RelayPin)= 1 ' now turn on relay to add C2 Pause 1000 'pause to allow osc to settle FCount = Pin(OscPin) ' get frequency again Freq2 = Fcount 'copy into Freq2 Pin(RelayPin) = 0 'turn off relay again 'now find the values of C1 and L1, knowing C2, Freq1 & Freq2 F1 = Freq1 F2 = Freq2 F1sqrd = F1*F1 'then find their squares F2sqrd = F2*F2 F1sqlessF2sq = ((F1sqrd - F2sqrd) '& their difference C1val = C2val *(F2sqrd / F1sqlessF2sq) ' calculate the value of C1 L1val = 1.0/(FourPiSqrd * (F1sqrd) * C1val) ' calculate the value of L1 End Sub [/code] |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1993 |
OK, yes of course, I'm converting the code from an Arduino sketch and it is a nightmare (for me). Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1993 |
I put the brackets in as they should be, but still getting the error Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1993 |
Found another error with the brackets in the last few lines, but still the error persists. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1993 |
From reading the manual I think it has something to do with me using OPTION EXPLICIT which I haven't used before. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
robert.rozee Guru ![]() Joined: 31/12/2012 Location: New ZealandPosts: 2442 |
can you post the full basic code please? cheers, rob :-) |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1993 |
@ robert.rozee This is the code so far, it is nowhere near completed. I have started to do a bit of work on the GUI but it needs a lot more. If I change the 'GetCL' defined SUB to a normal SUB with...GOSUB/LABEL/RETURN... it runs through OK or at least to a point where it returns a Divide by Zero error because I have no hardware connected. '************************************************************************************** 'INDUCTANCE / CAPACITANCE METER.....Paul Cahill Jun 2017 'Ported from Arduino Sketch Silicon Chip June 2017 '************************************************************************************** ' The NUDGE calibration factor CF that calibrates against a known standard has been omitted. CF=1 Option autorun on Option explicit Option default float 'SetTick 300, Measure, 1 Const CLbarPin = 16 'digital IO pin 16 for C/L-bar sensing Const RelayPin = 22 'digital IO pin 22 for driving RLY1 Const DecrPin = 4 'digital IO pin 4 for sensing DECR pos of S3 Const OscPin = 18 'digital IO pin 18 for input of oscillator signal Const IncrPin = 21 'digital IO pin 21 for sensing INCR pos of S3 Const CalLkPin = 17 'digital IO pin 17 for sensing CAL link LK1 Dim C1val ' C1's calculated value after calibration (in F) Const FourPiSqrd = 39.4784 Const uHmult = 1.0e6 ' multiplier for converting H into uHRed Const mHmult = 1.0e3 ' multiplier for converting H into mH Const pFmult = 1.0e12 ' multiplier for converting F into pF Const nFmult = 1.0e9 ' multiplier for converting F into nF Const uFmult = 1.0e6 ' multiplier for converting F into uF Const C2val = 1.000e-9 ' nominal value of C2 (1nF = 1 x 10^-9F (change to actual value if known) Dim c Dim CXval ' calculated value for Cx (in F) Dim L1val ' calculated value for L1 after calibration (H) Dim LXval ' calculated value for Lx (in H) Dim F1 Dim F2 Dim F3 Dim F1sqrd ' calc value for Freq1 squared (as a float) Dim F2sqrd ' calc value for Freq2 squared (as a float) Dim F3sqrd ' calc value for Freq3 squared (as a float) Dim F1SqlessF2Sq Dim CF ' calibration factor, set by nudging via S3 Dim Fcount ' raw frequency count figure (from GetFrequency function) Dim Freq1 ' measured Freq1 in Hz (L1 & C1 only) Dim Freq2 ' measured Freq2 in Hz (L1 & (C1 + C2)) Dim Freq3 ' measured Freq3 in Hz (C1+Cx/L1 or C1/L1+Lx) Dim CXuF Dim CDisp$ CF = 1 ' calibration factor (not used) SetPin CLbarPin, DIN,pullup ' make pin 2 an input with pullup SetPin RelayPin, DOUT ' but make pin3 an output Pin(RelayPin) = 0 ' set relay "off" SetPin DecrPin, DIN,pullup ' make pin 4 an input with pullup SetPin OscPin, FIN ' make pin 15 a frequency input SetPin IncrPin, DIN,pullup ' make pin 6 an input with pullup SetPin CalLkPin, DIN,pullup ' and make pin 7 an input with pullup CLS RGB(yellow) Text (MM.HRes/2),(MM.VRes/2)-50, "Digital LC Meter", C, 1, 2, RGB(black),RGB(yellow) Pause 2000 'CALIBRATION If Pin(CLbarPin) = 1 Then Text (MM.HRes/2),MM.VRes/2,"S1 set for C: OK", C, 1, 2, RGB(black),RGB(yellow) Else Text (MM.HRes/2),MM.VRes/2, "Fit shorting bar",C, 1, 2, RGB(black),RGB(yellow) 'S1 in 'L' position, need for shortin bar Text (MM.HRes/2),(MM.VRes/2)+50, "Now Calibrating",C, 1, 2, RGB(black),RGB(yellow) EndIf Pause 1000 GetCL , sub To find value of C1 And L1 CLS RGB(yellow) Text MM.HRes/2,MM.VRes/2,"Calibration done",c, 1, 2, RGB(black),RGB(yellow) Text (MM.HRes/2),(MM.VRes/2)+50 ,"Ready to measure",c, 1, 2, RGB(black),RGB(yellow) Pause 3000 CLS RGB(yellow) RBox 55,80,220,80,5,c,RGB(White) Text MM.HRes/2,(MM.VRes/2)-10,"MEASURE",c,1,2,RGB(Black),RGB(white) 'Main Loop CLS RGB(yellow) FCount = Pin(OscPin) ' go get current osc frequency Freq3 = Fcount ' and copy into Freq3 F3 = Freq3 F3sqrd = F3*F3 ' so it can be squared If CLbarPin = 1 Then 'we're measuring a C CapValString 'SUB CapValString Text MM.VRes - 9,MM.HRes/2,Cdisp$, c, 1, 2, RGB(black) ' now display the cap value string Else IndValString ' SUB IndValString we're measuring L Text MM.VRes - 9,MM.HRes/2, Ldisp$, c, 1, 2, RGB(black) ' show inductance value or over range msg Text MM.VRes - 9,(MM.HRes/2)+50, "F3 =" + Str$(Freq3) + " Hz" EndIf 'end main loop Sub CapValString CXval = C1val * CF * ((F1sqrd/F3sqrd) - 1.0) ' value of test capacitor Print C1val;CF;F1sqrd;F3sqrd If CXval < 1.0e-9 Then ' if CXval < 1nF CXpF = CXval * pFmult ' get equiv value in pF Cdisp$ = " Cx = " +Str$(CXpF) + " pF" ' then assemble top line string ElseIf ' value must be 1nF or more CXval < 1.0e-6 Then ' but check if it's less than 1uF CXnF = CXval * nFmult ' if so, get equiv value in nF Cdisp$ = "Cx = " + Str$(CXnF) + " nF" ' then assemble top line string EndIf EndIf ' value must be 1uF or more CXuF = CXval * uFmult ' so get equiv value in uF Cdisp$ = "Cx = " + Str$(CXuF) + " uF" ' then assemble top line string End Sub Sub IndValString LXval = L1val * CF * ((F1sqrd/F3sqrd)-1.0) ' work it out If LXval < 1.0e-3 Then ' if LXval < 1mH LXuH = LXval * uHmult ' convert to uH Ldisp$ = " Lx = " + Str$(LXuH) + " uH" ' then assemble top line string ElseIf LXval > 1 Then ' value must be 1mH or moreLXval < 1.5e-1 then LXmH = LXval * mHmult ' convert to mH Ldisp$ = " Lx = " + Str$(LXmH) + " mH" ' then assemble top line string Else Ldisp$ = " Over Range!" EndIf EndIf End Sub Sub GetCL Pin(RelayPin) = 0 'make sure RLY1 is off (for C1 only) FCount = Pin(OscPin) ' get frequency Freq1 = Fcount ' copy into Freq1 Pin(RelayPin) = 1 ' now turn on relay to add C2 Pause 1000 'pause to allow osc to settle FCount = Pin(OscPin) ' get frequency again Freq2 = Fcount 'copy into Freq2 Pin(RelayPin) = 0 'turn off relay again 'now find the values of C1 and L1, knowing C2, Freq1 & Freq2 F1 = Freq1 F2 = Freq2 F1sqrd = F1*F1 'then find their squares F2sqrd = F2*F2 F1sqlessF2sq = (F1sqrd - F2sqrd) '& their difference C1val = C2val *(F2sqrd / F1sqlessF2sq) ' calculate the value of C1 L1val = 1.0/(FourPiSqrd * F1sqrd * C1val) ' calculate the value of L1 End Sub Paul. PS I hope it is OK to post this code, or do I need permission from SC to do what I am doing. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
You have an extra ENDIF on line 101 and line 116 line 64 you have a comma instead of quote mark. Jim VK7JH MMedit |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
Program with the above errors fixed. I had to change one of the pins to suit my hardware as pin 4 was used by my display and then it ran OK with a divide by zero error on line 134. This is expected when there is no oscillator running (or none attached as in my case). I would put a test for zero frequency just in case. Jim VK7JH MMedit |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1993 |
Thanks for that Jim the comma in the sub certainly stood out in MMEdit, I was doing most of my debugging in TeraTerm, and it is the old story when editing anything, it is often hard to see your own mistakes. Thanks again at least it is OK so far. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
Finding other peoples bugs is more fun than finding your own. I also use other's code to test MMEdit. In this case, I formatted your code and the two extra ENDIF's were obvious. This is not always the case. I then produced a variable report and line 64 threw up a lot of errors about variables only used once, so I knew where to look. Translating code from one language to another can be 'interesting' and sometimes harder than starting from scratch. Once you have it working, I would consider using the touch screen instead of old fashioned switches. VK7JH MMedit |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1993 |
@ Jim I also thought of using the touch instead of a switch but the inductor connects to a different pin on the micro so I would then need 3 input terminals on the meter. I really only want this to check SMD caps which for some unknown reason are usually never marked. If you can mark a resistor you can mark a cap. I had Uf on one of my multimeters but it died and as I have other multimeters decided to build this instead of buying a new meter. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
redrok![]() Senior Member ![]() Joined: 15/09/2014 Location: United StatesPosts: 209 |
Hi palcal; Would you mind posting a bit about how this works? Are you using an external oscillator or something else? redrok |
||||
panky![]() Guru ![]() Joined: 02/10/2012 Location: AustraliaPosts: 1114 |
@redrock It was in a June 17 Silicon Chip article - basically you have an LC oscilator running which provides a frequency out. By paralleling a capacitor or inductor to be tested across the built in capacitor, inductor, you change the frequency. Thus by comparing the two frequencies and knowing the built in capacitor and inductor, you can calculate what value the L or C under test is. In the article they used an Arduino to carry out the calculations but Paul has done all the hard work and converted these to MMBasic. I just added a GUI interface for fun and interest. @Paul I have taken the liberty of adapting your program to use GUI commands. As is, with a 300KHz square wave input into the Osc pin, it works on my 144 pin MZ board but I have not actually tested with the front end components. For your info. '**************************************************************** ' INDUCTANCE / CAPACITANCE METER.....Paul Cahill Jun 2017 ' Ported from Arduino Sketch Silicon Chip June 2017 ' Initial language conversion by Paul (palcal) ' GUI adaption by Doug Pankhurst (panky) ' Current version tested on 144 pin Micromite Extreme 252MHz ' running MMBasic Extreme 5.04.05 ' (not using any MMBasic Extreme explicit commands) ' - should be OK for 120MHz '470. ' Uses pin 81 as digital out to drive relay selecting L or C ' rather than DIN to read switch for L or C ' Uses pin 11 (Count1) as frequency input - tested ' without front end components - I just fed a 302KHz ' square wave in to test. '**************************************************************** ' The NUDGE calibration factor CF that calibrates against ' a known standard has not been implimented yet so CF=1 ' Declarations OPTION AUTORUN ON OPTION EXPLICIT OPTION DEFAULT FLOAT ' modified pin numbers for MZ144 CONST CLbarPin = 81 'digital IO pin 81 for C/L-bar sensing CONST RelayPin = 82 'digital IO pin 82 for driving RLY1 CONST DecrPin = 83 'digital IO pin 83 for sensing DECR pos of S3 CONST OscPin = 11 'digital IO pin 11 for input of oscillator signal CONST IncrPin = 84 'digital IO pin 84 for sensing INCR pos of S3 CONST CalLkPin = 87 'digital IO pin 87 for sensing CAL link LK1 ' constants for calculations CONST FourPiSqrd = 39.4784 CONST uHmult = 1.0e6 ' multiplier for converting H into uH CONST mHmult = 1.0e3 ' multiplier for converting H into mH CONST pFmult = 1.0e12 ' multiplier for converting F into pF CONST nFmult = 1.0e9 ' multiplier for converting F into nF CONST uFmult = 1.0e6 ' multiplier for converting F into uF CONST C2val = 1.000e-9 ' nominal value of C2 (1nF = 1 x 10^-9F ' (change to actual value if known) ' variables DIM C1val ' C1's calculated value after calibration (in F) DIM c DIM CXval ' calculated value for Cx (in F) DIM L1val ' calculated value for L1 after calibration (H) DIM LXval ' calculated value for Lx (in H) DIM F1 ' frequency 1 DIM F2 ' frequency 2 DIM F3 ' frequency 3 DIM F1sqrd ' calc value for Freq1 squared (as a float) DIM F2sqrd ' calc value for Freq2 squared (as a float) DIM F3sqrd ' calc value for Freq3 squared (as a float) DIM F1SqlessF2Sq DIM CF ' calibration factor, set by nudging via S3 DIM Fcount ' raw frequency count figure (from GetFrequency function) DIM Freq1 ' measured Freq1 in Hz (L1 & C1 only) DIM Freq2 ' measured Freq2 in Hz (L1 & (C1 + C2)) DIM Freq3 ' measured Freq3 in Hz (C1+Cx/L1 or C1/L1+Lx) DIM CXuF ' capacitor under test DIM CDisp$ dim LXuH ' inductor under test dim Ldisp$ dim Do_Measure_Flag ' start measurement cycle 'Program Entry Point ' Initialise any variables CF = 1 ' calibration factor (not implimented yet) CLS RGB(gray) ' Set up GUI Controls dim Title_DB% = 10 ' title area dim LCVal_DB% = 11 ' LC Display Box dim Freq_DB% = 12 ' Frequency Display Box dim CSel_RB% = 13 ' test capacitor radio button dim LSel_RB% = 14 ' test inductor radio button dim LC_Sel_Frame% = 15 ' group C or L select in frame Dim LC_Cal_RB% = 17 ' calibrate radio button dim Measure_B% = 18 ' initiate measure button dim LC_Help_RB% = 19 ' switch to Help Screen dim Msg1_DB% = 20 ' message 1 area dim Msg2_DB% = 21 ' message 2 area font 2,2 gui displaybox Title_DB%,40,20,400,40,rgb(black),rgb(yellow) font 2,1 gui displaybox LCVal_DB%,100,80,300,30,rgb(black),rgb(green) gui displaybox Freq_DB%,100,120,300,30,rgb(black),rgb(green) gui displaybox Msg1_DB%,100,160,300,30,rgb(black),rgb(green) gui displaybox Msg2_DB%,100,200,300,30,rgb(black),rgb(green) font 2,1 gui frame LC_Sel_Frame%,"Select C or L",450,30,180,100,rgb(blue) gui radio CSel_RB%,"Capacitor",480,60,15,rgb(blue) gui radio LSel_RB%,"Inductor",480,100,15,rgb(blue) ctrlval(CSel_RB%) = 1 ' capacitance selected to start gui button Measure_B%,"Measure",200,250,90,40,rgb(black),rgb(red) font 1,1 gui interrupt TouchDown,TouchUp ' Define and setup all I/O pins SETPIN CLbarPin, Dout ' make pin 81 an output pin(CLbarPin) = 1 ' default capacitor SETPIN RelayPin, DOUT ' but make pin 82 an output PIN(RelayPin) = 0 ' set relay "off" SETPIN DecrPin, DIN,PULLUP ' make pin 83 an input with pullup SETPIN OscPin, FIN ' make pin 11 a frequency input - Count1 SETPIN IncrPin, DIN,PULLUP ' make pin 84 an input with pullup SETPIN CalLkPin, DIN,PULLUP ' and make pin 87 an input with pullup ' Initialise display with startup splash screen ctrlval(Title_DB%) = "Digital LC Meter" ' Carry out Calibration LC_Calibrate ' subroutine to perform initial calibration ' - can also be called if re-cal needed Do_Measure_Flag = 0 ' initial state after cal ' Main program loop do ' main loop - until touch screen ' buttons initiate action ' - options will be ' select L or C. ' Touch "Measure" to initiate process ' if Do_Measure_Flag = 1 then GetCL ' set up for initial frequency calculation FCount = PIN(OscPin) ' go get current osc frequency Freq3 = Fcount ' and copy into Freq3 F3 = Freq3 F3sqrd = F3*F3 ' so it can be squared IF pin(CLbarPin) = 1 THEN 'we're measuring a capacitor CapValString 'SUB CapValString ctrlval(LCVal_DB%) = Cdisp$ ' now display the cap value string ELSE IndValString ' SUB IndValString we're measuring L ctrlval(LCVal_DB%) = Ldisp$ ' show inductance value or over range msg ENDIF ctrlval(Freq_DB%) = "F3 =" + STR$(Freq3) + " Hz" ' base frequency Do_Measure_Flag = 0 endif loop 'end main loop ' Interrupt Handler for Touch sub TouchDown select case touch(ref) case CSel_RB% if ctrlval(CSel_RB%) then pin(CLBarPin) = 1 endif case LSel_RB% if ctrlval(LSel_RB%) then pin(CLBarPin) = 0 endif case Measure_B% Do_Measure_Flag = 1 end select end sub sub TouchUp ' not implimented yet end sub ' Subroutines and Functions ' Calibrate subroutine sub LC_Calibrate IF PIN(CLbarPin) = 1 THEN ctrlval(Msg1_DB%) = "S1 set for C: OK" ELSE ctrlval(Msg1_DB%) = "S1 set for L: OK" ctrlval(Msg2_DB%) = "Fit shorting bar" ENDIF pause 3000 ctrlval(Msg1_DB%) = "Now Calibrating" PAUSE 3000 GetCL ' sub To find value of C1 And L1 ctrlval(Msg1_DB%) = "Calibration done" ctrlval(Msg2_DB%) = "Ready to Measure" end sub SUB CapValString local CXpF,CXnF,CXuF CXval = C1val * CF * ((F1sqrd/F3sqrd) - 1.0) ' value of test capacitor ' PRINT C1val;CF;F1sqrd;F3sqrd IF CXval < 1.0e-9 THEN ' if CXval < 1nF CXpF = CXval * pFmult ' get equiv value in pF Cdisp$ = " Cx = " +STR$(CXpF) + " pF" ' then assemble top line string ELSEIF CXval < 1.0e-6 THEN ' value must be 1nF or more ' but check if it's less than 1uF CXnF = CXval * nFmult ' if so, get equiv value in nF Cdisp$ = "Cx = " + STR$(CXnF) + " nF" ' then assemble top line string ENDIF ' value must be 1uF or more CXuF = CXval * uFmult ' so get equiv value in uF Cdisp$ = "Cx = " + STR$(CXuF) + " uF" ' then assemble top line string END SUB SUB IndValString local LXuH,LXmH if f3sqrd = 0 then print "Divide by zero error line 204" LXval = L1val else LXval = L1val * CF * ((F1sqrd/F3sqrd)-1.0) ' work it out endif IF LXval < 1.0e-3 THEN ' if LXval < 1mH LXuH = LXval * uHmult ' convert to uH Ldisp$ = " Lx = " + STR$(LXuH) + " uH" ' then assemble top line string ELSEIF LXval > 1 THEN ' value must be 1mH or moreLXval < 1.5e-1 then LXmH = LXval * mHmult ' convert to mH Ldisp$ = " Lx = " + STR$(LXmH) + " mH" ' then assemble top line string ELSE Ldisp$ = " Over Range!" ENDIF 'EndIf END SUB SUB GetCL PIN(RelayPin) = 0 ' make sure RLY1 is off (for C1 only) FCount = PIN(OscPin) ' get frequency Freq1 = Fcount ' copy into Freq1 PIN(RelayPin) = 1 ' now turn on relay to add C2 PAUSE 1000 ' pause to allow osc to settle FCount = PIN(OscPin) ' get frequency again Freq2 = Fcount ' copy into Freq2 PIN(RelayPin) = 0 ' turn off relay again 'now find the values of C1 and L1, knowing C2, Freq1 & Freq2 F1 = Freq1 F2 = Freq2 F1sqrd = F1*F1 'then find their squares F2sqrd = F2*F2 F1sqlessF2sq = (F1sqrd - F2sqrd) '& their difference If F1sqlessF2sq = 0 then print "Divide by zero error line 236" C1val = C2val else C1val = C2val *(F2sqrd / F1sqlessF2sq) ' calculate the value of C1 endif If (FourPiSqrd * F1sqrd * C1val) = 0 then print "Divide by zero error line 242" else L1val = 1.0/(FourPiSqrd * F1sqrd * C1val) ' calculate the value of L1 endif END SUB Cheers, Doug. ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |