ERROR 21...SUBS and FUNCTIONS cannot be nested...(in PROPBASIC)
denno
Posts: 223
It does not seem to matter what I do, in the "arrangement of SUB, GOSUB, no SUB at all, I cannot get more then one SUB in a COG. Meaning, I can call a single SUB with the same name, any number of times in a single COG, but if i put another SUB in that same COG, with a different name, I always get the above error message. Yes, I am listing the SUB right after the VARIABLE list like so "getADCdata SUB", but before the DO/LOOP. That SUB does get used 3 times in the DO/LOOP, with three RETURN(s).
Is the problem due to a different SUB, with a different name, being called inside the same above DO/LOOP as the above SUB? "getADCdata SUB"
DennO
Is the problem due to a different SUB, with a different name, being called inside the same above DO/LOOP as the above SUB? "getADCdata SUB"
DennO
Comments
Please post your code. If you can minimize it as much as you can.
P.S. I am confused when you talk about putting SUBs in COGs ?
Do you mean putting SUBs in TASKs ? A "TASK" is not a COG...
A COG is a processor capable of running a TASK.
The main code is a TASK (implied), that is run in COG0 at startup.
A COG can run different TASKs at different times.
Bean
TASK voltMeasure is where I have the only SUB routine running...to get data from the MCP3204...by using 3 different single ended channels for 2 different voltages, and 1 temperature measurement using an LM34.
DennO
The only thing I see wrong is you do NOT put the task name after ENDTASK. But I don't think that causes an error, but it might confuse the compiler.
Bean
Ah, good catch. I didn't see that...
Bean
If you have more than one SUB without the ENDSUB, I suspect the compiler interprets that as defining a subroutine within a subroutine.
Bob
Bean, the code in the above thread does compile and run with no errors. The problem I was having was using another SUB routine in the same task and then getting ERROR 21. I will try as jones suggested. Also, Bean, I believe I do have the task name after each (7 of them) ENDTASK(s). I double checked....anyways...thanks again...DennO
Addendum: jones...I just installed a practice SUB in the same TASK as the first SUB and declared it, and the program compiled. So, that was my problem...I was using RETURN, as in PBASIC with the Stamp...thanks again to all....
So ENDSUB tells the compiler that is the end of the SUBROUTINE.
For example you might do:
Bean
Wasn't GOSUB obsoleted ? I seem to remember this was stated in the doc's.
On another note, does anyone know why my Windows 7, will not stop downloading the same ZIP file. It goes crazy, and i have to back out of Chrome, or reboot by holding the off button down for 5 seconds. Then I have to open my download files, and delete 20 of the same ZIP file. It will not stop after one... Just thought I would ask, as some of the PROPBASIC examples are in ZIP format...
DennO...also the dog's name is Lincoln...
I'd have to check the source code to be sure...
Bean
It's Microsoft Windows. Who knows why it does anything? I switched to Linux Mint a while ago and have not regretted it in spite of having to hunt for Linux versions of several apps. IMPNSHO it's past time to abandon Windows and switch to open source software.
Bean, is there anyway to preform integer math with PROPBASIC, with more then one operator on one line...please see attached code to obtain tens, units, tenths, and hundreds of a volt...
Thanks..DennO
So just do this:
Bean
I will rewrite my code and remember your instructions..and I did, so, 4 lines of code (your help) replaced 7 lines, to do the same thing. Very good....what can I say....other then I am looking for 1.49...LOL
DennO
Now, I am using an LM34 temperature sensor, operating on 5 volts supply. I am using the following code to get the temperature reading on the LCD to whole degrees and tenth of a degree. Which does work. Later on, I send it to the LCD using DATA statments.
However in trying to get "your"version to work, I cannot seem to duplicate it. I have tried several different ways, with no luck. You converted the 819 ADC units to 100 ADC units per volt. Which gave me the */8003 to use with the MCPvalue. In trying to do the same with 5 volts, I am not having much success. (Need a call to the expert)...the resolution of the MCP3204 is 12 bit for 5 volts. This give us the 891/volt. Would appreciate your thoughts....
The LM34 outputs 10mvolt/degreeF...I did try to convert to 5 volts by dividing 5 by 819, which gives me a value of .0061. That value * 65536 gives 388 to use with the */MCPvalue. Still no joy...what am I missing? Hope I am making sense to you or the other readers...
Again thanks....DennO
Temperature calculation with a 12 bit adc and 5V reference would be ADCreading x 500 / 4095.
I owe this trick to Bean...
DennO
DennO