PDA

View Full Version : Compare value ...



cobuccit
- 7th April 2020, 17:45
Hi good morning everyone,
i have a little project on PIC16F88 whit LM35.
When temperature go over Tmax Portb.6 go High.


I don't understand how to compare values


On the lCD display i have 3 value
Temp from Lm35
Tmax from eprom
Tmin from eprom


but i don't undesrstand why portb.6 go always High also if the temperature Tmax is low


thank you

the code is




temp var word
temperature var word
samples var word
sample VAR BYTE
quanta con 1250
Tmax VAR byte
Tmin VAR byte


Read 0,DatoEE
Tmin=DatoEE


Read 1,DatoEE
Tmax=DatoEE


temp = 0 'Clear temp register
temperature = 0 'Clear temperature register
sample = 0 'Clear sample register
samples = 0 'Clear samples register


FOR sample = 1 TO 20 'Take 20 samples
ADCIN 0, temp 'Read AN0 into temp variable
samples = samples + temp
PAUSE 50 ' Wait 1/4 seconds per reading
NEXT sample
temp = samples/20 'Average over 20 samples (Every 5 seconds)
temperature= (temp*10) */ quanta


Pause 200 ' Timeout for LCD to settle
LCDOUT $FE, 1 ' cancella LCD
LCDOUT $FE, 2 ' ritorna al primo carattere
lcdout $FE, 2, "Temp ",dec2 (temperature/100),".", dec1 (temperature//100),$DF,"C"
lcdout $FE, $C0, "Tmin ",#Tmin DIG 1,#Tmin Dig 0," Tmax ",#Tmax DIG 1,#Tmax Dig 0






If temperature > Tmax then
PORTA.6=1
Endif

richard
- 8th April 2020, 02:29
DatoEE is never defined
i see that no data is stored to eeprom therefore tmax and tmin = 255

then --

If temperature > Tmax then
PORTA.6=1
Endif

why would porta.6 change if temperature < Tmax your code only sets the pin it never clears it
the initial state of pin should also be set , there is no code visible to set trisb either


If temperature > Tmax then
PORTA.6=1
else
PORTA.6=0
Endif



this makes me wonder what your actual fosc is , you posted no config section and there is no OSC definition


PAUSE 50 ' Wait 1/4 seconds per reading

cobuccit
- 8th April 2020, 11:24
Hi, Forgive me, your questions are legitimate, I tried to post a surrogate code so as not to stretch too much, but I think I have created confusion.

anyway :

DatoEE is never defined
i see that no data is stored to eeprom therefore tmax and tmin = 255


' EEPROM Locations
'================================================= ==========================
DATA @0,16 ' 16 Tenp min.
DATA @1,30 ' 30 Temp Max.
'================================================= ==========================

then temp is 20 to 24 °C (ambiental)
Tmax is set 30°C


the configuration is

' -------- bit a bit controllo 0=output 1=input

INTCON = 0 ' NO INTERRUPT
ADCON1 = %10001110 '
ADCON0 = %00000101 'Disable Converter Module
ANSEL = %00000001 'Disable Inputs Tranne AN0
OSCCON = %01100000 'Internal RC set to 4MHZ
CMCON = 7 '
'76543210
TRISA = %10111111 ' impostazioni INP/OUT
TRISB = %00000000 ' delle porte
'----------------------------------------------------

the string
PAUSE 50 ' Wait 1/4 seconds per reading

only reports an incorrect comment


so my problem is, i believe:
temperature is a word
Tmax is a byte

and I don't understand how compare the values

cobuccit
- 8th April 2020, 11:30
Hi, Forgive me, your questions are legitimate, I tried to post a surrogate code so as not to stretch too much, but I think I have created confusion.


anyway :


DatoEE is never defined
i see that no data is stored to eeprom therefore tmax and tmin = 255



' EEPROM Locations
'================================================= ==========================
DATA @0,16 ' 16 Tenp min.
DATA @1,30 ' 30 Temp Max.
'================================================= ==========================


then temp is 20 to 24 °C (ambiental)
Tmax is set 30°C




the configuration is


' -------- bit a bit controllo 0=output 1=input


INTCON = 0 ' NO INTERRUPT
ADCON1 = 001110 '
ADCON0 = 000101 'Disable Converter Module
ANSEL = 000001 'Disable Inputs Tranne AN0
OSCCON = 100000 'Internal RC set to 4MHZ
CMCON = 7 '
'76543210
TRISA = 111111 ' impostazioni INP/OUT
TRISB = 000000 ' delle porte
'----------------------------------------------------


the string
PAUSE 50 ' Wait 1/4 seconds per reading


only reports an incorrect comment




so my problem is, i believe:
temperature is a word
Tmax is a byte


and I don't understand how compare the values

cobuccit
- 8th April 2020, 11:31
Hi, Forgive me, your questions are legitimate, I tried to post a surrogate code so as not to stretch too much, but I think I have created confusion.


anyway :


DatoEE is never defined
i see that no data is stored to eeprom therefore tmax and tmin = 255



' EEPROM Locations
'================================================= ==========================
DATA @0,16 ' 16 Tenp min.
DATA @1,30 ' 30 Temp Max.
'================================================= ==========================


then temp is 20 to 24 °C (ambiental)
Tmax is set 30°C




the configuration is


' -------- bit a bit controllo 0=output 1=input


INTCON = 0 ' NO INTERRUPT
ADCON1 = %10001110 '
ADCON0 = %00000101 'Disable Converter Module
ANSEL = %00000001 'Disable Inputs Tranne AN0
OSCCON = %01100000 'Internal RC set to 4MHZ
CMCON = 7 '
'76543210
TRISA = %10111111 ' impostazioni INP/OUT
TRISB = %00000000 ' delle porte
'----------------------------------------------------


the string
PAUSE 50 ' Wait 1/4 seconds per reading


only reports an incorrect comment




so my problem is, i believe:
temperature is a word
Tmax is a byte


and I don't understand how compare the values

Ioannis
- 8th April 2020, 15:28
Try:

1.
ADCON0=%10000101
while !adcon0.2:wend

2.
Display your variables on LCD or a serial port to be sure what values they are

Ioannis

cobuccit
- 8th April 2020, 16:14
Try:

1.
ADCON0= 000101
while !adcon0.2:wend



with this the Pic16F88 not working








2.
Display your variables on LCD or a serial port to be sure what values they are


Display on LCD
24.5 °C
Tmin 16 Tmax 30

cdout $FE, 2, "Temp ",dec2 (temperature/100),".", dec1 (temperature//100),$DF,"C"
lcdout $FE, $C0, "Tmin ",#Tmin DIG 1,#Tmin Dig 0," Tmax ",#Tmax DIG 1,#Tmax Dig 0



My problem is, i think:
temperature is a word
Tmax is a byte

and I don't understand how compare the values

Ioannis
- 8th April 2020, 17:44
Don't you see? You display a decimal number but the number is in fact 245 and not 24.5!

So, maybe you can use word variables and multiply them by 10 so you can compare 245 to 160 and 300.

My first suggestion was to make sure that bit 0 of ADCON0 was set. It needs some time and if you go fast to start ADC, the module might not work as expected. I am sorry that I made the mistake of bit 0 to 2. Please include it as this:



ADCON0=%10000101
while !adcon0.0:wend


I would not set bit 2 at this stage but anyway.

Ioannis

cobuccit
- 8th April 2020, 18:19
ADCON0=000101
while !adcon0.0:wend





OK, Perfect ;) this work well now



Don't you see? You display a decimal number but the number is in fact 245 and not 24.5!

So, maybe you can use word variables and multiply them by 10 so you can compare 245 to 160 and 300.

Ioannis

I have modified code in this mode, but don't work yet

If temperature > (Tmax*10) then
PORTA.6=1
else
PORTA.6=0
Endif

PORTA.6 go high when power on after showing the values on the display

NOTE :
The variables are still "temperature WORD" and "Tmax BYTE". I tried to change Tmax from BYTE to WORD in the declaration area but it gives me an error when compile

Ioannis
- 8th April 2020, 18:52
You should make it word. 30*10=300 > than a byte can hold.
Also better make the multiplication outside the comparison.

Use the LCD as a monitor to check your values.

About compilation, I guess it is a syntax error thing.

Ioannis

cobuccit
- 8th April 2020, 19:14
You should make it word. 30*10=300 > than a byte can hold.
Also better make the multiplication outside the comparison.

Use the LCD as a monitor to check your values.

About compilation, I guess it is a syntax error thing.

Ioannis

hi,

I have define Tcomp VAR WORD
and now i have :




tcomp=tmax*100

lcdout $FE, 2, "Temp. ",dec2 (temperature/100),".", dec1 (temperature//100),$DF,"C "
lcdout $FE, $C0, "Tmax ",#Tmax DIG 1,#Tmax Dig 0," Tco ",dec2 (Tcomp/100),".", dec1 (Tcomp//100)


On display i see :

Temp. 23.5°C
Tmax 30 Tco 30.0

And PORTA.6 go at 1 the same

louislouis
- 8th April 2020, 19:37
Try this:


INTCON = 0 ' NO INTERRUPT
ADCON1 = %10001110 '
ADCON0 = %000101 'Disable Converter Module
ANSEL = %00000001 'Disable Inputs Tranne AN0
OSCCON = %01100000 'Internal RC set to 4MHZ
CMCON = 7
TRISA = %10001111 ' impostazioni INP/OUT
TRISB = %00000000 ' delle porte
'----------------------------------------------------

temp var word
temperature var word
samples var word

sample VAR BYTE
quanta con 1250
Tmax VAR byte
Tmin VAR byte

Tmin=16
Tmax=30



temp = 0 'Clear temp register
temperature = 0 'Clear temperature register
sample = 1 'Clear sample register
samples = 0 'Clear samples register

PORTA.6=0

do
samples=0
FOR sample = 1 TO 20 'Take 20 samples
ADCIN 0, temp 'Read AN0 into temp variable
samples = samples + temp
PAUSE 50 ' Wait 1/4 seconds per reading
NEXT sample
temp = samples/20 'Average over 20 samples (Every 5 seconds)
temperature= (temp*10) */ quanta


Pause 200 ' Timeout for LCD to settle
LCDOUT $FE, 1 ' cancella LCD
LCDOUT $FE, 2 ' ritorna al primo carattere
lcdout $FE, 2, "Temp ",dec2 (temperature/100),".", dec1 (temperature//100),$DF,"C"
lcdout $FE, $C0, "Tmin ",#Tmin DIG 1,#Tmin Dig 0," Tmax ",#Tmax DIG 1,#Tmax Dig 0


If temperature/1000 > Tmax then
PORTA.6=1
else
PORTA.6=0
Endif
loop

cobuccit
- 8th April 2020, 20:57
Try this:


INTCON = 0 ' NO INTERRUPT
ADCON1 = 001110 '
ADCON0 = 0101 'Disable Converter Module
ANSEL = 000001 'Disable Inputs Tranne AN0
OSCCON = 100000 'Internal RC set to 4MHZ
CMCON = 7
TRISA = 001111 ' impostazioni INP/OUT
TRISB = 000000 ' delle porte
'----------------------------------------------------

temp var word
temperature var word
samples var word

sample VAR BYTE
quanta con 1250
Tmax VAR byte
Tmin VAR byte

Tmin=16
Tmax=30



temp = 0 'Clear temp register
temperature = 0 'Clear temperature register
sample = 1 'Clear sample register
samples = 0 'Clear samples register

PORTA.6=0

do
samples=0
FOR sample = 1 TO 20 'Take 20 samples
ADCIN 0, temp 'Read AN0 into temp variable
samples = samples + temp
PAUSE 50 ' Wait 1/4 seconds per reading
NEXT sample
temp = samples/20 'Average over 20 samples (Every 5 seconds)
temperature= (temp*10) */ quanta


Pause 200 ' Timeout for LCD to settle
LCDOUT $FE, 1 ' cancella LCD
LCDOUT $FE, 2 ' ritorna al primo carattere
lcdout $FE, 2, "Temp ",dec2 (temperature/100),".", dec1 (temperature//100),$DF,"C"
lcdout $FE, $C0, "Tmin ",#Tmin DIG 1,#Tmin Dig 0," Tmax ",#Tmax DIG 1,#Tmax Dig 0


If temperature/1000 > Tmax then
PORTA.6=1
else
PORTA.6=0
Endif
loop



it's all very strange!
Testing the code with temperature / 1000 in the same way PORTA.6 goes ON
Not even dividing by 1000 is it possible to obtain the right comparison


Then I added the Do .. loop and everything went crazy.
The room temperature changed with each cycle and the DOOR. 6 went its own without ON and OFF criteria without considering the temperature.

louislouis
- 8th April 2020, 21:10
Pplease post the whole code.

cobuccit
- 8th April 2020, 21:17
Pplease post the whole code.




'************************************************* ***************
'* Name : 16F88_LM235.BAS *
'* Author : *
'* Notice : Copyright (c) 2020 *
'* : All Rights Reserved *
'* Date : 04/04/2020 *
'* Version : 1.0 *
'*
'************************************************* ***************
'PIC 16F88
' Hardware Assignments
' --------------------
' LCD circuitery
'01 - Vss (GND)
'02 - Vdd (+5V)
'08 RS - PORTB.2
'09 E - PORTB.3
'10 DB4 - PORTB.4
'11 DB5 - PORTB.5
'12 DB6 - PORTB.6
'13 DB7 - PORTB.7


DEFINE LCD_DREG PORTB 'Porta B DATA OUT
DEFINE LCD_DBIT 4 '0 --> Bit 0-3 : 4 --> Bit 4-7


DEFINE LCD_RSREG PORTB 'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2 'LCD register select bit - Pin RS B2


DEFINE LCD_EREG PORTB 'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3 'LCD enable bit - Pin EN B3


DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD


DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us


' EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...
'================================================= ==========================
DATA @0,16 ' 16 Tenp min.
DATA @1,30 ' 30 Temp Max.
'================================================= ==========================


'================================================= ==========================
'***** SETTAGGIO PORTE


' VAR PORTA.0 'LM235M Pin 17
IncButton VAR PORTA.1 'SW Pin 18
DecButton VAR PORTA.2 'SW Pin 1
SetButton VAR PORTA.3 'SW Pin 2
' VAR PORTA.4 ' Pin 3
' VAR PORTA.5 ' Pin 4
Rele VAR PORTA.6 ' Pin 15
' VAR PORTA.7 ' Pin 16
'-----------------------------------------------
' Var PORTB.0 ' Pin 6
' var PORTB.1 ' Pin 7
l_rs var PORTB.2 'LCD sig. RS Pin 8
l_en Var PORTB.3 'LCD sig. E Pin 9
l_d4 var PORTB.4 'LCD 4 Pin 10
l_d5 var PORTB.5 'LCD 5 Pin 11
l_d6 var PORTB.6 'LCD 6 Pin 12
l_d7 var PORTB.7 'LCD 7 Pin 13


'--------------------------------------------------------------


'---------Define ADCin Parameters
DEFINE ADC_BITS 10 'set number of bits in result
DEFINE ADC_CLOCK 3 'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 'Set sampling time in uS




' RAM Assignments and Variables
'================================================= ==========================
CounterA var byte ' General purpose Variable
CounterB var byte ' General purpose Variable
CounterC var byte ' General purpose Variable
temp var word
temperature var word
samples var word
Dummy var word
sample VAR BYTE
quanta con 1250
DatoEE var byte
Tmax VAR Byte
Tmin VAR Byte
Tcomp VAR word
Grade var Byte
TimeOut var word ' Variable for SetUp Menu Time-Out
'================================================= ==========================





START:
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* ~*~*~*~*~*~*~*~*~*~*~*~*~*~
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* ~*~*~*~*~*~*~*~*~*~*~*~*~*~


' -------- bit a bit controllo 0=output 1=input


INTCON = 0 ' NO INTERRUPT
ADCON1 = 001110 '
ADCON0= 000101 'Disable Converter Module
while !adcon0.0:wend ' Attende che il convertitore sia spento prima di fare il resto
ANSEL = 000001 'Disable Inputs Tranne AN0
OSCCON = 100000 'Internal RC set to 4MHZ
CMCON = 7 '
'76543210
TRISA = 111111 ' impostazioni INP/OUT
TRISB = 000000 ' delle porte
'----------------------------------------------------


' Per utilizare i pin RA6 ed RA7 come I/O bisogna impostare lo switch in fase
' di programmazione Oscillotar come "INTRC_IO"
PORTA.6=0





' Leggi Dati dalla EEPROM
'================================================= ==========================
Read 0,DatoEE
Tmin=DatoEE


Read 1,DatoEE
Tmax=DatoEE
'================================================= ==========================

Lcdout $FE, 1 'Clear screen


MAIN:


'Subroutine to measure temp
'----------------------------------------------------
TEMP_READ:
temp = 0 'Clear temp register
temperature = 0 'Clear temperature register
sample = 0 'Clear sample register
samples = 0 'Clear samples register


do
sample = 0
FOR sample = 1 TO 20 'Take 20 samples
ADCIN 0, temp 'Read AN0 into temp variable
samples = samples + temp
PAUSE 50 ' Wait 1/4 seconds per reading
NEXT sample
temp = samples/20 'Average over 20 samples (Every 5 seconds)
temperature= (temp*10) */ quanta


Pause 200 ' Timeout for LCD to settle
LCDOUT $FE, 1 ' cancella LCD
LCDOUT $FE, 2 ' ritorna al primo carattere
lcdout $FE, 2, "Temp. ",dec2 (temperature/100),".", dec1 (temperature//100),$DF,"C "
lcdout $FE, $C0, "Tmin ",#Tmin DIG 1,#Tmin Dig 0," Tmax ",#Tmax DIG 1,#Tmax Dig 0





If temperature> TMax then
PORTA.6=1
else
PORTA.6=0
Endif


'lcdout $FE, $C0, "Tmax ",#Tmax DIG 1,#Tmax Dig 0," Tco ",dec2 (Tcomp/100),".", dec1 (Tcomp//100)
loop


goto MAIN
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* ~*~*~*~*~*~*~*~*~*~*~*~*~*~
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* ~*~*~*~*~*~*~*~*~*~*~*~*~*~

louislouis
- 8th April 2020, 21:50
Try this:



'************************************************* ***************
'* Name : 16F88_LM235.BAS *
'* Author : *
'* Notice : Copyright (c) 2020 *
'* : All Rights Reserved *
'* Date : 04/04/2020 *
'* Version : 1.0 *
'*
'************************************************* ***************
'PIC 16F88
' Hardware Assignments
' --------------------
' LCD circuitery
'01 - Vss (GND)
'02 - Vdd (+5V)
'08 RS - PORTB.2
'09 E - PORTB.3
'10 DB4 - PORTB.4
'11 DB5 - PORTB.5
'12 DB6 - PORTB.6
'13 DB7 - PORTB.7

' -------- bit a bit controllo 0=output 1=input

INTCON = 0 ' NO INTERRUPT
ADCON1 = %10001110 '
ADCON0 = %000101 'Disable Converter Module
ANSEL = %00000001 'Disable Inputs Tranne AN0
OSCCON = %01100000 'Internal RC set to 4MHZ
CMCON = 7
TRISA = %10001111 ' impostazioni INP/OUT
TRISB = %00000000 ' delle porte
'----------------------------------------------------


DEFINE LCD_DREG PORTB 'Porta B DATA OUT
DEFINE LCD_DBIT 4 '0 --> Bit 0-3 : 4 --> Bit 4-7


DEFINE LCD_RSREG PORTB 'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2 'LCD register select bit - Pin RS B2


DEFINE LCD_EREG PORTB 'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3 'LCD enable bit - Pin EN B3


DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD


DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us


' EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...
'================================================= ==========================
'================================================= ==========================


'================================================= ==========================
'***** SETTAGGIO PORTE


' VAR PORTA.0 'LM235M Pin 17
IncButton VAR PORTA.1 'SW Pin 18
DecButton VAR PORTA.2 'SW Pin 1
SetButton VAR PORTA.3 'SW Pin 2
' VAR PORTA.4 ' Pin 3
' VAR PORTA.5 ' Pin 4
Rele VAR PORTA.6 ' Pin 15
' VAR PORTA.7 ' Pin 16
'-----------------------------------------------
' Var PORTB.0 ' Pin 6
' var PORTB.1 ' Pin 7
l_rs var PORTB.2 'LCD sig. RS Pin 8
l_en Var PORTB.3 'LCD sig. E Pin 9
l_d4 var PORTB.4 'LCD 4 Pin 10
l_d5 var PORTB.5 'LCD 5 Pin 11
l_d6 var PORTB.6 'LCD 6 Pin 12
l_d7 var PORTB.7 'LCD 7 Pin 13


'--------------------------------------------------------------


'---------Define ADCin Parameters
DEFINE ADC_BITS 10 'set number of bits in result
DEFINE ADC_CLOCK 3 'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 'Set sampling time in uS




' RAM Assignments and Variables
'================================================= ==========================
CounterA var byte ' General purpose Variable
CounterB var byte ' General purpose Variable
CounterC var byte ' General purpose Variable
Dummy var word
DatoEE var byte
Tcomp VAR word
Grade var Byte
TimeOut var word ' Variable for SetUp Menu Time-Out
temp var word
temperature var word
samples var word

sample VAR BYTE
quanta con 1250
Tmax VAR byte
Tmin VAR byte
'================================================= ==========================

Tmin=16
Tmax=30



START:
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* ~*~*~*~*~*~*~*~*~*~*~*~*~*~
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* ~*~*~*~*~*~*~*~*~*~*~*~*~


Lcdout $FE, 1 'Clear screen

temp = 0 'Clear temp register
temperature = 0 'Clear temperature register
sample = 1 'Clear sample register
samples = 0 'Clear samples register

rele=0

main:

samples=0
FOR sample = 1 TO 20 'Take 20 samples
ADCIN 0, temp 'Read AN0 into temp variable
samples = samples + temp
PAUSE 40 ' Wait 1/4 seconds per reading
NEXT sample
temp = samples/20 'Average over 20 samples (Every 5 seconds)
temperature= (temp*10) */ quanta


Pause 200 ' Timeout for LCD to settle
LCDOUT $FE, 1 ' cancella LCD
LCDOUT $FE, 2 ' ritorna al primo carattere
lcdout $FE, 2, "Temp ",dec2 (temperature/100),".", dec1 (temperature//100),$DF,"C"
lcdout $FE, $C0, "Tmin ",#Tmin DIG 1,#Tmin Dig 0," Tmax ",#Tmax DIG 1,#Tmax Dig 0

If temperature/1000 > Tmax then
rele=1
else
rele=0
Endif

goto main

Ioannis
- 9th April 2020, 00:30
On your last program, you still have in the room temperature a 3 digit value, say 250 and compare it with the Tmax that is 30.

If temperature is 250 and TMax is 30 what is the result? Portb.6 always set as you requested.

Try this and see if relay makes 2 clicks at the start of the program and then rest of the program works as expected.

If it does not click, then your port has a problem. Search other things...



'************************************************* ***************
'* Name : 16F88_LM235.BAS *
'* Author : *
'* Notice : Copyright (c) 2020 *
'* : All Rights Reserved *
'* Date : 04/04/2020 *
'* Version : 1.0 *
'*
'************************************************* ***************
'PIC 16F88
' Hardware Assignments
' --------------------
' LCD circuitery
'01 - Vss (GND)
'02 - Vdd (+5V)
'08 RS - PORTB.2
'09 E - PORTB.3
'10 DB4 - PORTB.4
'11 DB5 - PORTB.5
'12 DB6 - PORTB.6
'13 DB7 - PORTB.7


DEFINE LCD_DREG PORTB 'Porta B DATA OUT
DEFINE LCD_DBIT 4 '0 --> Bit 0-3 : 4 --> Bit 4-7


DEFINE LCD_RSREG PORTB 'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2 'LCD register select bit - Pin RS B2


DEFINE LCD_EREG PORTB 'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3 'LCD enable bit - Pin EN B3


DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD


DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us


' EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...
'================================================= ==========================
DATA @0,16 ' 16 Tenp min.
DATA @1,30 ' 30 Temp Max.
'================================================= ==========================


'================================================= ==========================
'***** SETTAGGIO PORTE


' VAR PORTA.0 'LM235M Pin 17
IncButton VAR PORTA.1 'SW Pin 18
DecButton VAR PORTA.2 'SW Pin 1
SetButton VAR PORTA.3 'SW Pin 2
' VAR PORTA.4 ' Pin 3
' VAR PORTA.5 ' Pin 4
Rele VAR PORTA.6 ' Pin 15
' VAR PORTA.7 ' Pin 16
'-----------------------------------------------
' Var PORTB.0 ' Pin 6
' var PORTB.1 ' Pin 7
l_rs var PORTB.2 'LCD sig. RS Pin 8
l_en Var PORTB.3 'LCD sig. E Pin 9
l_d4 var PORTB.4 'LCD 4 Pin 10
l_d5 var PORTB.5 'LCD 5 Pin 11
l_d6 var PORTB.6 'LCD 6 Pin 12
l_d7 var PORTB.7 'LCD 7 Pin 13


'--------------------------------------------------------------


'---------Define ADCin Parameters
DEFINE ADC_BITS 10 'set number of bits in result
DEFINE ADC_CLOCK 3 'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 'Set sampling time in uS




' RAM Assignments and Variables
'================================================= ==========================
CounterA var byte ' General purpose Variable
CounterB var byte ' General purpose Variable
CounterC var byte ' General purpose Variable
temp var word
temperature var word
samples var word
Dummy var word
sample VAR BYTE
quanta con 1250
DatoEE var byte
Tmax VAR Byte
Tmin VAR Byte
Tcomp VAR word
Grade var Byte
TimeOut var word ' Variable for SetUp Menu Time-Out
'================================================= ==========================





START:
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* ~*~*~*~*~*~*~*~*~*~*~*~*~*~
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* ~*~*~*~*~*~*~*~*~*~*~*~*~*~
for sample =0 to 3
toggle portb.6
pause 250
next sample

' -------- bit a bit controllo 0=output 1=input


INTCON = 0 ' NO INTERRUPT
ADCON1 = 001110 '
ADCON0= 000101 'Disable Converter Module
while !adcon0.0:wend ' Attende che il convertitore sia spento prima di fare il resto
ANSEL = 000001 'Disable Inputs Tranne AN0
OSCCON = 100000 'Internal RC set to 4MHZ
CMCON = 7 '
'76543210
TRISA = 111111 ' impostazioni INP/OUT
TRISB = 000000 ' delle porte
'----------------------------------------------------


' Per utilizare i pin RA6 ed RA7 come I/O bisogna impostare lo switch in fase
' di programmazione Oscillotar come "INTRC_IO"
PORTA.6=0





' Leggi Dati dalla EEPROM
'================================================= ==========================
Read 0,DatoEE
Tmin=DatoEE


Read 1,DatoEE
Tmax=DatoEE
'================================================= ==========================

Lcdout $FE, 1 'Clear screen


MAIN:


'Subroutine to measure temp
'----------------------------------------------------
TEMP_READ:
temp = 0 'Clear temp register
temperature = 0 'Clear temperature register
sample = 0 'Clear sample register
samples = 0 'Clear samples register


do
sample = 0
FOR sample = 1 TO 20 'Take 20 samples
ADCIN 0, temp 'Read AN0 into temp variable
samples = samples + temp
PAUSE 50 ' Wait 1/4 seconds per reading
NEXT sample
temp = samples/20 'Average over 20 samples (Every 5 seconds)
temperature= (temp*10) */ quanta


Pause 200 ' Timeout for LCD to settle
LCDOUT $FE, 1 ' cancella LCD
LCDOUT $FE, 2 ' ritorna al primo carattere
lcdout $FE, 2, "Temp. ",dec2 (temperature/100),".", dec1 (temperature//100),$DF,"C "
lcdout $FE, $C0, "Tmin ",#Tmin DIG 1,#Tmin Dig 0," Tmax ",#Tmax DIG 1,#Tmax Dig 0



temperature=temperature/10

If temperature> TMax then
PORTA.6=1
else
PORTA.6=0
Endif


'lcdout $FE, $C0, "Tmax ",#Tmax DIG 1,#Tmax Dig 0," Tco ",dec2 (Tcomp/100),".", dec1 (Tcomp//100)
loop


goto MAIN
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* ~*~*~*~*~*~*~*~*~*~*~*~*~*~
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* ~*~*~*~*~*~*~*~*~*~*~*~*~*~


Ioannis

richard
- 9th April 2020, 00:43
On your last program, you still have in the room temperature a 3 digit value, say 250 and compare it with the Tmax that is 30.


If temperature is 250 and TMax is 30 what is the result? Portb.6 always set as you requested.


for a Temperature of 30 deg the temperature var would equal 3000 , what 3 digit number are we talking about, the display is to two
decimal points the comparison must be on equal terms

If temperature > (Tmax*100) then
rele=1
else
rele=0
Endif



or


If (temperature/100) > Tmax then
rele=1
else
rele=0
Endif

Ioannis
- 9th April 2020, 08:19
Yeah Richard. I missed that.

Also he must check if the port is working.

Ioannis

cobuccit
- 9th April 2020, 09:27
Hi, I added the loop at the beginning of the program:




for sample = 0 to 3
rele=1
pause 1000
rele=0
pause 1000
next sample




Yours was too fast and I didn't hear the clicks. It is now OK, at start-up three times the relay turns ON / OFF, then the display appears.


As always, however, dividing the variable "temperature" by 10 or 100 and multiplying the variable "Tmax" by 10 or 100 the comapration between the two variables fails. and the end result is that the relay goes ON despite the Tmax is set to 30 and the value read by the sensor is 24 ° C (or at least I think, I say 24 ° C because it is what comes out on the display giving the string



lcdout $ FE, 2, "Temp", dec2 (temperatures / 100), ".", dec1 (temperatures // 100), $ DF, "C")


If I try to show the pure "Temperature" variable on the display like this:



lcdout $ FE, $ C0, "TEmpe", temperatures



an ASCII character appears on the display which changes as the temperature changes.



I'm currently running this code




'************************************************* ***************
'* Name : 16F88_LM235.BAS *
'* Author : *
'* Notice : Copyright (c) 2020 *
'* : All Rights Reserved *
'* Date : 04/04/2020 *
'* Version : 1.0 *
'*
'************************************************* ***************
'PIC 16F88
' Hardware Assignments
' --------------------
' LCD circuitery
'01 - Vss (GND)
'02 - Vdd (+5V)
'08 RS - PORTB.2
'09 E - PORTB.3
'10 DB4 - PORTB.4
'11 DB5 - PORTB.5
'12 DB6 - PORTB.6
'13 DB7 - PORTB.7


' -------- bit a bit controllo 0=output 1=input


INTCON = 0 ' NO INTERRUPT
ADCON1 = 001110 '
ADCON0 = 0101 'Disable Converter Module
ANSEL = 000001 'Disable Inputs Tranne AN0
OSCCON = 100000 'Internal RC set to 4MHZ
CMCON = 7
TRISA = 001111 ' impostazioni INP/OUT
TRISB = 000000 ' delle porte
'----------------------------------------------------




DEFINE LCD_DREG PORTB 'Porta B DATA OUT
DEFINE LCD_DBIT 4 '0 --> Bit 0-3 : 4 --> Bit 4-7




DEFINE LCD_RSREG PORTB 'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2 'LCD register select bit - Pin RS B2




DEFINE LCD_EREG PORTB 'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3 'LCD enable bit - Pin EN B3




DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD




DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us




' EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...
'================================================= ==========================
'================================================= ==========================




'================================================= ==========================
'***** SETTAGGIO PORTE




' VAR PORTA.0 'LM235M Pin 17
IncButton VAR PORTA.1 'SW Pin 18
DecButton VAR PORTA.2 'SW Pin 1
SetButton VAR PORTA.3 'SW Pin 2
' VAR PORTA.4 ' Pin 3
' VAR PORTA.5 ' Pin 4
Rele VAR PORTA.6 ' Pin 15
' VAR PORTA.7 ' Pin 16
'-----------------------------------------------
' Var PORTB.0 ' Pin 6
' var PORTB.1 ' Pin 7
l_rs var PORTB.2 'LCD sig. RS Pin 8
l_en Var PORTB.3 'LCD sig. E Pin 9
l_d4 var PORTB.4 'LCD 4 Pin 10
l_d5 var PORTB.5 'LCD 5 Pin 11
l_d6 var PORTB.6 'LCD 6 Pin 12
l_d7 var PORTB.7 'LCD 7 Pin 13




'--------------------------------------------------------------




'---------Define ADCin Parameters
DEFINE ADC_BITS 10 'set number of bits in result
DEFINE ADC_CLOCK 3 'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 'Set sampling time in uS








' RAM Assignments and Variables
'================================================= ==========================
CounterA var byte ' General purpose Variable
CounterB var byte ' General purpose Variable
CounterC var byte ' General purpose Variable
Dummy var word
DatoEE var byte
Tcomp VAR word
Grade var Byte
TimeOut var word ' Variable for SetUp Menu Time-Out
temp var word
temperature var word
samples var word


sample VAR BYTE
quanta con 1250
Tmax VAR byte
Tmin VAR byte
'================================================= ==========================


Tmin=16
Tmax=30

START:
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* ~*~*~*~*~*~*~*~*~*~*~*~*~*~
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* ~*~*~*~*~*~*~*~*~*~*~*~*~
for sample = 0 to 3
rele=1
pause 1000
rele=0
pause 1000
next sample




Lcdout $FE, 1 'Clear screen

temp = 0 'Clear temp register
temperature = 0 'Clear temperature register
sample = 1 'Clear sample register
samples = 0 'Clear samples register


'rele=0


main:

samples=0
FOR sample = 1 TO 20 'Take 20 samples
ADCIN 0, temp 'Read AN0 into temp variable
samples = samples + temp
PAUSE 40 ' Wait 1/4 seconds per reading
NEXT sample
temp = samples/20 'Average over 20 samples (Every 5 seconds)
temperature= (temp*10) */ quanta




Pause 200 ' Timeout for LCD to settle
LCDOUT $FE, 1 ' cancella LCD
LCDOUT $FE, 2 ' ritorna al primo carattere
lcdout $FE, 2, "Temp ",dec2 (temperature/100),".", dec1 (temperature//100),$DF,"C"
lcdout $FE, $C0," TEmpe", temperature


Tmax=Tmax*100

If temperature > Tmax then
rele=1
else
rele=0
Endif

goto main

richard
- 9th April 2020, 09:32
Tmax=Tmax*100 you cannot do this ,Tmax is a byte var

If temperature > Tmax then
rele=1
else
rele=0
Endif

goto main



this will work the pbp inline intermediate results are word sized

If temperature > (Tmax*100) then
rele=1
else
rele=0
Endif

cobuccit
- 9th April 2020, 10:00
this will work the pbp inline intermediate results are word sized
[CODE]If temperature > (Tmax*100) then
rele=1
else
rele=0
Endif


I tried, but nothing changes

my code now is :


​'********************************************** ******************'* Name : 16F88_LM235.BAS *
'* Author : *
'* Notice : Copyright (c) 2020 *
'* : All Rights Reserved *
'* Date : 04/04/2020 *
'* Version : 1.0 *
'*
'************************************************* ***************
'PIC 16F88
' Hardware Assignments
' --------------------
' LCD circuitery
'01 - Vss (GND)
'02 - Vdd (+5V)
'08 RS - PORTB.2
'09 E - PORTB.3
'10 DB4 - PORTB.4
'11 DB5 - PORTB.5
'12 DB6 - PORTB.6
'13 DB7 - PORTB.7


' -------- bit a bit controllo 0=output 1=input


INTCON = 0 ' NO INTERRUPT
ADCON1 = 001110 '
ADCON0 = 0101 'Disable Converter Module
ANSEL = 000001 'Disable Inputs Tranne AN0
OSCCON = 100000 'Internal RC set to 4MHZ
CMCON = 7
TRISA = 001111 ' impostazioni INP/OUT
TRISB = 000000 ' delle porte
'----------------------------------------------------




DEFINE LCD_DREG PORTB 'Porta B DATA OUT
DEFINE LCD_DBIT 4 '0 --> Bit 0-3 : 4 --> Bit 4-7




DEFINE LCD_RSREG PORTB 'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2 'LCD register select bit - Pin RS B2




DEFINE LCD_EREG PORTB 'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3 'LCD enable bit - Pin EN B3




DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD




DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us




' EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...
'================================================= ==========================
'================================================= ==========================




'================================================= ==========================
'***** SETTAGGIO PORTE




' VAR PORTA.0 'LM235M Pin 17
IncButton VAR PORTA.1 'SW Pin 18
DecButton VAR PORTA.2 'SW Pin 1
SetButton VAR PORTA.3 'SW Pin 2
' VAR PORTA.4 ' Pin 3
' VAR PORTA.5 ' Pin 4
Rele VAR PORTA.6 ' Pin 15
' VAR PORTA.7 ' Pin 16
'-----------------------------------------------
' Var PORTB.0 ' Pin 6
' var PORTB.1 ' Pin 7
l_rs var PORTB.2 'LCD sig. RS Pin 8
l_en Var PORTB.3 'LCD sig. E Pin 9
l_d4 var PORTB.4 'LCD 4 Pin 10
l_d5 var PORTB.5 'LCD 5 Pin 11
l_d6 var PORTB.6 'LCD 6 Pin 12
l_d7 var PORTB.7 'LCD 7 Pin 13




'--------------------------------------------------------------




'---------Define ADCin Parameters
DEFINE ADC_BITS 10 'set number of bits in result
DEFINE ADC_CLOCK 3 'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 'Set sampling time in uS








' RAM Assignments and Variables
'================================================= ==========================
CounterA var byte ' General purpose Variable
CounterB var byte ' General purpose Variable
CounterC var byte ' General purpose Variable
Dummy var word
DatoEE var byte
Tcomp VAR word
Grade var Byte
TimeOut var word ' Variable for SetUp Menu Time-Out
temp var word
temperature var word
samples var word


sample VAR BYTE
quanta con 1250
Tmax VAR byte
Tmin VAR byte
'================================================= ==========================


Tmin=16
Tmax=30

START:
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* ~*~*~*~*~*~*~*~*~*~*~*~*~*~
'*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* ~*~*~*~*~*~*~*~*~*~*~*~*~
for sample = 0 to 3
rele=1
pause 1000
rele=0
pause 1000
next sample




Lcdout $FE, 1 'Clear screen

temp = 0 'Clear temp register
temperature = 0 'Clear temperature register
sample = 1 'Clear sample register
samples = 0 'Clear samples register


'rele=0


main:

samples=0
FOR sample = 1 TO 20 'Take 20 samples
ADCIN 0, temp 'Read AN0 into temp variable
samples = samples + temp
PAUSE 40 ' Wait 1/4 seconds per reading
NEXT sample
temp = samples/20 'Average over 20 samples (Every 5 seconds)
temperature= (temp*10) */ quanta




Pause 200 ' Timeout for LCD to settle
LCDOUT $FE, 1 ' cancella LCD
LCDOUT $FE, 2 ' ritorna al primo carattere
lcdout $FE, 2, "Temp ",dec2 (temperature/100),".", dec1 (temperature//100),$DF,"C"
lcdout $FE, $C0," TEmpe", temperature



If temperature > (Tmax*100) then
rele=1
else
rele=0
Endif

goto main

richard
- 9th April 2020, 10:12
lcdout $FE, $C0," TEmpe", temperature

what does this line display the temperature value as ?

cobuccit
- 9th April 2020, 11:19
lcdout $FE, $C0," TEmpe", temperature

what does this line display the temperature value as ?

ASCII code, one strange character, and it changes every time the temperature changes

richard
- 9th April 2020, 12:07
ASCII code, one strange character, and it changes every time the temperature changes

lcdout $FE, $C0," TEmpe", dec temperature


removing all the unused/unecessary stuff " just noise" , using a proper config and displaying a result more in keeping with lm35 accuracy

this works just fine

'************************************************* ***************'* '* Name : 16F88_LM235.BAS *
'* Author : *
'* Notice : Copyright (c) 2020 *
'* : All Rights Reserved *
'* Date : 04/04/2020 *
'* Version : 1.0 *
'*
'************************************************* ***************
#CONFIG
__config _CONFIG1, _INTRC_IO & _WDT_ON & _PWRTE_OFF & _MCLR_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _DEBUG_OFF & _CCP1_RB0 & _CP_OFF
__config _CONFIG2, _FCMEN_ON & _IESO_ON
#ENDCONFIG
'PIC 16F88
' Hardware Assignments
' --------------------
' LCD circuitery
'01 - Vss (GND)
'02 - Vdd (+5V)
'08 RS - PORTB.2
'09 E - PORTB.3
'10 DB4 - PORTB.4
'11 DB5 - PORTB.5
'12 DB6 - PORTB.6
'13 DB7 - PORTB.7


adcon1.7=1
ANSEL = %000001 'Disable Inputs Tranne AN0
OSCCON = %01100000 'Internal RC set to 4MHZ
TRISA = %10111111 ' impostazioni INP/OUT
TRISB = 0 ' delle porte
'----------------------------------------------------
DEFINE LCD_DREG PORTB 'Porta B DATA OUT
DEFINE LCD_DBIT 4 '0 --> Bit 0-3 : 4 --> Bit 4-7
DEFINE LCD_RSREG PORTB 'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2 'LCD register select bit - Pin RS B2
DEFINE LCD_EREG PORTB 'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3 'LCD enable bit - Pin EN B3DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us


' EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...


'================================================= ==========================
'***** SETTAGGIO PORTE


Rele VAR PORTA.6 ' Pin 15
'--------------------------------------------------------------
'---------Define ADCin Parameters
DEFINE ADC_BITS 10 'set number of bits in result
DEFINE ADC_CLOCK 3 'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 'Set sampling time in uS


' RAM Assignments and Variables
'================================================= ==========================
temp var word
temperature var word
samples var word
sample VAR BYTE
quanta con 1250
Tmax VAR byte
Tmin VAR byte
'================================================= ==========================
Tmin=16
Tmax=30

START:
Lcdout $FE, 1 'Clear screen
rele=0


main:
samples=0
FOR sample = 1 TO 20 'Take 20 samples
ADCIN 0, temp 'Read AN0 into temp variable
samples = samples + temp
PAUSE 40 ' Wait 1/4 seconds per reading
NEXT sample
temp = samples/20 'Average over 20 samples (Every 5 seconds)
temperature= temp */ quanta


LCDOUT $FE, 1 ' cancella LCD
LCDOUT $FE, 2 ' ritorna al primo carattere
lcdout $FE, 2, "Temp ",dec2 (temperature/10),".", dec1 (temperature//10),$DF,"C"
lcdout $FE, $C0," TEmpe", dec temperature

If temperature > (Tmax*10) then
rele=1
else
rele=0
Endif

goto main

louislouis
- 9th April 2020, 13:12
I think, You want this:
https://www.youtube.com/watch?v=nm7L-FTlR2M

Here is a Richard's corrected and tested code. I hope it will be works:


'************************************************* ***************'* '* Name : 16F88_LM235.BAS *
'* Author : *
'* Notice : Copyright (c) 2020 *
'* : All Rights Reserved *
'* Date : 04/04/2020 *
'* Version : 1.0 *
'*
'************************************************* ***************
#CONFIG
__config _CONFIG1, _INTRC_IO & _WDT_ON & _PWRTE_OFF & _MCLR_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _DEBUG_OFF & _CCP1_RB0 & _CP_OFF
__config _CONFIG2, _FCMEN_ON & _IESO_ON
#ENDCONFIG
'PIC 16F88
' Hardware Assignments
' --------------------
' LCD circuitery
'01 - Vss (GND)
'02 - Vdd (+5V)
'08 RS - PORTB.2
'09 E - PORTB.3
'10 DB4 - PORTB.4
'11 DB5 - PORTB.5
'12 DB6 - PORTB.6
'13 DB7 - PORTB.7


adcon1.7=1
ANSEL = %000001 'Disable Inputs Tranne AN0
OSCCON = %01100000 'Internal RC set to 4MHZ
TRISA = %10111111 ' impostazioni INP/OUT
TRISB = 0 ' delle porte
'----------------------------------------------------
DEFINE LCD_DREG PORTB 'Porta B DATA OUT
DEFINE LCD_DBIT 4 '0 --> Bit 0-3 : 4 --> Bit 4-7
DEFINE LCD_RSREG PORTB 'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2 'LCD register select bit - Pin RS B2
DEFINE LCD_EREG PORTB 'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3 'LCD enable bit - Pin EN B3DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us


' EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...


'================================================= ==========================
'***** SETTAGGIO PORTE


Rele VAR PORTA.6 ' Pin 15
'--------------------------------------------------------------
'---------Define ADCin Parameters
DEFINE ADC_BITS 10 'set number of bits in result
DEFINE ADC_CLOCK 3 'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 'Set sampling time in uS


' RAM Assignments and Variables
'================================================= ==========================
temp var word
temperature var word
samples var word
sample VAR BYTE
quanta con 1250
Tmax VAR byte
Tmin VAR byte
'================================================= ==========================
Tmin=16
Tmax=30

START:
Lcdout $FE, 1 'Clear screen
rele=0


main:
sample = 1
samples= 0
FOR sample = 1 TO 20 'Take 20 samples
ADCIN 0, temp 'Read AN0 into temp variable
samples = samples + temp
PAUSE 50 ' Wait 1/4 seconds per reading
NEXT sample
temp = samples/20 'Average over 20 samples (Every 5 seconds)
temperature= temp */ quanta


LCDOUT $FE, 2 ' ritorna al primo carattere
lcdout $FE, 2, "Temp ",dec2 (temperature/10),".", dec1 (temperature/10),"C"
lcdout $FE, $C0, "Tmin ",#Tmin, " Tmax ",#Tmax

If temperature > (Tmax*100) then
rele=1
else
rele=0
Endif

goto main

cobuccit
- 9th April 2020, 14:53
I think, You want this:
Here is a Richard's corrected and tested code. I hope it will be works:


'************************************************* ***************'* '* Name : 16F88_LM235.BAS *
'* Author : *
'* Notice : Copyright (c) 2020 *
'* : All Rights Reserved *
'* Date : 04/04/2020 *
'* Version : 1.0 *
'*
'************************************************* ***************
#CONFIG
__config _CONFIG1, _INTRC_IO & _WDT_ON & _PWRTE_OFF & _MCLR_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _DEBUG_OFF & _CCP1_RB0 & _CP_OFF
__config _CONFIG2, _FCMEN_ON & _IESO_ON
#ENDCONFIG
'PIC 16F88
' Hardware Assignments
' --------------------
' LCD circuitery
'01 - Vss (GND)
'02 - Vdd (+5V)
'08 RS - PORTB.2
'09 E - PORTB.3
'10 DB4 - PORTB.4
'11 DB5 - PORTB.5
'12 DB6 - PORTB.6
'13 DB7 - PORTB.7


adcon1.7=1
ANSEL = 0001 'Disable Inputs Tranne AN0
OSCCON = 100000 'Internal RC set to 4MHZ
TRISA = 111111 ' impostazioni INP/OUT
TRISB = 0 ' delle porte
'----------------------------------------------------
DEFINE LCD_DREG PORTB 'Porta B DATA OUT
DEFINE LCD_DBIT 4 '0 --> Bit 0-3 : 4 --> Bit 4-7
DEFINE LCD_RSREG PORTB 'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2 'LCD register select bit - Pin RS B2
DEFINE LCD_EREG PORTB 'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3 'LCD enable bit - Pin EN B3DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us


' EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...


'================================================= ==========================
'***** SETTAGGIO PORTE


Rele VAR PORTA.6 ' Pin 15
'--------------------------------------------------------------
'---------Define ADCin Parameters
DEFINE ADC_BITS 10 'set number of bits in result
DEFINE ADC_CLOCK 3 'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 'Set sampling time in uS


' RAM Assignments and Variables
'================================================= ==========================
temp var word
temperature var word
samples var word
sample VAR BYTE
quanta con 1250
Tmax VAR byte
Tmin VAR byte
'================================================= ==========================
Tmin=16
Tmax=30

START:
Lcdout $FE, 1 'Clear screen
rele=0


main:
sample = 1
samples= 0
FOR sample = 1 TO 20 'Take 20 samples
ADCIN 0, temp 'Read AN0 into temp variable
samples = samples + temp
PAUSE 50 ' Wait 1/4 seconds per reading
NEXT sample
temp = samples/20 'Average over 20 samples (Every 5 seconds)
temperature= temp */ quanta


LCDOUT $FE, 2 ' ritorna al primo carattere
lcdout $FE, 2, "Temp ",dec2 (temperature/10),".", dec1 (temperature/10),"C"
lcdout $FE, $C0, "Tmin ",#Tmin, " Tmax ",#Tmax

If temperature > (Tmax*100) then
rele=1
else
rele=0
Endif

goto main




Your video is OK!
and the code is similar to mine, except for the initial strings.



#CONFIG
__config _CONFIG1, _INTRC_IO & _WDT_ON & _PWRTE_OFF & _MCLR_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _DEBUG_OFF & _CCP1_RB0 & _CP_OFF
__config _CONFIG2, _FCMEN_ON & _IESO_ON
#ENDCONFIG



without too much hesitation, however, I did copy and paste of your source in my compiler
Microcode Studio Plus 3.0.0.5
and as soon as I tried to issue the compile command it gave me errors.




ERROR Line 11: Syntax error. (louislouis.pbp)
ERROR Line 12: Syntax error. (louislouis.pbp)
ERROR Line 13: Redefiniton of LABEL __config. (louislouis.pbp)
ERROR Line 13: Syntax error. (louislouis.pbp)
ERROR Line 14: Syntax error. (louislouis.pbp)



What are all those strings? why won't my compiler accept them?
Thanks

louislouis
- 9th April 2020, 15:04
did you have set the correct microcontroller to 16F88 in microcodestudio?

cobuccit
- 9th April 2020, 15:17
did you have set the correct microcontroller to 16F88 in microcodestudio?

here the Screenshoot

8809

louislouis
- 9th April 2020, 15:48
and if you take away the config part, it compiles without errors?
Copy and paste this, and try to compile.


define osc 4

adcon1.7=1
ANSEL = %000001 'Disable Inputs Tranne AN0
OSCCON = %01100000 'Internal RC set to 4MHZ
TRISA = %10111111 ' impostazioni INP/OUT
TRISB = 0 ' delle porte
'----------------------------------------------------
DEFINE LCD_DREG PORTB 'Porta B DATA OUT
DEFINE LCD_DBIT 4 '0 --> Bit 0-3 : 4 --> Bit 4-7
DEFINE LCD_RSREG PORTB 'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2 'LCD register select bit - Pin RS B2
DEFINE LCD_EREG PORTB 'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3 'LCD enable bit - Pin EN B3DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us


' EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...


'================================================= ==========================
'***** SETTAGGIO PORTE


Rele VAR PORTA.6 ' Pin 15
'--------------------------------------------------------------
'---------Define ADCin Parameters
DEFINE ADC_BITS 10 'set number of bits in result
DEFINE ADC_CLOCK 3 'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 'Set sampling time in uS


' RAM Assignments and Variables
'================================================= ==========================
temp var word
temperature var word
samples var word
sample VAR BYTE
quanta con 1250
Tmax VAR byte
Tmin VAR byte
'================================================= ==========================
Tmin=16
Tmax=30

START:
Lcdout $FE, 1 'Clear screen
rele=0


main:
sample = 1
samples= 0
FOR sample = 1 TO 20 'Take 20 samples
ADCIN 0, temp 'Read AN0 into temp variable
samples = samples + temp
PAUSE 50 ' Wait 1/4 seconds per reading
NEXT sample
temp = samples/20 'Average over 20 samples (Every 5 seconds)
temperature= temp */ quanta


LCDOUT $FE, 2 ' ritorna al primo carattere
lcdout $FE, 2, "Temp ",dec2 (temperature/10),".", dec1 (temperature/10),"C"
lcdout $FE, $C0, "Tmin ",#Tmin, " Tmax ",#Tmax

If temperature > (Tmax*100) then
rele=1
else
rele=0
Endif

goto main

cobuccit
- 9th April 2020, 16:19
and if you take away the config part, it compiles without errors?
Copy and paste this, and try to compile.


Yes, compile without problems

If I understand correctly, that's what I do when programming the chip, I set the fuses like this

8810

louislouis
- 9th April 2020, 16:29
Yes. And now it runs OK?

cobuccit
- 9th April 2020, 17:25
Yes. And now it runs OK?

No, I have always used fuses since the first moment I started creating the project.
I'm going crazy for this, I also changed PBP to version 2.47. I don't know what to think anymore.


it is evident that I have a problem, but I cannot attribute to what.


1) PBP compiler, tested with 2 versions 2.60 and 2.47
2) IDE MicroCode, I wouldn't say.
3) Microcontroller (the chip) cannot be, because if I pilot the door with the command PORTB.6 = 1 and PORTB.6 = 0 the relay attacks and disconnects regularly.
4) the BYTE or WORD variables, but I also tried to change the reference value by declaring them both as WORD.
5) The firmware is the same
6) The programmer?

I don't know what to think anymore

louislouis
- 9th April 2020, 17:39
What kind of programmer do you use? What is your programming process?
First you compile in MCSP and then take the compiled HEX file and program to PIC with your picprogrammer? Or? How you program the PIC?

louislouis
- 9th April 2020, 17:48
Here is the compiled HEX file. Take it in to your programmer and program your PIC. It must run.

cobuccit
- 9th April 2020, 18:00
What kind of programmer do you use? What is your programming process?
First you compile in MCSP and then take the compiled HEX file and program to PIC with your picprogrammer? Or? How you program the PIC?

It was a long time since I worked there, I pulled out old tools because I stopped at work for the "Corona Virus" and I wanted to have some fun.
Some time ago I used a self-built ProPic2, which went on parallel port.
Now that I no longer have the parallel port, I bought a K150 on the internet. This mounts on USB.


1) I write the code in MicroCode
2) the MicroCode settings are these

8812


3) I take the .Hex file
4) I load the firmware for download on this program:

8813

5) I mount the chip on the K150
6) I program
7) At the end I reassemble my chip in the BreadBoard

and go ON

cobuccit
- 9th April 2020, 18:14
Here is the compiled HEX file. Take it in to your programmer and program your PIC. It must run.

Excellent, I tried. But it behaves the same way !! :eek::eek:

I noticed that by entering your firmware the fuses are set automatically as I manually set them.
And that's OK.

But the behavior seems identical to that compiled by me. After an initial click, the relay goes ON even when the temperature is lower than 30 ° and when it exceeds 30 ° nothing happens.

louislouis
- 9th April 2020, 18:54
This compiled HEX test your PORTA.6 (pin 15) on your PIC if is it wired right.
It switch ON and OFF the relay five times, on LCD write: Rele ON if activate the pin
and Rele OFF when deactivate the pin.
If this perform As I wrote then the rele is wired OK and works. Then the fault must be elsewhere.
Then we go troubleshoot further more.

cobuccit
- 9th April 2020, 19:57
[QUOTE = louislouis; 145045] Questo HEX compilato verifica il tuo PORTA.6 (pin 15) sul PIC se è cablato correttamente.
Accedere e spendere il relè cinque volte, sul display LCD scrive: Rele ON se si attiva il pin
e Rele OFF quando si disattiva il pin.
Se questo funziona Come ho scritto, il rele è cablato OK e funziona. Quindi la colpa deve essere altrove.
Quindi andremo a risolvere i problemi. [/ QUOTE]


Ti confermo.
Il relè attiva e disattiva 5 volte l'


ultimo passaggio, spegne il relè, pulisce lo schermo e non appena lo schermo mostra le temperature, il relè viene attivato.


A quel punto non succede più nulla, anche quando la temperatura ambiente supera i 30 °

louislouis
- 9th April 2020, 20:27
OK, please program this HEX and tell what number shown on display. Then warm up the sensor with fingers or soldering iron. The numbers should be arround 600 for 30degC and 700 for 35degC and so on.
This test the ADC reading on your PIC.

cobuccit
- 9th April 2020, 20:49
[QUOTE = louislouis; 145048] OK, si prega di registrare questo esadecimale e dire quale numero mostrato sul display. Quindi riscaldare il sensore con le dita o il saldatore. I numeri devono essere intorno a 600 per 30 ° C e 700 per 35 ° C e così via.
Questo test la lettura ADC sul PIC. [/ QUOTE]


Prima di installare questo firmware il display mostrava 25,5 ° C.
Con questo firmware sul display della legge 665.
Tenendo il sensore tra le dita puoi vedere il valore salire 670, 674, 677.679 ... ecc.

louislouis
- 9th April 2020, 21:20
That's confirms the ADC readings is OK.

If you program this HEX (thermometerNOrele.hex), the rele must be allways switched OFF. Yes or No?

Then program this HEX (thermometerTEST.hex), probably this should be working proper. Yes or No?

cobuccit
- 9th April 2020, 21:34
That's confirms the ADC readings is OK.

If you program this HEX (thermometerNOrele.hex), the rele must be allways switched OFF. Yes or No?



OK, the rele allways switched OFF



Then program this HEX (thermometerTEST.hex), probably this should be working proper. Yes or No?

after the display appears, the relay goes ON and remains there regardless of the temperature.

NOTA

As soon as I turn on, there is a quick initial CLICK-CLACK. I believe the PIC port is set. he always has. Then he shows me the numbers on the display and the relay goes ON and does not move anymore, whatever the temperature.

louislouis
- 9th April 2020, 22:09
That's weird behaviour. I don't had on hand 16F88, I run it on 16F690, but it doesn't matter.
OK, one more chance try this:

cobuccit
- 9th April 2020, 22:37
That's weird behaviour. I don't had on hand 16F688, I run it on 16F690, but it doesn't matter.
OK, one more chance try this:


OK ! NOW WORK !

Where was the problem ?
Can you explain to me ?

can you also show me how you managed to show the hexadecimal value 665 on the display?

I am truly grateful to you for taking the time. Thank you very much.

louislouis
- 9th April 2020, 22:58
I'm just curious, can you please try this hex, is It working OK?

cobuccit
- 9th April 2020, 23:08
I'm just curious, can you please try this hex, is It working OK?

No, it doesn't work, the relay goes ON as soon as I see the display and then it doesn't move anymore

louislouis
- 9th April 2020, 23:28
Here is the code. Look at the comments, and modify the RAW number to number when the display show 30.0degC.


define osc 4
adcon1.7=1
ANSEL = %000001 'Disable Inputs Tranne AN0
ADCON1 = %10001110
OSCCON = %01100000 'Internal RC set to 4MHZ
TRISA = %00000001 ' impostazioni INP/OUT
TRISB = %00000000 ' delle porte
'----------------------------------------------------
DEFINE LCD_DREG PORTB 'Porta B DATA OUT
DEFINE LCD_DBIT 4 '0 --> Bit 0-3 : 4 --> Bit 4-7
DEFINE LCD_RSREG PORTB 'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2 'LCD register select bit - Pin RS B2
DEFINE LCD_EREG PORTB 'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3 'LCD enable bit - Pin EN B3DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us

Rele VAR PORTA.6 ' Pin 15
'--------------------------------------------------------------
'---------Define ADCin Parameters
DEFINE ADC_BITS 10 'set number of bits in result
DEFINE ADC_CLOCK 3 'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 'Set sampling time in uS


' RAM Assignments and Variables
'================================================= ==========================
temp var word
temperature var word
samples var word
sample VAR BYTE
quanta con 1250
Tmax VAR byte
Tmin VAR byte
'================================================= ==========================
Tmin=16
Tmax=30

START:
Lcdout $FE, 1

low rele

main:
sample = 1
samples= 0
FOR sample = 1 TO 20 'Take 20 samples
ADCIN 0, temp 'Read AN0 into temp variable
samples = samples + temp
PAUSE 50 ' Wait 1/4 seconds per reading
NEXT sample
temp = samples/20 'Average over 20 samples (Every 5 seconds)
temperature= temp */ quanta

if temp > 675 then high rele 'Instead 675 write the correct RAW number for 30degC
if temp < 675 then low rele 'Instead 675 write the correct RAW number for 30degC

LCDOUT $FE, 2 ' ritorna al primo carattere
lcdout $FE, 2, "Temp ",dec2 (temperature/10),".", dec1 (temperature/10),"C"
'lcdout $FE, $C0, "Tmin ",#Tmin, " Tmax ",#Tmax FOR NORMAL OPERATION UNCOMMENT LINE
lcdout $FE, $C0, "RAW:",dec temp 'this show the ADC value FOR NORMAL OPERATION COMMENT OR DELETE THIS LINE

'When the display show 30,0 degC look at the RAW number on LCD and rewrite it in lines: if temp > 675 then high rele
'and if temp < 675 then low rele .

goto main

richard
- 10th April 2020, 00:14
not sure whats going on here

my LM35 has a 0.3 volt output @30c, adc value 61 [10mV/deg]

an adc read of 675 would need 329 deg

louislouis
- 10th April 2020, 00:23
on 10bit adc?

richard
- 10th April 2020, 00:24
correct 10 bit 1024 counts @5v vcc

richard
- 10th April 2020, 03:37
i get same result from proteus

88208821


'************************************************* ***************'*
'* Name : 16F88_LM35.BAS *
'* Author : *
'* Notice : Copyright (c) 2020 *
'* : All Rights Reserved *
'* Date : 04/04/2020 *
'* Version : 1.0 *
'* PIC 16F88
'************************************************* ***************
#CONFIG
__config _CONFIG1, _INTRC_IO & _WDT_ON & _PWRTE_OFF & _MCLR_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _DEBUG_OFF & _CCP1_RB0 & _CP_OFF
__config _CONFIG2, _FCMEN_ON & _IESO_ON
#ENDCONFIG


adcon1.7=1
ANSEL = %00000001 'Disable Inputs Tranne AN0
OSCCON = %01100000 'Internal RC set to 4MHZ
TRISA = %10111111 ' impostazioni INP/OUT
TRISB = 0 ' delle porte
'----------------------------------------------------
DEFINE LCD_DREG PORTB 'Porta B DATA OUT
DEFINE LCD_DBIT 4 '0 --> Bit 0-3 : 4 --> Bit 4-7
DEFINE LCD_RSREG PORTB 'LCD register select port - Porta B --> RS
DEFINE LCD_RSBIT 2 'LCD register select bit - Pin RS B2
DEFINE LCD_EREG PORTB 'LCD enable port - Porta B --> EN
DEFINE LCD_EBIT 3 'LCD enable bit - Pin EN B3DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us

' EEPROM
data @0,16,30
'================================================= ==========================
'***** SETTAGGIO PORTE
Rele VAR PORTA.6 ' Pin 15

'---------Define ADCin Parameters
DEFINE ADC_BITS 10 'set number of bits in result
DEFINE ADC_CLOCK 3 'set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 'Set sampling time in uS

' RAM Assignments and Variables
'================================================= ==========================
temp var word
temperature var word
samples var word
sample VAR BYTE
quanta con 1249
Tmax VAR byte
Tmin VAR byte
'================================================= ==========================
pause 500
START:
read 0,tmin,tmax
Lcdout $FE, 1 'Clear screen
rele=0
main:
samples=0
FOR sample = 1 TO 10 'Take 10 samples
ADCIN 0, temp 'Read AN0 into temp variable
samples = samples + temp
PAUSE 40 ' Wait 1/4 seconds per reading
NEXT sample
temp = samples/10 'Average over 10 samples
temperature= temp */ quanta
LCDOUT $FE, 1 ' cancella LCD
lcdout "Temp ",dec2 (temperature/10),".", dec1 (temperature//10),$DF,"C"
lcdout $FE, $C0,"temp ", dec temp
If temperature > (Tmax*10) then
rele=1
else
rele=0
Endif
goto main

richard
- 10th April 2020, 04:59
not sure whats going on here

my LM35 has a 0.3 volt output @30c, adc value 61 [10mV/deg]

an adc read of 675 would need 329 deg

i think i see the problem, if louis is using a 16f690 then the adc settings used are totally inappropriate
adc control on a 16f690 is quite different to a 16f88

define osc 4 ;there is no define called osc
adcon1.7=1 ;bit 7 is unimplemented
ADCON1 = %10001110 ;fosc/2 adc clk bits 0:3 and 7 are unimplemented


should be
define OSC 4 ;OSC = 4
adcon0.7=1 ;right justify result
adcon1= %00110000 ; frc adc clk

louislouis
- 10th April 2020, 07:03
no, no. The problem why is the ADC reading high is the LM335 wiring. Cobuccit has wired a "pullup" resistor to LM335 from 5V and this shifting the output voltage to 3V at 30degC.

My ADC settings on 16F690 is correct, I don't use settings for 16F88 on 16F690 of course.
Anyway, I tried to figure out what's wrong with Cobuccit's setup and then I look at web and find the most popular LM335 wiring and then I got it. He has probably wired the sensor like this and that's the problem in cooperation with his posted code.

richard
- 10th April 2020, 07:15
i see no schematic anywhere and post 1 says a lm35, a pullup for a lm35 is not warranted.
this has turned into a pointless exercise in guesswork.

richard
- 10th April 2020, 07:27
this won't work properly with those readings either

670 */ 1250 = 3271 and would display as 27.1 deg with following code


temperature= temp */ quanta ; this result is now 4 digits




lcdout $FE, 2, "Temp ",dec2 (temperature/10),".", dec1 (temperature/10),"C"


its just so wrong i give up

louislouis
- 10th April 2020, 07:46
Yea lm35, I overlooked that. You have right. I had no info about Cobuccit's setup, wiring, etc. Difficult to gave correct advice. If he use your posted schematic, and code it must be run whitout problems.

richard
- 10th April 2020, 08:17
yes its a good reminder.
code snippets for debugging are a pointless exercise
code without a config section or at least in some way describing the config settings is a waste of time
code without a schematic leads to pointless speculation and wasted time and resources
if you are using a version of pbp that noah had in the ark at least tell us.
gigo garbage in garbage out
lucky covid has us all trapped inside bored shitless

richard
- 10th April 2020, 08:20
if your lm335 setup was used you need to subtract the offset
eg

main:
samples=0
FOR sample = 1 TO 10 'Take 10 samples
ADCIN 0, temp 'Read AN0 into temp variable
samples = samples + temp
PAUSE 40 ' Wait 1/4 seconds per reading
NEXT sample
temp = (samples/10) -558 'subtract 2.73 v offset count
temperature= temp */ quanta
LCDOUT $FE, 1 ' cancella LCD
lcdout "Temp ",dec2 (temperature/10),".", dec1 (temperature//10),$DF,"C"
lcdout $FE, $C0,"temp raw ", dec temp
If temperature > (Tmax*10) then
rele=1
else
rele=0
Endif
goto main

louislouis
- 10th April 2020, 09:54
I'm pretty sure, He has incorrectly wired the lm35 and that caused the weird behaviour. Tested in proteus, working firmware with wrong lm35 wiring causes relay always on.
Conclusion, I need a drink :) Richard's code and schematic is the correct one. Please use it, it works.

Just in case, here is the schematic and code for lm335:

cobuccit
- 10th April 2020, 10:52
Hello gentlemen forgive me, I think I put you in trouble. As I explained in some previous posts I pulled out an old "BreadBoard" to play on in this time of "Corona Virus".


You are right, I looked at it for the good end I do not have an LM35, I have an LM235H recovered who knows where.
its pattern is the current:

8826

Ioannis
- 10th April 2020, 11:39
Oh dear... come on now!

Ioannis

richard
- 10th April 2020, 11:53
guess its my fault , should have launched into defensive mode on first reply
like this
it looked too easy.

http://www.picbasic.co.uk/forum/showthread.php?t=24035

questions to ask

(http://www.picbasic.co.uk/forum/showthread.php?t=24035)
what have you tried ?
what are you measuring ?
where is your schematic ?
your code is incomplete what is in your config section ?
i see an incompletely described pgm with no config settings
in an unspecified circuit
no OSC statement in pbp code and still not a clue about the config settings used



it just occurred to me that the op may be a troll and we have just been played.
there is no way that the the op's code would ever have shown a realistic temp display with a lm335/lm235
because multiplying the reading with an offset would yield meaningless results.
it could have displayed a lm35 result as it was .
at no time did op ever say the displayed temp results were also wrong
i wonder.

louislouis
- 10th April 2020, 13:21
Do you think the op just troll us?

richard
- 10th April 2020, 14:15
Do you think the op just troll us?

seems likely when you analyse it a bit

how many newcomers can use the */ operator properly
temperature= (temp*10) */ quanta
or format a lcd line
lcdout $FE, 2, "Temp ",dec2 (temperature/100),".", dec1 (temperature//100),$DF,"C"

yet cannot use an if else block to set/clear a pin from a simple comparison

cobuccit
- 10th April 2020, 14:42
it just occurred to me that the op may be a troll and we have just been played..



:mad::mad: ...

But please, thank you very much but don't make up stories.

What does this phrase mean, which I pretended not to know how to do?
A long time ago I was a more practical programmer and I certainly do not miss old preserved codes on which I went to browse to retrieve pieces of code here and there.

I had the working object and could not find the source. Since I had noticed a bug I wanted to correct it. Not finding the source I thought to rewrite it. From there the adventure began.

I am dusting off, I would love to start being a programmer again but times run like the wind.

I hope to get back on track.

I hope it is clear what I write, I use google translator.

richard
- 10th April 2020, 15:36
But please, thank you very much but don't make up stories

i feel no shame , if it looks like a duck and it walks like a duck i'm prepared to say it could be a duck.

you misled us with the sensor type, provided code that really can't display a meaningful result for the actual sensor in use
yet provide no indication of that problem at all. you go on to describe a problem that's actually not relevant as if that's the main issue.
worse still the code provided could very well have displayed proper temperature data with the bogus sensor.
a troller would have been proud of the effort and result.
its not a good look for a new user.

cobuccit
- 10th April 2020, 16:14
you misled us with the sensor type, provided code that really can't display a meaningful result for the actual sensor in use
yet provide no indication of that problem at all. you go on to describe a problem that's actually not relevant as if that's the main issue.
worse still the code provided could very well have displayed proper temperature data with the bogus sensor.
a troller would have been proud of the effort and result.
its not a good look for a new user.

Well I'm sorry. I don't know why you like to make all these insinuations.
But I can guarantee you that I had no bad intention. And I don't think it's fair to judge a person like that, but what I've done wrong?
But every time I have to post something, I have to be afraid of being investigated in this way.
Richard, maybe you see too many detective films. :)
Well I'm sorry. I don't know why you like to make all these insinuations.
But I can guarantee you that I had no bad intention. And I don't think it's fair to judge a person like that, but what I've done wrong?
But every time I have to post something, I have to be afraid of being investigated in this way.
Richard, maybe you see too many detective films.
In any case, I think, it is going off topic. I was here to learn and get advice, not to be charged.

Ioannis
- 10th April 2020, 17:29
Calm everybody please.

End of story.

Seems that our lockdown makes everybody more sensitive!

Ioannis