Thermo 7 segments - little problem


Closed Thread
Results 1 to 40 of 50

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    Thanks for reply !
    So ... using as hardware - 16F628A @ 4 MHz and LED display KW4-311AVA, I built one termometer, using DS18B20, with different variants of software (presented in this topic). All my variants have this issue - display flickering, more or less, but present.
    The hardware from the link posted above use same hardware, 16F628 @ 4 Mhz and same display. BUT ... no flickering ! The display look sharp and bright.
    So ... I intend to build an termometer, using same hardware, but flicker-free ! And, despite searching this forum, I could not find any convenient version to apply.
    This is why I asked for help ! Thanks in advance !

  2. #2
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    Tried a "variation" of code from post #20 :
    Code:
    ;                        Termo LED 7 seg 
    '======================================================================================
    
    @ DEVICE pic16F628A, intOSC_osc_noclkout, WDT_OFF, PWRT_ON, MCLR_OFF, LVP_OFF, CPD_OFF
    
    
    INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
    
    DEFINE OSC 4
    CMCON	= 7
    VRCON 	= 0
    INTCON 	= 0
    
                                    
        Common_4   	VAR PORTA.1
        Common_3   	VAR PORTA.0
        Common_2   	VAR PORTA.7
        Common_1   	VAR PORTA.6   
        DQ            VAR PORTA.4
        DP            VAR PORTB.2
    
    Temp   	    Var     Byte
    Temperature     Var     Word
    TempC           Var     Word
    I               Var     Byte
    Sign            Var     Word
    Float           Var     Word
    V		    Var     Word		   
    Dummy           Var     Byte
    Busy		    Var     Bit
        DIGIT_0     VAR 	BYTE
        DIGIT_1     VAR 	BYTE
        DIGIT_2     VAR 	BYTE
        DIGIT_3     VAR 	BYTE
    digit		    Var 	BYTE
    
    DS18B20_12bit 	CON %01111111        	' 750ms,   0.0625°C 
    
    
    
    Data @0,20,215,76,69,135,37,36,87,4,5,255
    
    
    PortA=%00000100
    TrisA=%00111000
    PortB=%11111111
    TrisB=%00000000
    
    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
        INT_Handler TMR1_INT, _DISP, PBP, yes
      endm
      INT_CREATE ; Creates the interrupt processor
    ENDASM
    
    @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
    T1CON = $1 
    
    ' Init Sensor 1
     OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_12bit]
     OWOut DQ, 1, [$CC, $48]                   ' Start temperature conversion
     OWOut DQ, 1, [$CC, $B8] 
     OWOut DQ, 1, [$CC, $BE] 
     Pause 50
     OWIn DQ, 2, [temperature.byte0, temperature.byte1]
    
    Main:
    ' Start temp.conv.Sensor1
     OWOut DQ, 1, [$CC, $44] 
     OWOut DQ, 1, [$CC, $BE]
     OWIn DQ, 2, [temperature.byte0, temperature.byte1]  
    
    If Temperature.15 then       
      Temperature= ~Temperature +1
      Sign  = 1
    Endif
     
    Dummy = 625 * Temperature
    TempC = DIV32 10 
    TempC = (Temperature & $7FF) >> 4
    Float = ((Temperature.Lowbyte & $0F ) * 25 )>>2
    Temperature = TempC*100 + Float
    
    If Sign=1 then
      V= 10000 - Temperature            
    else
      V= 10000 + Temperature
    EndIf
    
    If V >= 10000 then                  
      Temperature=V-10000
      sign = " "                   
    else                                   
      Temperature=10000-V                 
      sign = "-"
    EndIf
    
    Temperature=Temperature/10
    
    Gosub Selectie
    
    Goto Main
    
    '======================================================================================
    Selectie :
    
    If sign = "-" then
    PortB = %11101111					
    else 
    PortB = %11111111					
    endif
    
    IF Temperature DIG 2 = 0 THEN
    digit = " "
        else
    digit = Temperature dig 2
    ENDIF
        read digit, DIGIT_2
    
    digit = Temperature dig 1
        read digit, DIGIT_1
        
    digit = Temperature dig 0
        read digit, DIGIT_0
    Return    
    '====================================================================================== 
    Disp:
      T1CON.0 = 0                ; stop timer
      TMR1H = %11111100
      TMR1L = %00011111
      T1CON.0 = 1                ; restart timer
    
    Common_1 = 1 : PAUSE 1 : Common_1 = 0	
          
    PortB = DIGIT_2
    Common_2 = 1 : PAUSE 1 : Common_2 = 0
    
    PortB = DIGIT_1
    Common_3 = 1 : DP = 0 : PAUSE 1 : Common_3 = 0 : DP = 1
    
    PortB = DIGIT_0
    Common_4 = 1 : PAUSE 1 : Common_4 = 0
    
    @ INT_RETURN
    ...but I have some errors :

    ERROR Line 95: Syntax error. (ReEnterPBP.bas)
    ERROR Line 128: Redefiniton of LABEL Vars_Saved. (ReEnterPBP.bas)
    ERROR Line 128: Syntax error. (ReEnterPBP.bas)
    Advices ?! Thanks !

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    DT_INTS only works with the MPASM assembler.
    Your device statement indicates you are trying to use the old PM assembler.

    But I can say that 1-Wire and ASM Interrupts don't get along very well.
    1-Wire has very strict timing requirements. And ASM Interrupts have a tendancy to disturb that timing.

    1-Wire commands take enough time that if you stop the interrupts to do a software OWOUT/IN ... it will cause blinking.

    The only way I can see to scan LED's at a constant rate, and do 1-Wire I/O at the same time ... is to do the 1-Wire communications by Interrupts too.
    Sorry, don't have sample code.
    DT

  4. #4
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    Ok, I understand ...Thank You so much for advice ! I will try to figure out how doing 1-Wire by interrupts ...Regards !

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    There's an example of reading the DS18B20 without using OWOUT/IN here ...
    http://support.melabs.com/content/389-TEMPX.pbp

    It doesn't use timer interrupts. It uses pauses instead.
    But it should give a good idea on how to read the sensor.
    DT

  6. #6
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    Many thanks ! Now I wait for account validation ... for see the example. Thanks again !

  7. #7
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Thermo 7 segments - little problem

    I'm stuck ...at red lines bellow ...
    Code:
    ;                        Termo 7 seg
    '======================================================================================
    
    @ DEVICE pic16F628A, intOSC_osc_noclkout, WDT_OFF, PWRT_ON, MCLR_OFF, LVP_OFF, CPD_OFF
    
    DEFINE OSC 4
    CMCON	= 7
    VRCON 	= 0
    INTCON 	= 0
    
                                    
        Common_4   	VAR PORTA.0
        Common_3   	VAR PORTA.1
        Common_2   	VAR PORTA.2
        Common_1   	VAR PORTA.3  
        DP            VAR PORTB.7
    
    Temp   	    Var     byte
    Temperature     Var     Word
    TempC           Var     Word
    I               Var     Byte
    Sign            Var     Word
    Float           Var     Word
    V		    Var     Word		   
    Dummy           Var     Byte
    Busy		    Var     Bit
        DIGIT_0     VAR 	BYTE
        DIGIT_1     VAR 	BYTE
        DIGIT_2     VAR 	BYTE
        DIGIT_3     VAR 	BYTE
    digit		    Var 	BYTE
    
    
    DQ VAR PORTA.4
    DQ_DIR var TRISA.4
    command var byte
    pis   var byte
    
    	TrisB=0					' Make PortB outputs
    	TrisA.0=0:TrisA.1=0:TrisA.2=0		' Make only the specific bits of PortA outputs					
    	TrisA.3=0:TrisA.4=1
    	PortA=0:PortB=0			     	' Clear PortB and PortA
    
    INTCON = %00100000
    OPTION_REG = %10000000
    ON INTERRUPT GOTO ISR
    INTCON = %10100000
    
        
    '======================================================================================
     
       Gosub init1820      ' Init the DS1820
       command = $cc       ' Issue Skip ROM command
       Gosub write1820
    
       command = $44       ' Start temperature conversion
       Gosub write1820
       Pause 2000          ' Wait 2 seconds for conversion to complete
       Gosub init1820      ' Do another init
    
       command = $cc       ' Issue Skip ROM command
       Gosub write1820
    
    MAIN :
       command = $be       ' Read the temperature
       Gosub write1820
       Gosub read1820
    
    temperature = ??????
    sign = ????
    
    Gosub Selectie
    Goto Main
    
    '======================================================================================
    Selectie :
    IF sign ="-" then					
        DIGIT_3="-"
        else
        DIGIT_3=" "
    ENDIF
     
    IF TEMPERATURE DIG 2 = 0 THEN
        DIGIT_2 = " "
        ELSE
        DIGIT_2 = TEMPERATURE dig 2
    ENDIF
    
        DIGIT_1 = TEMPERATURE dig 1
        DIGIT_0 = TEMPERATURE dig 0
    
    RETURN
    
    '====================================================================================== 
    DISABLE
    ISR:   
     
    for i=0 to 4
        TEMP = DIGIT_3 : gosub segments
        COMMON_1 = 1 : PAUSE 1 : COMMON_1 = 0
    
         
        TEMP = DIGIT_2 : GOSUB segments
        COMMON_2 = 1 : PAUSE 1 : COMMON_2 = 0
       
        TEMP = DIGIT_1 : GOSUB segments
        COMMON_3 = 1 : DP = 0 : PAUSE 1 : COMMON_3 = 0 : DP = 1
      
        TEMP = DIGIT_0 : GOSUB segments
        COMMON_4 = 1 : PAUSE 1 : COMMON_4 = 0
    next i
    
    segments:  ; CONVERTS DATES TO 7 SEGMENT CODE for Common ANOD
        
        SELECT CASE TEMP       
    CASE 0 	 : PortB=%11000000 ; 0=ON ; 1=OFF
    CASE 1 	 : PortB=%11111001
    CASE 2 	 : PortB=%10100100      
    CASE 3 	 : PortB=%10110000        
    CASE 4 	 : PortB=%10011001
    CASE 5 	 : PortB=%10010010        
    CASE 6 	 : PortB=%10000010
    CASE 7 	 : PortB=%11111000        
    CASE 8 	 : PortB=%10000000       
    CASE 9 	 : PortB=%10010000        
    CASE "-"     : PortB=%10111111               
    CASE " "     : PortB=%11111111        
        END SELECT 
    return
    
    INTCON.2=0
    RESUME
    ENABLE
    '====================================================================================== 
    ' Initialize DS1820 and check for presence
    init1820:
       Low DQ              ' Set the data pin low to init
       Pauseus 500         ' Wait > 480us
       DQ_DIR = 1          ' Release data pin (set to input for high)
    
       Pauseus 100         ' Wait > 60us
       If DQ = 1 Then
          Pause 500
          Goto main        ' Try again
       Endif
       Pauseus 400         ' Wait for end of presence pulse
       Return
    
    ' Write "command" byte to the DS1820
    write1820:
       For pis = 1 To 8      ' 8 bits to a byte
         If command.0 = 0 Then
            Gosub write0   ' Write a 0 bit
         Else
            Gosub write1   ' Write a 1 bit
         Endif
         command = command >> 1  ' Shift to next bit
       Next pis
       Return
    
    ' Write a 0 bit to the DS1820
    write0:
       Low DQ
       Pauseus 60          ' Low for > 60us for 0
       DQ_DIR = 1          ' Release data pin (set to input for high)
       Return
    
    ' Write a 1 bit to the DS1820
    write1:
       Low DQ              ' Low for < 15us for 1
     @ nop                 ' Delay 1us at 4MHz
       DQ_DIR = 1          ' Release data pin (set to input for high)
       Pauseus 60          ' Use up rest of time slot
       Return
    
    ' Read temperature from the DS1820
    read1820:
       For pis = 1 To 16     ' 16 bits to a word
         temperature = temperature >> 1  ' Shift down bits
         Gosub readbit     ' Get the bit to the top of temp
       Next pis
       Return
    
    ' Read a bit from the DS1820
    readbit:
       temperature.15 = 1         ' Preset read bit to 1
       Low DQ              ' Start the time slot
     @ nop                 ' Delay 1us at 4MHz
       DQ_DIR = 1          ' Release data pin (set to input for high)
       If DQ = 0 Then
          temperature.15 = 0      ' Set bit to 0
       Endif
       Pauseus 60          ' Wait out rest of time slot
       Return    
    
    end
    I have no ideea how to find the value of temperature ...

Similar Threads

  1. Windows 7 64 bit problem..can anyone help???
    By ljc4141 in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 18th July 2011, 16:29
  2. LED Machine Tach For Tired Eyes
    By Archangel in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 27th January 2010, 15:55
  3. adding with 7 segments
    By ruijc in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 28th November 2007, 23:51
  4. 7 segments clock
    By the_apprentice in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th April 2006, 19:45
  5. 7 segment digit problem (using Mister E's code)
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th September 2005, 21:25

Members who have read this thread : 0

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