Compare value ...


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    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

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


    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

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    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

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

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,692


    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

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

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,692


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

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

    what does this line display the temperature value as ?
    Warning I'm not a teacher

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

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,692


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

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

  10. #10


    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 11:20.

  11. #11
    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: 5047
Size:  28.8 KB

  12. #12
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Oh dear... come on now!

    Ioannis

  13. #13
    Join Date
    May 2013
    Location
    australia
    Posts
    2,692


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    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

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

  14. #14


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Do you think the op just troll us?

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

    it just occurred to me that the op may be a troll and we have just been played..
    ...

    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.

  16. #16


    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.

  17. #17
    Join Date
    May 2013
    Location
    australia
    Posts
    2,692


    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

  18. #18
    Join Date
    May 2013
    Location
    australia
    Posts
    2,692


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

Similar Threads

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