Hello! I need urgent help.
I'm new here. I just began working on a temperature controlled system using Pic 16f877a and an lm 35 sensor.
I'm simulating the results of it in Proteus. I have been able to get the pic to display the startup text only.
I get stuck at writing the code to make the pic keep displaying the current temperature until it detects a change.
I'm also stuck at doing the right Adc conversions for the sensor.
I've gone through all the related threads here. I haven't obtained any help yet.
I'd really appreciate a quick response.
Thanks.
Judah.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I included the ds header file cos from what i saw in the gcbasic documentation, i thought it contained temperature settings and might work on the lm 35 sensor also.
Uhmm...also, this is the first part of the project. I intend to use switches(push buttons) later on to be able to set reference temperature and save it to maybe EEPROM (I guess).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Then, when you have resolve the three errors you get, and, you understand why the errors are happening, and, you have the correct type of variables... I want you to consinder using scale, see Scale in the Help rather than using your existing code temp=ReadAD10(AN4)*5000/1024
PS A good post regarding your project. The GCB enabled me to review your work, the ASM let me check you source code and the HEX is not required. :-)
Last edit: Anobium 2019-11-19
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Uhmm....I have gone through both links but I could not understand them. I think it might help me out to fix the code and I'll fiddle with it a lot after implementing to really understand what it actually does.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I added it to the code. The value displayed on the lcd began changing as the temperature was changing in accordance with the lm35 even though it was lower by one degree. Also, I havent been able to make the pic display the startup text only on startup while looping the rest of the code.
I have attached the gcb file and hex.
thanks a lot
Couple of observations in your code TEMP will always equal TEMP so I'm surprised that you are getting output to the screen.
Second the output of the LM35 gives out an absolute voltage (independent of the supply) so the reading from the ADC will depend on the voltage you are supplying to the circuit (and how stable it is). Using a voltage reference (Vref+) for the ADC may be a better way to go.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks a lot. I tried using "when temp=!temp at first to detect when the temperature changes to then obtain anothe reading but it didnt work out. Then I tried doing the reverse. Still didnt work.
Thanks a lot. I'm using a 5 volts supply for the sensor. But I have to ask, how do I do the referencing. I came across sth like that while searching but haven't understood it yet, same way I'm still yet to understand about ADC conversions.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As David said, but, here is working code.
* I renamed your variables. They are now meaningful.
* The if-endif is meaningful now
* The test is now valid. But, note - you have to initialise tempold with a value that cause the test to work first time.
* The print has a CLS screen. (remove it and discover what happens).
* Note sure what #include <ds18b20.h> is intended to do.
Enjoy
#chip 16f877a, 4#include <ds18b20.h>#option explicit#config osc=RC#config WDT = OFF#define sensor PORTA.5;lcdconnectionsettings#define LCD_Speed medium#define LCD_IO 4#define LCD_NO_RW#define LCD_RS PORTD.2#define LCD_Enable PORTD.3#define LCD_DB4 PORTD.4#define LCD_DB5 PORTD.5#define LCD_DB6 PORTD.6#define LCD_DB7 PORTD.7dirsensorindimtempnowasWorddimccountasWorddimtempoldasword;variablesusedccount=0print"System On."wait3sclsPrint"Obtaining temp."wait2slocate1,0print"Please wait..."wait2scls'init tempold so it not equalt tempnow, if can never read 65535tempold=0xffffmain:doforevertempnow=scale(ReadAD10(AN4),0,1023,0,499)iftempold<>tempnowthenclsprinttempnowprint"degree C"tempold=tempnowccount++endifwait10msloop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you.
The code worked exactly as said.
When I took out the cls, it simply kept writing each new temperature on the screen continously. It has become clear its use.
I'd appreciate if you could help me explain the line "tempold=0xffff" and the comment before it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Setting tempold to a very big number ensures the if -then test works on the first run through. If tempold was equal to zero and the returned value from the readadc was also 0 then the if-then would fail and your LCD would not get written to. The big number ensures the first read updates the LCD.
My comment.. oh I left it in.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I appreciate the help so far. I'm now proceeding to add a menu to set a reference temperature and save that temperature using push buttons for menu control.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello!
After looking for ways I could put in a menu to the system, I saw that using interrupts was the most viable way, if not the only way.
Here's what I have in mind for the project I'm on.
I intend for the lcd to continue diplaying the regular temperature until whenever the "ok" switch is pressed. It should then enter a menu where it shows the current reference temperature (as last saved in the EEPROM) and gives you space to either increase or decrease this temperature by pressing either the down or the up button (using subroutines). After adjusting this temperature to what you want, you could then save it (still with the ok button but under a new subroutine called "save"). It then returns to the normal display where it shows the regular temperature.
Firstly, I'm not sure if this thread should fall under interrupts but I figured since it was the same project, and for ease, I should drop it here.
Also, I've gone through some of the other threads on interrupts and I must say that they are really getting me confused as the documentation just has very few things to say about interrupts.
I've seen how people post images of their code here but since I'm not sure yet how to do that and my code refused to compile, I might just have to attach the gcb file and asm, if I find it.
Many thanks.
Where save, down and up are subroutines - these therefore are not values that will set the bits you are setting, and, you have the same defined as CONSTANTS that map to Ports.
I think to write out your overall approach may be of benefit.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello! I need urgent help.
I'm new here. I just began working on a temperature controlled system using Pic 16f877a and an lm 35 sensor.
I'm simulating the results of it in Proteus. I have been able to get the pic to display the startup text only.
I get stuck at writing the code to make the pic keep displaying the current temperature until it detects a change.
I'm also stuck at doing the right Adc conversions for the sensor.
I've gone through all the related threads here. I haven't obtained any help yet.
I'd really appreciate a quick response.
Thanks.
Judah.
Hello!
We need to see how far you have got.
Post your program as an attachment.
Alright, Ill do just that
I attached the gcbasic ide and code and the proteus simulation snapshots
I included the ds header file cos from what i saw in the gcbasic documentation, i thought it contained temperature settings and might work on the lm 35 sensor also.
Uhmm...also, this is the first part of the project. I intend to use switches(push buttons) later on to be able to set reference temperature and save it to maybe EEPROM (I guess).
These are pictures.... always good to attach the source GCB file.
Alright, let me try that
I attache the text file, assembly file, and hex file.
OK. Rather than have me fix the code - I am going to use the experiencial method. I hope this works for you.
Have a look at http://gcbasic.sourceforge.net/help/__option_explicit.html
Then, when you have resolve the three errors you get, and, you understand why the errors are happening, and, you have the correct type of variables... I want you to consinder using
scale, see Scale in the Help rather than using your existing codetemp=ReadAD10(AN4)*5000/1024PS A good post regarding your project. The GCB enabled me to review your work, the ASM let me check you source code and the HEX is not required. :-)
Last edit: Anobium 2019-11-19
Alright....thanks a lot.
Pls if I'm not able to understand or make good use of the references, I might have to return here for help.
Of course you can, and you should. Lots of folks here will help.
Uhmm....I have gone through both links but I could not understand them. I think it might help me out to fix the code and I'll fiddle with it a lot after implementing to really understand what it actually does.
OK.
You have not define the variables.
So, add
#option explicitthis will force you to define the variables.Your ReadAD10 returns a WORD, s, temp should be a WORD
but, I think this will work better as this will read 0-1023 range and set temp1 to 0 to 499
Okay let me do this....thanks
I added it to the code. The value displayed on the lcd began changing as the temperature was changing in accordance with the lm35 even though it was lower by one degree. Also, I havent been able to make the pic display the startup text only on startup while looping the rest of the code.
I have attached the gcb file and hex.
thanks a lot
Couple of observations in your code TEMP will always equal TEMP so I'm surprised that you are getting output to the screen.
Second the output of the LM35 gives out an absolute voltage (independent of the supply) so the reading from the ADC will depend on the voltage you are supplying to the circuit (and how stable it is). Using a voltage reference (Vref+) for the ADC may be a better way to go.
Thanks a lot. I tried using "when temp=!temp at first to detect when the temperature changes to then obtain anothe reading but it didnt work out. Then I tried doing the reverse. Still didnt work.
Thanks a lot. I'm using a 5 volts supply for the sensor. But I have to ask, how do I do the referencing. I came across sth like that while searching but haven't understood it yet, same way I'm still yet to understand about ADC conversions.
Many little errors.
As David said, but, here is working code.
* I renamed your variables. They are now meaningful.
* The if-endif is meaningful now
* The test is now valid. But, note - you have to initialise
tempoldwith a value that cause the test to work first time.* The print has a CLS screen. (remove it and discover what happens).
* Note sure what
#include <ds18b20.h>is intended to do.Enjoy
Thank you.
The code worked exactly as said.
When I took out the cls, it simply kept writing each new temperature on the screen continously. It has become clear its use.
I'd appreciate if you could help me explain the line "tempold=0xffff" and the comment before it.
I included the ds18b20 file cos I thought it would contain some needed stuff. It doesnt, for this project I see. I'd take it out.
Setting tempold to a very big number ensures the if -then test works on the first run through. If tempold was equal to zero and the returned value from the readadc was also 0 then the if-then would fail and your LCD would not get written to. The big number ensures the first read updates the LCD.
My comment.. oh I left it in.
I appreciate the help so far. I'm now proceeding to add a menu to set a reference temperature and save that temperature using push buttons for menu control.
Hello!
After looking for ways I could put in a menu to the system, I saw that using interrupts was the most viable way, if not the only way.
Here's what I have in mind for the project I'm on.
I intend for the lcd to continue diplaying the regular temperature until whenever the "ok" switch is pressed. It should then enter a menu where it shows the current reference temperature (as last saved in the EEPROM) and gives you space to either increase or decrease this temperature by pressing either the down or the up button (using subroutines). After adjusting this temperature to what you want, you could then save it (still with the ok button but under a new subroutine called "save"). It then returns to the normal display where it shows the regular temperature.
Firstly, I'm not sure if this thread should fall under interrupts but I figured since it was the same project, and for ease, I should drop it here.
Also, I've gone through some of the other threads on interrupts and I must say that they are really getting me confused as the documentation just has very few things to say about interrupts.
I've seen how people post images of their code here but since I'm not sure yet how to do that and my code refused to compile, I might just have to attach the gcb file and asm, if I find it.
Many thanks.
I thought to attach the circuit also
Had a scan - but, I am very confused.
Where
save,downandupare subroutines - these therefore are not values that will set the bits you are setting, and, you have the same defined as CONSTANTS that map to Ports.I think to write out your overall approach may be of benefit.