Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 15:17 06 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : New CFunction Crashing Super Clock

Author Message
Trakky
Newbie

Joined: 12/07/2014
Location: Australia
Posts: 9
Posted: 06:21pm 28 Mar 2017
Copy link to clipboard 
Print this post

To brush up my C programming ‘skills’ and to try to understand more of the requirements behind writing CFunctions I decided to write a CFunction to talk to two DS18B20s on a single 1-Wire circuit.

I realise that others have written functions for 1_Wire (eg. TEMPR(), ONEWIRE WRITE pin) but decided to have a go at it as I already have the DS18B20s installed in my caravan on a single circuit driven from a PIC18F2520 with the Inside/Outside temperatures, date and time displayed on a 20x2 LCD display. When Geoff came out with the Super Clock I thought that it was time to update as the LCD display which is not all that easy to read. I also have the time displayed on a four digit LCD display.

As I was going to use a RTC and not use the GPS function I started to remove code relating to GPS and added the code to drive the DDM4 LCD display. To check the timing for both the DDM4 and the 1-Wire interface I also added some MMBasic code to give me short loops to produce a trigger for the CRO and to call the CFunction (the DDM4 and Ds18B20s tested individually). As the timing for the DDM4 is simple I’ve only checked the timing and not connected it to the display itself, only have one and its in the caravan.

To cut the story short, all worked well until I uncommented the functions in the CFunction that read and converted the temperature before the temperature is passed back to Super Clock code. When I compiled the entire C code and added it after the CSub DrawTriangles CFunction in the Super Clock bas file and ran the clock it bombed out with a message stating that it could not find the function GetSec. If calls to GetSec were commented out, GetYear was the next function not able to be found, followed by GetMonth etc. With all commented out all ran well in the loop with the correct temperatures being displayed on the Super Clock display.

Can anybody please point me in the right direction to overcome my problem, to me the temperature Cfunction is overwriting an array of pointers to the MMBasic functions that could not be found, (I’m not sure how the interpreter knows where to branch to when a MMBasic function/sub is called). Another thought is that possibly the interpreter is being overwritten as I have had to reload everything, MMBasic, font library and the .bas file.

I’ve used the correct versions of MPLAB X IDE and the C Compiler with all options set up correctly. I’ve attached my MPLAB X folder which also has my altered Super Clock bas file in it, I've been using MMBasic V5.2.

Sorry for the long winded explanation about my problem but I will greatly appreciate it if anyone can help me as I’m not too sure where to look next to fix my problem.
Edited by Trakky 2017-03-30
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 06:59pm 28 Mar 2017
Copy link to clipboard 
Print this post

It might be that a Cfunction/function/sub is not terminated.
Check all your SUB/END SUB, IF/ENDIF etc blocks of code.

Microblocks. Build with logic.
 
Trakky
Newbie

Joined: 12/07/2014
Location: Australia
Posts: 9
Posted: 07:33pm 28 Mar 2017
Copy link to clipboard 
Print this post

Thanks MicroBlocks, will check it out.

Can you see the the zipped folder that I tried to add to my post?
 
Nathan
Regular Member

Joined: 10/01/2016
Location: Germany
Posts: 49
Posted: 08:07pm 28 Mar 2017
Copy link to clipboard 
Print this post

Hi Trakky,

first run the memory command on the pogram you have.

After that split your program into two parts:

1.) save some of your c-lib functions as libraries.
LIBRARY SAVE

2.) put the other part into the main program.

run memory again. In case you see a difference in defined
c-functions there is a good chance by balancing 1.), 2.)
to get your program running.

If memory shows the correct number of functions in both cases,
there will be an other problem.

If possible update to the actual MMBasic version. There are some enhancements
around c-functions storage.

good luck,

Nathan






 
Trakky
Newbie

Joined: 12/07/2014
Location: Australia
Posts: 9
Posted: 10:39pm 28 Mar 2017
Copy link to clipboard 
Print this post

Trying to upload my file again.

2017-03-29_083745_GetTemp.zip
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5914
Posted: 11:56am 29 Mar 2017
Copy link to clipboard 
Print this post

The IF statement on line 168 is missing an ENDIF
I think it should go before the SELECT CASE code

  Quote   ' THE MAIN PROGRAM LOOP
'*******************************************************************************************************
DO
WATCHDOG 5000 ' reset after 5 seconds of no activity
' once a second get the time
' this will exit immediately if the screen is touched so that the following code can process the touch
IF TimeSource < 2 THEN ' RTC = 1
DO WHILE OldTime$ = TIME$ AND TOUCH(x) = -1 : LOOP
OldTime$ =
TIME$

' check if we need to process a touch or simply update the time
SELECT CASE TOUCH(X)
CASE 0 TO 120
' previous clock
DO : LOOP UNTIL TOUCH(x) = -1 ' wait for the touch to be lifted
DO
ClockNbr = ClockNbr -
1
IF ClockNbr < 0 THEN ClockNbr = maxclocks
LOOP WHILE ClockType(ClockNbr) = 0
VAR SAVE ClockNbr
InitClock


  Quote   ' THE MAIN PROGRAM LOOP
'*******************************************************************************************************
DO
WATCHDOG 5000 ' reset after 5 seconds of no activity
' once a second get the time
' this will exit immediately if the screen is touched so that the following code can process the touch
IF TimeSource < 2 THEN ' RTC = 1
DO WHILE OldTime$ = TIME$ AND TOUCH(x) = -1 : LOOP
OldTime$ =
TIME$
ENDIF

' check if we need to process a touch or simply update the time
SELECT CASE TOUCH(X)


Jim
VK7JH
MMedit   MMBasic Help
 
Trakky
Newbie

Joined: 12/07/2014
Location: Australia
Posts: 9
Posted: 12:37am 30 Mar 2017
Copy link to clipboard 
Print this post

Thanks MicroBlocks, Nathan and TassyJim for taking time out to reply to my post.

I went through the motions again this afternoon, recompiled the CFunction, ran CFGen and added the result to the end of the bas file. It ran fine without any apparent problems and I did not have my original problem.

When I tried all the functions of the Super Clock, ie. setting time , date, configuring the Daylight Saving setup it again bombed out. I tracked these down to somehow I accidentally erased the declaration of the string array 'dstdow. The second problem arose when I created a new string array with shorter month titles ('mthabrv' and commented out the original 'mths'), I missed one occurrence of 'mths' where I did change it to 'mthsabrv'.

I was thinking about my problem after I created this post, in my CFunction I have functions calling a function calling a function, I wondered if I nested them too deeply and this caused the problem.

It is interesting that you spotted the missing 'EndIf', when I originally decided to remove the GPS option from the Super Clock I just commented out the appropriate lines, later deleting those lines. I went back to my original file with the commented out lines and sure enough I had commented out both 'EndIf's, (there was another 'If' statement). Of course when I deleted the commented lines, both'If" statements went to. Up to the point where I started having problems with my CFunction I did not have any problems running the Super Clock program so I had no reason to check the bas file.

As I intend to use a 5" LCD for the final product I will have to use the Micromite Plus 64 - can you envisage any problems porting the modified Super Clock program to the Micromite Plus 64?

Once again thanks for replying (especially reading all that I wrote) , you have helped me again.

Regards, Ken.





 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 03:41am 30 Mar 2017
Copy link to clipboard 
Print this post

Use OPTION EXPLICIT to make sure all variables are defined.
It is the best strategy for writing a larger program.

Microblocks. Build with logic.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024