Compare value ...


Closed Thread
Results 1 to 40 of 69

Hybrid View

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


    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

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

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

  4. #4


    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 23:33.

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

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

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


    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

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

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


    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

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

    Code:
    ADCON0=000101
    while !adcon0.0:wend

    OK, Perfect this work well now


    Quote Originally Posted by Ioannis View Post
    Don't you see? You display a decimal number but the number is in fact 245 and not 24.5!

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

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

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

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

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

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


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    You should make it word. 30*10=300 > than a byte can hold.
    Also better make the multiplication outside the comparison.

    Use the LCD as a monitor to check your values.

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

    Ioannis

  12. #12


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Here is the code. Look at the comments, and modify the RAW number to number when the display show 30.0degC.
    Code:
    define osc 4
    adcon1.7=1
    ANSEL = %000001 'Disable Inputs Tranne AN0
    ADCON1 = %10001110 
    OSCCON = %01100000 'Internal RC set to 4MHZ
    TRISA =  %00000001 ' impostazioni INP/OUT
    TRISB =  %00000000 ' delle porte
    '----------------------------------------------------
    DEFINE LCD_DREG PORTB       'Porta B DATA OUT 
    DEFINE LCD_DBIT 4           '0 --> Bit 0-3 : 4 --> Bit 4-7 
    DEFINE LCD_RSREG PORTB      'LCD register select port - Porta B --> RS
    DEFINE LCD_RSBIT 2          'LCD register select bit  - Pin RS B2
    DEFINE LCD_EREG PORTB       'LCD enable port - Porta B --> EN
    DEFINE LCD_EBIT 3           'LCD enable bit - Pin EN B3DEFINE LCD_BITS 4           'LCD bus size 4 or 8 
    DEFINE LCD_LINES 2          'Number lines on LCD DEFINE LCD_COMMANDUS 2000   'Command delay time in us 
    DEFINE LCD_DATAUS 50        'Data delay time in us
    
    Rele   VAR    PORTA.6     '                  Pin 15
    '--------------------------------------------------------------
    '---------Define ADCin Parameters   
    DEFINE ADC_BITS 10      'set number of bits in result
    DEFINE ADC_CLOCK 3      'set clock source (3=rc)
    DEFINE ADC_SAMPLEUS 50  'Set sampling time in uS
    
    
    '    RAM Assignments and Variables
    '=========================================================================== 
    temp var word
    temperature var word
    samples var word
    sample VAR BYTE
    quanta con 1250
    Tmax VAR byte
    Tmin VAR byte
    '===========================================================================
    Tmin=16
    Tmax=30
     
    START:
    Lcdout $FE, 1
    
    low rele
    
    main:   
    sample = 1
    samples= 0
    FOR sample = 1 TO 20 'Take 20 samples
    ADCIN 0, temp 'Read AN0 into temp variable
    samples = samples + temp
    PAUSE 50 ' Wait 1/4 seconds per reading
    NEXT sample
    temp = samples/20 'Average over 20 samples (Every 5 seconds)
    temperature= temp */ quanta
    
    if temp > 675 then high rele  'Instead 675 write the correct RAW number for 30degC 
    if temp < 675 then low rele   'Instead 675 write the correct RAW number for 30degC 
    
    LCDOUT $FE, 2 ' ritorna al primo carattere
    lcdout $FE, 2, "Temp ",dec2 (temperature/10),".", dec1 (temperature/10),"C"
    'lcdout $FE, $C0, "Tmin ",#Tmin, " Tmax ",#Tmax            FOR NORMAL OPERATION UNCOMMENT LINE 
    lcdout $FE, $C0, "RAW:",dec temp 'this show the ADC value  FOR NORMAL OPERATION COMMENT OR DELETE THIS LINE
    
    'When the display show 30,0 degC look at the RAW number on LCD and rewrite it in lines: if temp > 675 then high rele
    'and if temp < 675 then low rele . 
    
    goto main

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


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    not sure whats going on here

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

    an adc read of 675 would need 329 deg
    Warning I'm not a teacher

  14. #14


    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

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

  16. #16


    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

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

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