Temperature Controller Problem


+ Reply to Thread
Page 1 of 8 123 ... LastLast
Results 1 to 10 of 72

Thread: Temperature Controller Problem141 days old

  1. #1
    Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    119
    Thumbs Up
    Received: 38
    Given: 5
    Total Downloaded
    10.35 MB

    0 Not allowed!

    Default Temperature Controller Problem

    hi,
    i had made a digital temperature controller with "j" type thermocouple .Every thing is working fine except Thermocouple break option.I want when thermocouple break or open then display on seven segment should display "tcbr".i have written " If value >800 Then GoSub TCB" but it is not working.Please guide.

    my code:




    ;-------------------------------------------------------------------------------
    ;**** Added by Fuse Configurator ****
    ; Use the Fuse Configurator plug-in to change these settings


    Device = 16F886


    Config1 FOSC_INTRC_NOCLKOUT, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, CPD_OFF, BOREN_OFF, IESO_OFF, FCMEN_OFF, LVP_OFF, DEBUG_OFF
    Config2 BOR4V_BOR40V, WRT_OFF


    ;**** End of Fuse Configurator Settings ****
    ;-------------------------------------------------------------------------------








    Xtal 4
    OSCCON=%01110001
    'All_Digital On




    Dim DG1 As Byte
    Dim DG2 As Byte
    Dim DG3 As Byte
    Dim DG4 As Byte
    Dim DIGIT As Byte
    Dim DG As Byte
    Dim COUNTT As Byte
    Dim i As Byte
    Dim J As Byte
    Dim NUMB As Word
    Dim N As Float
    Dim ADVAL As Float
    Dim temp As Word
    Dim TEMPP As Word
    Dim RESULT1 As Float
    Dim o As Byte
    Dim value As Float
    Dim AD As Word
    Dim II As Byte


    ADCON1=%10000000
    ADCON0=%01000011
    TRISA=%00111101
    TRISB=%00000000
    TRISC=%11110000
    ANSELH=%00000001
    ANSEL=%00000001
    CM1CON0=0
    CM2CON0=0
    VRCON=0





    'driven seven segment for start up disply "ver.1"
    For i=0 To 999
    '
    DG=$C7

    PORTB=DG
    PORTC.3=0
    DelayUS 5000
    PORTC.3=1

    DG=$61

    PORTB=DG
    PORTC.2=0
    DelayUS 5000
    PORTC.2=1

    DG=$F4


    PORTB=DG
    PORTC.1=0
    DelayUS 5000
    PORTC.1=1

    DG=$9F

    PORTB=DG
    PORTC.0=0
    DelayUS 5000
    PORTC.0=1



    Next i





    GoSub MREAD
    GoSub DIGITCALC





    N=NUMB




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

    MAIN1:

    GoSub DISPLAY

    If PORTA.2=0 Then MREAD 'read eeprom

    If PORTA.2=1 Then MAIN

    MAIN:
    RESULT1 = ADIn 0
    value=value-(value/2) 'average
    value=value+(RESULT1/2) 'average

    N=value
    GoSub DISPLAY
    GoSub DIGITCALC

    If value > NUMB Then PORTA.6=0 'relay off
    If value < NUMB-1 Then PORTA.6=1 'relay on

    'thermocouple break
    If value >800 Then GoSub TCB
    GoTo MAIN1







    'set point for temperature cutoff higher side


    UP:
    If NUMB=400 Then MAIN 'maximum limit
    NUMB=NUMB+1
    N=NUMB
    GoSub DISPLAY
    GoSub DIGITCALC
    If PORTA.3=0 Then memory
    GoTo MAIN1


    memory:
    EWrite 00,[NUMB]

    GoTo MAIN1




    DOWN:
    If NUMB=0 Then MAIN 'minumum limit
    NUMB=NUMB-1
    N=NUMB
    GoSub DISPLAY
    GoSub DIGITCALC
    If PORTA.4=0 Then memory
    GoTo MAIN1




    MREAD:
    NUMB = ERead 00

    N=NUMB
    GoSub DISPLAY
    GoSub DIGITCALC

    If PORTA.3=0 Then UP

    If PORTA.4=0 Then DOWN

    GoTo MAIN1


    'thermocouple break display "tcbr"
    TCB:
    For o=1 To 999

    DG=$E1
    PORTB=DG
    PORTC.3=0
    DelayUS 3000
    PORTC.3=1

    DG=$E5
    PORTB=DG
    PORTC.2=0
    DelayUS 3000
    PORTC.2=1

    DG=$C1
    PORTB=DG
    PORTC.1=0
    DelayUS 3000
    PORTC.1=1

    DG=$F5
    PORTB=DG
    PORTC.0=0
    DelayUS 3000
    PORTC.0=1



    Next o




    'light up four digit seven segment display
    DISPLAY:


    For COUNTT=0 To 99


    PORTB=DG1
    PORTC.3=0
    DelayUS 100
    PORTC.3=1


    PORTB=DG2
    PORTC.2=0
    DelayUS 100
    PORTC.2=1


    PORTB=DG3
    PORTC.1=0
    DelayUS 100
    PORTC.1=1

    PORTB=DG4
    PORTC.0=0
    DelayUS 100
    PORTC.0=1


    Next COUNTT


    Return


    '_________________________________________________ _______________






    'sending numbers to each digit
    DIGITCALC:


    DIGIT=0
    LP1:
    If N<1000 Then DS1
    N=N-1000
    DIGIT=DIGIT+1
    GoTo LP1
    DS1:
    GoSub FND
    DG1=DG



    DIGIT=0
    LP2:
    If N<100 Then DS2
    N=N-100
    DIGIT=DIGIT+1
    GoTo LP2


    DS2:
    GoSub FND
    DG2=DG


    DIGIT=0
    LP3:
    If N<10 Then DS3
    N=N-10
    DIGIT=DIGIT+1
    GoTo LP3


    DS3:
    GoSub FND
    DG3=DG


    DIGIT=N
    GoSub FND
    DG4=DG

    Return






    '_________________________________________________ _________________________




    'lighting up each segment of display according to numbers
    FND:


    FND0:
    If DIGIT>0 Then FND1
    DG=%00000011 '%0111 1110
    GoTo FNDEND


    FND1:
    If DIGIT>1 Then FND2
    DG=%10011111 '%0100 1000
    GoTo FNDEND


    FND2:
    If DIGIT>2 Then FND3
    DG=%00100101 '%0011 1101
    GoTo FNDEND


    FND3:
    If DIGIT>3 Then FND4
    DG=%00001101 '%0110 1101
    GoTo FNDEND


    FND4:
    If DIGIT>4 Then FND5
    DG=%10011001 '%0100 0011
    GoTo FNDEND


    FND5:
    If DIGIT>5 Then FND6
    DG=%01001001 '%0110 0111
    GoTo FNDEND


    FND6:
    If DIGIT>6 Then FND7
    DG=%01000001 '%0111 0111
    GoTo FNDEND


    FND7:
    If DIGIT>7 Then FND8
    DG=%00011111 '%0100 1100
    GoTo FNDEND


    FND8:
    If DIGIT>8 Then FND9
    DG=%00000001 '%0111 1111
    GoTo FNDEND


    FND9:
    DG=%00011001 '%0110 1111


    FNDEND:








    Return
    '______________________________

  2. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Senior Member Stephen Moss's Avatar
    Join Date
    Jan 2006
    Posts
    490
    Thumbs Up
    Received: 29
    Given: 7
    Total Downloaded
    3.57 GB

    1 Not allowed!

    Default Re: Temperature Controller Problem

    I am not sure what you mean by thermocouple break, I assume you me a defined switching (i.e. on/off) point.

    I cannot see where your initially set the variable "value" to a number, consequently for...
    Code:
    value=value-(value/2) 'average
    value=value+(RESULT1/2) 'average
    At best the first value is completely random, at worst you could get a divide by 0 error if value is initially 0 which may be causing problems.

    Another problem could be your calculation, your comment indicates you are trying to derive an average value, to do so you have to take several samples, add them together and then divide by the number of samples.
    value = value - (value/2) does not do that...
    If the initial number of your value variable was 100 then your average should be 100 (100/1), however the first line of your code would reduce that to 50,
    If the value of RESULT1/2 was then 80 the average on the next loop through for the first line of code should be equal to (100+80)/2 = 90 but your calculation would be equal to (50+80)/2 = 60. This could be why you never reach a value large enough to trigger your "break" point.
    If you comment out those two line and add...
    value = [enter your break point value here]
    that will at least allow you to test that your break point code is working.

  4. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    119
    Thumbs Up
    Received: 38
    Given: 5
    Total Downloaded
    10.35 MB

    0 Not allowed!

    Default Re: Temperature Controller Problem

    How can I average ADC value.

  6. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Administrator John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,749
    Thumbs Up
    Received: 77
    Given: 33
    Total Downloaded
    4.30 GB

    0 Not allowed!

    Default Re: Temperature Controller Problem

    As described previously you can either
    1) sample say 10 times each input from the A/D then assign a Word variable such as Value =0. Then Value = Value + NewAD for 10 samples then divide by 10.
    Value would need to be a word variable. The number of samples must be less than 64 or your word variable may overflow.

    2) Alternatively download the latest copy of the compiler and use the new Median Filter include file. You need the Procedures upgrade to use the include.
    John

  8. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Prolific Poster RGV250's Avatar
    Join Date
    Aug 2005
    Posts
    2,305
    Thumbs Up
    Received: 28
    Given: 7
    Total Downloaded
    801.38 MB

    0 Not allowed!

    Default Re: Temperature Controller Problem

    Hi,
    I am assuming you are looking for a wire break situation, I don't normally use analog inputs so I am not sure how they respond but I would expect the value to be zero without an input so where does the value of 800 come from?, should you not be looking for zero?

    Also on a side not, I found the code quite difficult to follow as there are a lack of comments and you seem to be using a lot of GoTo instructions that jump back and are probably not required.
    One example is If PORTA.2=0 Then MREAD 'read eeprom, this jumps to MREAD which then either jumps to UP, DOWN or memory which are are above it and then jumps back MAIN or MAIN1.

    Regards the comments, when you come back to it in 6 months or a year to modify it you will wish you had put more detail in it, it also helps us if to work out what you are trying to do.

    Where you split the value into individual digits for the display, have you tried Dig which extracts values.
    This is what I used for a revcounter.

    'Split the value into individual numbers for the display
    RPM_THOUSANDS = Dig RPM_INT,3
    RPM_HUNDREDS = Dig RPM_INT,2
    RPM_TENS = Dig RPM_INT,1
    RPM_UNITS = Dig RPM_INT,0

    Regards,
    Bob
    Last edited by RGV250; 27th May 2019 at 11:55.

  10. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    119
    Thumbs Up
    Received: 38
    Given: 5
    Total Downloaded
    10.35 MB

    0 Not allowed!

    Default Re: Temperature Controller Problem

    As I can see that my display code for driving four digit seven segment display is very lengthy.Please send me a code for driving four digit common anode seven segment display.
    Thanks

  12. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Prolific Poster RGV250's Avatar
    Join Date
    Aug 2005
    Posts
    2,305
    Thumbs Up
    Received: 28
    Given: 7
    Total Downloaded
    801.38 MB

    0 Not allowed!

    Default Re: Temperature Controller Problem

    Hi,
    I think the snippet I posted
    Code:
    'Split the value into individual numbers for the display 
            RPM_THOUSANDS = Dig RPM_INT,3
            RPM_HUNDREDS = Dig RPM_INT,2
            RPM_TENS = Dig RPM_INT,1
            RPM_UNITS = Dig RPM_INT,0
    will replace this.
    Code:
    DIGIT=0
    LP1:
    If N<1000 Then DS1
    N=N-1000
    DIGIT=DIGIT+1
    GoTo LP1
            DS1:
            GoSub FND
            DG1=DG
           
    
    
    DIGIT=0
    LP2:
    If N<100 Then DS2
    N=N-100
    DIGIT=DIGIT+1
    GoTo LP2
    
    
            DS2:
            GoSub FND
            DG2=DG
            
            
    DIGIT=0
    LP3:
    If N<10 Then DS3
    N=N-10
    DIGIT=DIGIT+1
    GoTo LP3
    
    
            DS3:
            GoSub FND
            DG3=DG
    
    
    DIGIT=N
    GoSub FND
    DG4=DG
     
    Have a look here for driving the display, I have not looked but it might help http://www.protonbasic.co.uk/content...gment-displays

    Regards,
    Bob
    Last edited by RGV250; 27th May 2019 at 15:39.

  14. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  15. #8
    Member flosigud's Avatar
    Join Date
    Oct 2013
    Posts
    100
    Thumbs Up
    Received: 6
    Given: 11
    Total Downloaded
    2.57 GB

    0 Not allowed!

    Default Re: Temperature Controller Problem

    Many years ago Les posted several examples of seven segment led drivers. The post is still there but the files are missing. Someone might still have them.
    Flosi Guğmundsson
    Reykjavík

  16. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  17. #9
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,333
    Thumbs Up
    Received: 289
    Given: 138
    Total Downloaded
    1.60 GB

    0 Not allowed!

    Default Re: Temperature Controller Problem

    Here's a program I wrote that uses a PIC16F886 device and a common anode 7-segment x4 display.

    It uses a Timer0 interrupt to drive the seven segment display and the procedure that extracts the seperate digits from a value also zero supresses the final numeric display output.

    The program is a pulse counter, which is essentially a slow frequency counter, but you can take out the bits of the code you don't want and wrap your code around the routines that control the 7-segment displays. i.e. The interrupt handler and the Build_Displays() procedure. It is fully working and has been used on a few projects so it is good to go. As you can see, the code is highly, but cleanly, commented that makes the code easier to follow and understand. It's just the dreadful code window of the forum that makes it look a bit of a mess here. Once copied and pasted into the IDE it will become clean and line up again.

    Code:
    '
    '   /\\\\\\\\\
    '  /\\\///////\\\
    '  \/\\\     \/\\\                                                 /\\\          /\\\
    '   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
    '    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
    '     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
    '      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
    '       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
    '        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
    '                                  Let's find out together what makes a PIC Tick!
    '
    ' A simple pulse counter and outputted on a 7 segment display
    ' For use with a Common Anode display
    '
    ' Written by Les Johnson for the Proton BASIC Compiler
    '
    Declare Hints = Off
    
        Device = 16F886                             ' Use a standard 14-bit core device
        Declare Xtal = 20                           ' Use a 20MHz crystal
        Declare Optimiser_Level = 1                 ' Increase optimisation
    
        On_Hardware_Interrupt GoTo ISR_Handler      ' Point to the interrupt handler
    
        Dim bOnes       As Byte                    ' The value for the 1st right LED display
        Dim bTens       As Byte                    ' The value for the 2nd right LED display
        Dim bHundreds   As Byte                    ' The value for the 3rd right LED display
        Dim bThousands  As Byte                    ' The value for the 4th right LED display
        Dim bTimeShare  As Byte                    ' Used by the interrupt for time sharing
        Dim wPulseCount As Word                    ' The amount of pulses detected
    '
    ' Setup the pins used
    '
    $define Segment_Pins PORTC                      ' Sets the segments of each display
    $define Display1_Pin PORTB.1                    ' Enables or disables display 1
    $define Display2_Pin PORTB.2                    ' Enables or disables display 2
    $define Display3_Pin PORTB.3                    ' Enables or disables display 3
    $define Display4_Pin PORTB.4                    ' Enables or disables display 4
    $define Signal_Pin   PORTB.0                    ' The pulse is placed onto the INT pin
    '
    ' Individual segment values for a Common Anode 7 segment display (inverted compared to Common Cathode values)
    '
    $define Segment_A $FE                           ' The value (bin 11111110) to send to illuminate segment A on the Common Anode display
    $define Segment_B $FD                           ' The value (bin 11111101) to send to illuminate segment B on the Common Anode display
    $define Segment_C $FB                           ' The value (bin 11111011) to send to illuminate segment C on the Common Anode display
    $define Segment_D $F7                           ' The value (bin 11110111) to send to illuminate segment D on the Common Anode display
    $define Segment_E $EF                           ' The value (bin 11101111) to send to illuminate segment E on the Common Anode display
    $define Segment_F $DF                           ' The value (bin 11011111) to send to illuminate segment F on the Common Anode display
    $define Segment_G $BF                           ' The value (bin 10111111) to send to illuminate segment G on the Common Anode display
    '
    ' An LED display is formatted like this:
    '     A
    '   ------
    '   |    |
    '  F|    |B
    '   | G  |
    '   ------
    '   |    |
    '  E|    |C
    '   | D  |
    '   ------
    '
    ' So each segment has a letter associated with it, that is controlled by one of its pins.
    '
    ' Seven Segment data Anded together to give values for the Common Anode digits
    '
        Dim SevenSeg_Data As Code = Segment_A & Segment_B & Segment_C & Segment_D & Segment_E & Segment_F,_     ' The segments to illuminate a digit 0
                                    Segment_B & Segment_C,_                                                     ' The segments to illuminate a digit 1
                                    Segment_A & Segment_B & Segment_D & Segment_E & Segment_G,_                 ' The segments to illuminate a digit 2
                                    Segment_A & Segment_B & Segment_C & Segment_D & Segment_G,_                 ' The segments to illuminate a digit 3
                                    Segment_B & Segment_C & Segment_F & Segment_G,_                             ' The segments to illuminate a digit 4
                                    Segment_A & Segment_C & Segment_D & Segment_F & Segment_G,_                 ' The segments to illuminate a digit 5
                                    Segment_C & Segment_D & Segment_E & Segment_F & Segment_G,_                 ' The segments to illuminate a digit 6
                                    Segment_A & Segment_B & Segment_C,_                                         ' The segments to illuminate a digit 7
                                    Segment_A & Segment_B & Segment_C & Segment_D & Segment_E & Segment_F & Segment_G,_ ' The segments to illuminate a digit 8
                                    Segment_A & Segment_B & Segment_C & Segment_D & Segment_F & Segment_G       ' The segments to illuminate a digit 9
    '
    ' Timer 0 prescaler values
    '
    $define Prescaler_2   0
    $define Prescaler_4   1
    $define Prescaler_8   2
    $define Prescaler_16  3
    $define Prescaler_32  4
    $define Prescaler_64  5
    $define Prescaler_128 6
    $define Prescaler_256 7
    
    '---------------------------------------------------------------------------------------
        GoTo Main                                       ' Jump to the main program
    
    '---------------------------------------------------------------------------------------
    ' Adjust the prescaler for Timer0
    ' Input     : pValue holds the prescaler rate
    '           :   000 = 1:2
    '           :   001 = 1:4
    '           :   010 = 1:8
    '           :   011 = 1:16
    '           :   100 = 1:32
    '           :   101 = 1:64
    '           :   110 = 1:128
    '           :   111 = 1:256
    ' Output    : None
    ' Notes     : None
    '
    $define OPTION_REGbits_PS(pValue) '
        OPTION_REG = OPTION_REG & $F8 '
        OPTION_REG = OPTION_REG | pValue
    
    '---------------------------------------------------------------------------------------
    ' Interrupt Handler
    ' Multiplexes the 7-segment displays
    ' Increments wPulseCount when a low to high signal is detected on the INT pin
    '
    ISR_Handler:
        Context Save
    
        If INTCONbits_INTF = 1 Then                     ' Is it an INT that has triggered the interrupt?
            Inc wPulseCount                             ' Yes. So increment the wPulseCount variable
            Clear INTCONbits_INTF                       ' Reset the INT interrupt flag
        EndIf
    
        If INTCONbits_T0IF = 1 Then                     ' Is it a Timer0 overflow that has triggered the interrupt?
            If bTimeShare = 0 Then                      ' Yes. So is it Display 1's turn?
                Clear Display4_Pin                      ' Yes. So turn Off the fourth LED
                Segment_Pins = bOnes                    ' Place the digit pattern on the LED's segments
                Set Display1_Pin                        ' Turn on the first LED
    
            ElseIf bTimeShare = 1 Then                  ' Is it Display 2's turn?
                Clear Display1_Pin                      ' Yes. So turn Off the first LED
                Segment_Pins = bTens                    ' Place the digit pattern on the LED's segments
                Set Display2_Pin                        ' Turn on the second LED
    
            ElseIf bTimeShare = 2 Then                  ' Is it Display 3's turn?
                Clear Display2_Pin                      ' Yes. So turn Off the second LED
                Segment_Pins = bHundreds                ' Place the digit pattern on the LED's segments
                Set Display3_Pin                        ' Turn on the third LED
    
            ElseIf bTimeShare = 3 Then                  ' Is it Display 4's turn?
                Clear Display3_Pin                      ' Yes. So turn Off the third LED
                Segment_Pins = bThousands               ' Place the digit pattern on the LED's segments
                Set Display4_Pin                        ' Turn on the fourth LED
            EndIf
    
            Inc bTimeShare                              ' Increment the time share counter
            If bTimeShare = 4 Then Clear bTimeShare     ' If it reaches 4 then clear it
            Clear INTCONbits_T0IF                       ' Reset the Timer0 interrupt flag
        EndIf
        Context Restore
    
    '---------------------------------------------------------------------------------------
    ' Build up the seperate digits of a variable
    ' Input     : pValue holds the value to display
    ' Output    : None
    ' Notes     : Zero suppression is implemented
    '
    Proc Build_Displays(pValue As Word)
    
        Dim bDigitValue As Byte
        
        bDigitValue = Dig pValue, 0                             ' Extract the first digit from pValue
        bOnes = CRead8 SevenSeg_Data[bDigitValue]               ' Read the data for the first digit of the value to display
        If pValue < 10 Then                                     ' Is the value to display less than 10?
            bTens = $FF                                         ' Yes. So blank the Tens Display
        Else                                                    ' Otherwise...
            bDigitValue = Dig pValue, 1                         ' Extract the second digit from pValue
            bTens = CRead8 SevenSeg_Data[bDigitValue]           ' Read the data for the second digit of the value to display
        EndIf
        
        If pValue < 100 Then                                    ' Is the value to display less than 100?
            bHundreds = $FF                                     ' Yes. So blank the Hundreds Display
        Else                                                    ' Otherwise...
            bDigitValue = Dig pValue, 2                         ' Extract the third digit from pValue
            bHundreds = CRead8 SevenSeg_Data[bDigitValue]       ' Read the data for the third digit of the value to display
        EndIf
        
        If pValue < 1000 Then                                   ' Is the value to display less than 1000?
            bThousands = $FF                                    ' Yes. So blank the Thousands Display
        Else                                                    ' Otherwise...
            bDigitValue = Dig pValue, 3                         ' Extract the fourth digit from pValue
            bThousands = CRead8 SevenSeg_Data[bDigitValue]      ' Read the data for the fourth digit of the value to display
        EndIf
    EndProc
    
    '---------------------------------------------------------------------------------------
    ' Setup the variables and peripherals
    ' Input     : None
    ' Output    : None
    ' Notes     : None
    '
    Proc Setup()
        Low Segment_Pins                    ' Clear all the 7 segment LED's segments
        Low Display1_Pin                    ' Disable the first display
        Low Display2_Pin                    ' Disable the second display
        Low Display3_Pin                    ' Disable the third display
        Low Display4_Pin                    ' Disable the fourth display
        Input Signal_Pin                    ' Make the INT pin an input
    
        bOnes = $FF                         ' Clear the bOnes variable (inverted because of Common Anode display)
        bTens = $FF                         ' Clear the bTens variable (inverted because of Common Anode display)
        bHundreds = $FF                     ' Clear the bHundreds variable (inverted because of Common Anode display)
        bThousands = $FF                    ' Clear the bThousands variable (inverted because of Common Anode display)
    
        Clear bTimeShare                    ' Clear the display time share variable
        Clear wPulseCount                   ' Clear the pulse counter variable
    '
    ' Setup Timer0 to interrupt on rollover
    '
        OPTION_REG = 128                    ' Disable the pullup resistors on the LEDs segments
        OPTION_REGbits_PS(Prescaler_32)     ' Set the prescaler for Timer0 to give a 625HZ refresh rate
        Clear TMR0                          ' Clear Timer0
        INTCONbits_T0IE = 1                 ' Enable a Timer0 overflow
    '
    ' Setup an INT interrupt
    '
        OPTION_REGbits_INTEDG = 1           ' Set for rising edge on pin INT
        INTCONbits_INTE = 1                 ' Enable an INT interrupt
    
        INTCONbits_GIE = 1                  ' Enable global interrupts
    EndProc
    
    '---------------------------------------------------------------------------------------
    ' The main program loop starts here
    ' Count the pulses per second and display them on a seven segment display
    '
    Main:
    
        Setup()                             ' Setup the variables and the peripherals
    
        Do                                  ' Create a loop
            Clear wPulseCount               ' Clear the pulse counter before we start the interrupt
            Clear INTCONbits_INTF           ' Clear the INT flag before enabling the interrupt
            INTCONbits_INTE = 1             ' Enable the INT interrupt to count the pulses
            DelayMS 992                     ' Create a delay to measure within (Taking into account the interrupt running in the background)
            INTCONbits_INTE = 0             ' Disable the INT interrupt
            Build_Displays(wPulseCount)     ' Create the value to display on the 7 segment LEDs
        Loop                                ' Loop forever
    Here's a screenshot of the above program working in the Isis simulator.

    CA_LED_PulseCount.jpg
    Last edited by top204; 27th May 2019 at 22:29.

  18. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  19. #10
    Member flosigud's Avatar
    Join Date
    Oct 2013
    Posts
    100
    Thumbs Up
    Received: 6
    Given: 11
    Total Downloaded
    2.57 GB

    1 Not allowed!

    Default Re: Temperature Controller Problem

    I found the files I mentioned previously. A zip is attached.
    Attached Files Attached Files
    Flosi Guğmundsson
    Reykjavík

  20. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Temperature Sensor
    By chuckieboy in forum The Lounge
    Replies: 9
    Last Post: 26th May 2012, 06:17
  2. Replies: 4
    Last Post: 23rd September 2010, 13:33
  3. temperature sensor
    By chuckieboy in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 30th June 2010, 20:10
  4. [SOLVED !] Temperature Controller using PIC16F628A
    By bentech4u in forum Proton Plus Compiler v3
    Replies: 9
    Last Post: 29th October 2008, 17:39
  5. Operating temperature...
    By Hans Chr in forum The Lounge
    Replies: 3
    Last Post: 8th August 2006, 12:16

Posting Permissions

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