I'm hoping someone can help me.
I'm using the PIC16F716. The ADC registers for this chip have some constraints. You can select 4 x ADC pins in, or 3 x ADC pins in & one digital out (RA2, which is what my project does). The ADCs are 8 bit.
The attached .gcb code compiles fine & runs through the entire start-up sequence absolutely fine. When it gets to the main loop with the ADC reads, it seems to hang. I don't know if this is my code (probably) or a problem with the chip definitions. I've tried to manually set-up the ADCs using #define ADC_REQUIRED MANUAL, but without success. I've provided plenty of comments to help understand the code.
I've shortened all of the Wait times, so if you debug or simulate it, you don't need to wait for ages :)
It is running here in the Real simulator. But, I do not know what the inputs / outputs are... so, see attached Real Simulator project. I increase the ADC some LEDS flash etc.
However, the code is not doing what you think it is doing. The many gotos has the logic blowing my mind. You need to refactor to use Logic statements and Subs. I have refactored using IF-THEN and I do not think this is doing what you want. This is my interpretation of what those GOTOs do - probably totally incorrect.
Memory report attached. This is the new HTML report in the latest build. Memory allocation looks to be correct. I used PICINFO, selected this chip, then opened the .DAT by selecting the GCBASIC IDE button, then I search for [ this quickly shows the memory locations FreeRAM and NoBankRAM.
I'm looking at your refactoring & will come back after I have thoroughly examined it. I have come from the world of programming using RTOS, so the Goto's was my methodology of how to implement this without using millis and interrupts.
One quick question. Normally, does the Real Pic Simulator input/output pin visualisations, show 8 bit ADCs as 10 bit ADCs?
All three 8 bit ADCs (AN0, AN1, AN3) show in the Real Pic Simulator (visualisation mode) as being 10 bit ADCs.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Add lots of serial debug and I would use the real hardware with a USB/TTL. You can probable keep all the gotos but refactoring is really the way to figure out what is going on.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Refactored even more as I have just added serial debug.
I have reused pulse_40ms as serial debug. This meant refactoring the code to remove the signle line If statements.
So, this code runs for ever showing 'loop'. You should add more serial,debug to figure out where the lock up is.
/*------------PORTA---------------Bit#: -7---6---5---4---3---2---1---0---IO:-x---x---x---I---I---O---I---I---Func:-x---x---x---OVR-IMP-PLS-EXP-NTC-Legend:AN0(PORTA.0)=HWS_NTC-HotWaterSystemNTCthermistor(AnalogIn)AN1(PORTA.1)=grid_export-Gridexportpowersensor(AnalogIn)PORTA.2=pulse_40ms-40mspulseoutput(DigitalOut)AN3(PORTA.3)=grid_import-Gridimportpowersensor(AnalogIn)PORTA.4=override_72hr-Legionella72hroverride(DigitalIn)PORTA.5-7=unused------------PORTB----------------Bit#: -7---6---5---4---3---2---1---0---IO:-O---O---O---O---O---O---O---I---Func:-MED-LOW-BST-HGH-MED-LOW-STB-THM-Legend:PORTB.0=thermostat-Thermostatinput(DigitalIn)PORTB.1=standby_led-StandbyLEDindicator(DigitalOut)PORTB.2=low_led-LowpowerLED(800W)(DigitalOut)PORTB.3=medium_led-MediumpowerLED(1600W)(DigitalOut)PORTB.4=high_led-HighpowerLED(2400W)(DigitalOut)PORTB.5=boost_led-Boost/LegionellaLED(DigitalOut)PORTB.6=low_element-Lowheatingelementrelay(800W)(DigitalOut)PORTB.7=medium_element-Mediumheatingelementrelay(1600W)(DigitalOut)Notes:-PIC16F716hasonlyPORTAandPORTB(noPORTC)-Highpower(2400W)=bothelementsonsimultaneously-Thermostat:open=1,closed=0-Overrideinput:PORTA.4isopendrainonly*/;-----Includelibrary#include <SoftSerial.h>;-----ConfigSerialUART:#define SER1_BAUD 9600 ; baudrate must be defined;ConfigI/Oportsfortransmitting:#define SER1_TXPORT PORTA ; I/O port (without .bit) must be defined#define SER1_TXPIN 2 ; portbit must be defined
Thank you Evan for all your hard work on the above.
I thought I'd start very simple this time.
I've attached a very small code snippet that I can't get to work in the Real Pic Simulator, along with a screenshot of the project loaded into the Real Pic Simulator. I'm hopeful you can tell me what's wrong with my code? It compiles fine (Build 1523 04/10/2025). I've detailed the expected outcome as comments in the code.
Basically, portB.5 should flash and portB.4 should come on if AD0 is >=128. Real Pic Sim (Visual Mode) manages the flashing portB.5 nicely, but no action at all on portB.4
Using the Oshonsoft simulator in "microcontroller view", portB5 comes on but does not flash as expected and AN0 is not seen as an analogue input, just a digital input. Therefore portB.4 remains off.
If there is anything in my short code snippet that can be changed/fixed to get one of the simulators to do what's expected, please let me know?
The new version of the compiler would have helped you.
See the attached HTML. Look at the Variable Memory Map. There is no byte_variable.
A quick scan od the .CDF shows byte_variable as a constant mapped to PORTA.0
So, I think the oversight is here #define byte_variable PORTA.0 this is a Bit. I think you need dim byte_variable as you are comparing to a byte value >= 128.
This works here with the change. A really easy oversight - done it many times.
The new HTML report is cool. It is the first place I went to see what was haopening. Then, the CDF confirmed it. Then, back to the source code....
The latest build is here at my house, and, at Angel's house in Mexico. :-)
We will release as soon a practical. I am using daily, all the test results are good. The new toolchain is very cool!
So, we will announce a Beta program very soon. The reason for a Beta is to understand and better document all the new Debugger and Programmer use cases. This is a huge update and we need to get this right.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm hoping someone can help me.
I'm using the PIC16F716. The ADC registers for this chip have some constraints. You can select 4 x ADC pins in, or 3 x ADC pins in & one digital out (RA2, which is what my project does). The ADCs are 8 bit.
The attached .gcb code compiles fine & runs through the entire start-up sequence absolutely fine. When it gets to the main loop with the ADC reads, it seems to hang. I don't know if this is my code (probably) or a problem with the chip definitions. I've tried to manually set-up the ADCs using #define ADC_REQUIRED MANUAL, but without success. I've provided plenty of comments to help understand the code.
I've shortened all of the Wait times, so if you debug or simulate it, you don't need to wait for ages :)
I'm using GCBASIC Build 1523 date 04/10/2025
Any help would be appreciated.
A code review.
What is this meant to do? Check the CDF for the results of this... This does not config the analog pins but this creates three constants.
It is running here in the Real simulator. But, I do not know what the inputs / outputs are... so, see attached Real Simulator project. I increase the ADC some LEDS flash etc.
However, the code is not doing what you think it is doing. The many gotos has the logic blowing my mind. You need to refactor to use Logic statements and Subs. I have refactored using IF-THEN and I do not think this is doing what you want. This is my interpretation of what those GOTOs do - probably totally incorrect.
Memory report attached. This is the new HTML report in the latest build. Memory allocation looks to be correct. I used PICINFO, selected this chip, then opened the .DAT by selecting the GCBASIC IDE button, then I search for
[this quickly shows the memory locations FreeRAM and NoBankRAM.Thank you heaps Evan.
I'm looking at your refactoring & will come back after I have thoroughly examined it. I have come from the world of programming using RTOS, so the Goto's was my methodology of how to implement this without using millis and interrupts.
One quick question. Normally, does the Real Pic Simulator input/output pin visualisations, show 8 bit ADCs as 10 bit ADCs?
All three 8 bit ADCs (AN0, AN1, AN3) show in the Real Pic Simulator (visualisation mode) as being 10 bit ADCs.
Goto's just cannot be debugged.
Real SIm shows the ADC correctly.
Load the RPP project provided.
Add lots of serial debug and I would use the real hardware with a USB/TTL. You can probable keep all the gotos but refactoring is really the way to figure out what is going on.
Refactored even more as I have just added serial debug.
I have reused pulse_40ms as serial debug. This meant refactoring the code to remove the signle line If statements.
So, this code runs for ever showing 'loop'. You should add more serial,debug to figure out where the lock up is.
Thank you Evan for all your hard work on the above.
I thought I'd start very simple this time.
I've attached a very small code snippet that I can't get to work in the Real Pic Simulator, along with a screenshot of the project loaded into the Real Pic Simulator. I'm hopeful you can tell me what's wrong with my code? It compiles fine (Build 1523 04/10/2025). I've detailed the expected outcome as comments in the code.
Basically, portB.5 should flash and portB.4 should come on if AD0 is >=128. Real Pic Sim (Visual Mode) manages the flashing portB.5 nicely, but no action at all on portB.4
Using the Oshonsoft simulator in "microcontroller view", portB5 comes on but does not flash as expected and AN0 is not seen as an analogue input, just a digital input. Therefore portB.4 remains off.
If there is anything in my short code snippet that can be changed/fixed to get one of the simulators to do what's expected, please let me know?
Many thanks.
Hmmm, seems only one file uploaded. Here is the .gcb file for the above.
The new version of the compiler would have helped you.
See the attached HTML. Look at the Variable Memory Map. There is no
byte_variable.A quick scan od the .CDF shows
byte_variableas a constant mapped to PORTA.0So, I think the oversight is here
#define byte_variable PORTA.0this is a Bit. I think you needdim byte_variableas you are comparing to a byte value>= 128.This works here with the change. A really easy oversight - done it many times.
Thanks heaps Evan. You are a lifesaver.
I've wondered where the new colour coded compiler is hiding. I only downloaded what I believed to be the latest version 5 days ago.
There are versions in github, sourceforge & I think at gcbasic.com.
Can you give me the link for the latest version?
Pleasure.
The new HTML report is cool. It is the first place I went to see what was haopening. Then, the CDF confirmed it. Then, back to the source code....
The latest build is here at my house, and, at Angel's house in Mexico. :-)
We will release as soon a practical. I am using daily, all the test results are good. The new toolchain is very cool!
So, we will announce a Beta program very soon. The reason for a Beta is to understand and better document all the new Debugger and Programmer use cases. This is a huge update and we need to get this right.