Hi JT,Don’t forget to post the fonts, too.
Just to clarify, the $REMOTE comes from the PC via radio link, correct?
Been thinking about this. For the stuff that does not use the radio why not? It will reduce the latency waiting for the next sentence.Hi,
I've been playing with the GPS module and tried uprating the $Sentences output, and got it to output 10x Sentences/sec. Now it's approx $sentence = 57ms and the gap =28ms. Perhaps the other two INPUTs could be speded up the same?
C.
Hi JT,Been thinking about this. For the stuff that does not use the radio why not? It will reduce the latency waiting for the next sentence.
I also looked at the re-integration you posted in #720. There are some problems as a result of the general lack of structure and changing paradigms over time. Rather than laboriously describing each detail I just made a pass through the code myself and rearranged, cleaned up and re-wrote to make it more like I would do it to show by example. The high points are:
I could have combed through it a few more times but that's sufficient for the example. If you are OK with it, you should find it's easier to understand the flow and work with additions. If you are uncomfortable with it you can ignore my example and proceed.
- Configuration, IO, memory declarations are collected together, each in its own block at the top of the code. I personally do the same and put each in their own include file, one for config, IO, memory etc. That way I know where everything is and can keep a copy open in Notepad for easy reference. Mixing declarations and code makes things very hard to read. The comment/uncomment lines for the target (LIVE or SIM) is collected at the very top so you don't miss something when selecting.
- Indented code makes it stand out.
- You should try to use the native data types as the only working representation of data. For example, maintaining a value as a number AND a string is overly complex and wasteful of resources. A better way is to read whatever goofy data types are used by the various peripherals, GPS text, BMP280 multi byte registers, ADC values etc. and NORMALIZE them to an internal data type (byte, word, signed, unsigned etc) that you can calculate and control with. Convert to strings ONLY when sending human readable text to the display or terminal and ONLY in the reporting routine itself. It's probable that you'll have to read and act on the data way more often than you type it out so why burn the CPU cycles for each update when you only type it out occasionally.
- With this in mind, I separated the init, calculation and reporting functions for the various functional blocks. The code for each block is grouped together. I'd put the code for each block in its own include file.
- Use OSH's capability to use #variable to embed string equivalent of numerical data. Example: The ADC channel report was obviously and old construct. You used 5 separate strings to hold the text for the channel values when you could have used #ch1 etc in the Hserout statement. PLUS, you calculated those strings and reported each time you read the ADC. That is expensive. I changed that one to use the #var construct and freed up 100bytes of RAM.
- There were different ways of telling whether it was time to report the code. The parse routine sets flags which are detected and cleared when that function is finished. Earlier code looked at the length of strings to see when things changed. Like all string operations in OSH, that is expensive and clumsy. But pick ONE way to handle that and be consistent.
- Instead of embedding long code sequences in the normal code flow, use subroutines to move that code and just call them for the function. I did that in your compass, radio, altimeter stuff. That way, you can see what happens and when just by looking at where you do the call. That showed an issue in main_loop where the ADC, barometer et al don't run when its waiting for a $sentence. That's probably not good.
Finally, I don't mean to be overly pedantic but even at this point, this is a complicated program and the problems with integrating this main code with the comms stuff we did effectively demonstrate, IMHO, the benefit and necessity of getting some structure and consistency in the coding. I think some effort in that area would be well repaid in future development.
Have fun!
I was proposing that all of the routines for a particular system function or peripheral be put in a separate INCLUDE file. I'd have several, one for the ADC/joystick stuff, another for the barometer etc. Open a new editor window and cut/paste the section to it and save it as a new file e.g. inclADC.bas, inclBARO.bas etc. That keeps your main code file smaller and more manageable. On a program like this, that's important. As I mentioned, I'd put the IO, config, and variable declarations in their own INCLUDE files too. A big benefit of this approach is that you can have multiple versions of the include files to support different versions of hardware, PCB revisions, target processors, LIVE or SIM etc. Put the INCLUDE directive for these at the top of the main program where it's easy to see and use. One downside is that you have to post multiple files if someone else is to compile and test your code. That can be done by a .zip or just drag and drop them.Regarding INCLUDES, are yours a different type to the FONT one? or are they intended for the same treatment later?
If you can dig through and understand how I structured the integrated code that would go a long way. You'll probably find that it could be better in places. The goal and reason for structure is to separate things into small, unique functions that have a specific purpose - little black box helpers if you will. You write and debug those ONCE then they are available when you need them. Your 'main' program then just consists of calling those in some useful manner. That also allows 'main' to be compact and by reading it, offer a concise description of the code flow. The details are deferred to the called routines.I don't really understand, structure of a program, as I've made it up as I've gone along, making it so I can read it, and I'm happy for any improvement changes, as it would be impossible for me to do. Looking through your program, it looks good, and I should get used to it pretty soon. If there are many changes, it's best for it to be done sooner than later. I'm happy to try making changes, and I don't expect anyone else to do it, but it takes me a long time to make changes, in case I spoil things.
Hi JT,I was proposing that all of the routines for a particular system function or peripheral be put in a separate INCLUDE file. I'd have several, one for the ADC/joystick stuff, another for the barometer etc. Open a new editor window and cut/paste the section to it and save it as a new file e.g. inclADC.bas, inclBARO.bas etc. That keeps your main code file smaller and more manageable. On a program like this, that's important. As I mentioned, I'd put the IO, config, and variable declarations in their own INCLUDE files too. A big benefit of this approach is that you can have multiple versions of the include files to support different versions of hardware, PCB revisions, target processors, LIVE or SIM etc. Put the INCLUDE directive for these at the top of the main program where it's easy to see and use. One downside is that you have to post multiple files if someone else is to compile and test your code. That can be done by a .zip or just drag and drop them.
If you can dig through and understand how I structured the integrated code that would go a long way. You'll probably find that it could be better in places. The goal and reason for structure is to separate things into small, unique functions that have a specific purpose - little black box helpers if you will. You write and debug those ONCE then they are available when you need them. Your 'main' program then just consists of calling those in some useful manner. That also allows 'main' to be compact and by reading it, offer a concise description of the code flow. The details are deferred to the called routines.
Yes to the first part. INCLUDE just inserts a copy of the BASIC source in the included file when compiling. It's exactly as if the source text itself were in the main file, you just don't have to look at it all the time.So to clarify, the INCLUDES will look the same as the FONT one, is that correct?
If so then once all of the INCLUDES and the FULL program have been posted, they will stay as they are, unless upated, and can be pointed to using the #XXX that you've introduced me to.
Basic source code from an external file can be included to the current program by using INCLUDE directive. Its only argument is a string containing the path to the external .BAS file. This can be the full path or only the file name, if the external file is located in the same folder as the current basic program file. During the compilation process the external basic source will be appended to the current program. Multiple files can be included with separate INCLUDE directives. To maintain the overall basic code structure, it is strongly suggested that the external file contains global declarations, subroutines, procedures and functions, only.
That's fine for now. I was just giving you something to think about.If we can leave them in the program for a while for my scanning, and during these 'what I would call' major updates, it would be a help.
What I ususally do is print it all out, and colour it in with LOOPs and GOSUBS, so I'll do that when you tell me, it's about right, if that's ok.
H JT,Yes to the first part. INCLUDE just inserts a copy of the BASIC source in the included file when compiling. It's exactly as if the source text itself were in the main file, you just don't have to look at it all the time.
#XXX ???
From the OSH manual:
That's fine for now. I was just giving you something to think about.
I also like working from a printed source with flow arrows and markups as necessary so have at it. When you get tired of printing the entire program just to look at a few routines, remember that INCLUDE idea.
Carry on!
For AAC classic (blue) format on a PC/Firefox:(I've forgotten the other method of adding links)
Hi JT,For AAC classic (blue) format on a PC/Firefox:
You can also just copy the link as described and paste it directly into the new post:
- Right click on the post number in the upper right corner of the target post
- Select 'Copy Link Location'
- Left click and drag over the text in the current post that you want to associate with the link to highlight it
- Click the Insert Link button on the toolbar or type CTRL+K
- Paste the link (CTRL+V) to the URL field in the dialog.
https://forum.allaboutcircuits.com/...location-pic-in-oshonsoft.148795/post-1533954
Good work so far. Hopefully your editing will be a bit simpler with more modular code.
#724Thanks for the link info, but what I meant was your way of adding a #XXX link, so it goes red, like the #720 you added.
Hi JT,So what you are calling the REMOTE is U4 18F4620 on the schematic. The ISCP connector calls it MASTER. Which is it?
It processes:
SPI:
Compass,
Air-data (altimeter et al),
Display
UART messages:
$GNRMC from GPS,
$BORI messages from the HC-12 radio (formerly $REMOTE),
NOTHING from PIC18F4431 (U5) ($QEIDEG is commented out)
It also does NOT process any ADC analog in (commented out). Doesn't this one have the joysticks?
No PWMs (there's no PWM code at all)
Is that correct? If so, I would delete all of the commented out stuff that doesn't belong to the PIC18F4620 and proceed from there.
I note that while you are only using UART channels 0 and 1, next_channel still increments through 0-1-2. That will cause problems. If you are going to eventually process UART messages from the other PIC (U5) I would leave them in as a placeholder but at any rate, next_channel needs to cycle only through valid channels.