Compare value ...


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 69

Hybrid View

  1. #1
    Join Date
    Apr 2020
    Posts
    30

    Default Compare value ...

    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




  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

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

    then --
    Code:
    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

    Code:
    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
    Code:
    PAUSE 50 ' Wait 1/4 seconds per reading
    Warning I'm not a teacher

  3. #3
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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

  4. #4
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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:
    Attached Files Attached Files
    Last edited by louislouis; - 9th April 2020 at 22:33.

  6. #6
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Quote Originally Posted by louislouis View Post
    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.

  7. #7
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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

  9. #9
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Quote Originally Posted by Ioannis View Post
    Try:

    1.
    ADCON0= 000101
    while !adcon0.2:wend
    with this the Pic16F88 not working






    Quote Originally Posted by Ioannis View Post
    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

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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:

    Code:
    ADCON0=%10000101
    while !adcon0.0:wend
    I would not set bit 2 at this stage but anyway.

    Ioannis

  11. #11


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    I'm just curious, can you please try this hex, is It working OK?
    Attached Files Attached Files

  12. #12
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Quote Originally Posted by louislouis View Post
    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

  13. #13


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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?
    Attached Files Attached Files

  14. #14
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Quote Originally Posted by louislouis View Post
    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

    Quote Originally Posted by louislouis View Post
    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.

  15. #15


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Try this:
    Code:
    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

  16. #16
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Quote Originally Posted by louislouis View Post
    Try this:
    Code:
    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.

  17. #17


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Pplease post the whole code.

  18. #18
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Quote Originally Posted by louislouis View Post
    Pplease post the whole code.
    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
    '*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
    '*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

  19. #19


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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.
    Attached Images Attached Images  

  20. #20
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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.
    Warning I'm not a teacher

  21. #21
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    this won't work properly with those readings either

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

    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
    Warning I'm not a teacher

  22. #22


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Try 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 = %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

  23. #23
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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...

    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:
    '*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
    '*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
    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

  24. #24
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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
    Code:
    If temperature > (Tmax*100) then
    rele=1
    else
    rele=0
    Endif

    or

    Code:
    If (temperature/100) > Tmax then
    rele=1
    else
    rele=0
    Endif
    Warning I'm not a teacher

  25. #25
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Yeah Richard. I missed that.

    Also he must check if the port is working.

    Ioannis

  26. #26
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Hi, I added the loop at the beginning of the program:

    Code:
    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

    Code:
    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:

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

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



    I'm currently running this code

    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

  27. #27
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Code:
    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
    Code:
    If temperature > (Tmax*100) then
    rele=1
    else
    rele=0
    Endif
    Warning I'm not a teacher

  28. #28
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Quote Originally Posted by richard View Post

    [CODE]

    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 :

    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
    
    
          
    If temperature > (Tmax*100) then
    rele=1
    else
    rele=0
    Endif
                                    
    goto main

  29. #29


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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:
    Attached Images Attached Images   
    Attached Files Attached Files
    Last edited by louislouis; - 10th April 2020 at 10:20.

  30. #30
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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:

    Name:  scheme.jpg
Views: 1611
Size:  28.8 KB

  31. #31


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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.

  32. #32
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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
    Warning I'm not a teacher

  33. #33
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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
    Last edited by richard; - 10th April 2020 at 08:29.
    Warning I'm not a teacher

  34. #34


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    I think, You want this:


    Here is a Richard's corrected and tested code. I hope it will be works:
    Code:
    '****************************************************************'*  '*  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

  35. #35
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Quote Originally Posted by louislouis View Post
    I think, You want this:
    Here is a Richard's corrected and tested code. I hope it will be works:
    Code:
    '****************************************************************'*  '*  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.

    Code:
    #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.

    Code:
    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

  36. #36


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    did you have set the correct microcontroller to 16F88 in microcodestudio?

  37. #37
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Quote Originally Posted by louislouis View Post
    did you have set the correct microcontroller to 16F88 in microcodestudio?
    here the Screenshoot

    Name:  Untitled.jpg
Views: 2434
Size:  266.1 KB

  38. #38


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    and if you take away the config part, it compiles without errors?
    Copy and paste this, and try to compile.
    Code:
    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

  39. #39
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Quote Originally Posted by louislouis View Post
    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

    Name:  Untitled.jpg
Views: 2451
Size:  60.3 KB

  40. #40


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Yes. And now it runs OK?

Similar Threads

  1. How to compare two temperatures
    By SKOLS1 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th April 2012, 09:07
  2. how to hserin compare with known value?
    By aa222k in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd November 2010, 18:48
  3. Is there a faster way to compare?
    By RussMartin in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 8th February 2010, 19:48
  4. how to compare data
    By Mus.me in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 1st November 2009, 22:30
  5. Compare Data
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 14th February 2008, 20:40

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts