+ Post New Thread
Page 1 of 2 1 2 LastLast
Results 1 to 20 of 24
  1. #1
    Full Member level 4
    Points: 2,239, Level: 10
    Achievements:
    7 years registered

    Join Date
    Jan 2010
    Posts
    210
    Helped
    2 / 2
    Points
    2,239
    Level
    10

    16F877 thermometer problem

    hello Guys
    im reading an thermistor which im displaying the result on 2 7seg displays
    im facing a problem with the reading of it, when temp is change between 1-2 or any number the units display is flickering until it get the right number
    i think its something like the number after DP which i dont need
    wht to do ?
    im not sure if i could explain my problem
    my display routine is ok when i test it with any fixed number the 2 digits r ok
    but when it change from (for example 01 to 02) the right number flicker until it get stable

    how to ignore the unwanted values of my ADC ?

  2. #2
    Advanced Member level 4
    Points: 7,450, Level: 20
    Achievements:
    7 years registered
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    1,238
    Helped
    256 / 256
    Points
    7,450
    Level
    20

    Re: 16F877 thermometer problem

    hello,


    use a filter to smooth the result ..
    arithmetique glissant ou Exponentiel



    Code:
     ******  ARITHMETIQUE FILTER for   up to 8 analog input  ********************
    
    unsigned int Table[8];
    unsigned int Somme_EA[8];
    unisgned int M, EA0,Nbval,Somme;
    
    
    
           M=0;
           EA0=ADC_Read(M);
           Table_EA[M][Nbval & 0x0007]=EA0;
           Nbval++;
           Somme_EA[M]=0;
           for (i=0;i<8;i++)
           {
           Somme_EA[M]= Somme_EA[M] + Table_EA[M][i];
           }
           f1=(float)Somme_EA[M] * 0.0061035;  // // soit 500.0 / (8 x 1024.0); // LM35DZ 10mV/V
         */
    
    ***************   EXPONENTIAL FILTER ********************
    unsigned int M;
    char *txt;
    char Texte[64];
    float TF,Kfilter,TNow,TOld;
    int FirstPass=0;
     
    void Float2Ascii (float x, unsigned char *str,char precision) 
    
    
    void main()
    {
    
       txt=&Texte[0];
       UART1_Init(19200);
      FirstPass=0; // to init the exponential filter
      Kfilter=0.2; // value of filter must be >0.0 and <1.0
    
    while(1)
    {
    .......
    
     M= ADC_Read(0); 
     TNow=(float)M * 0.0048;
       if (FirstPass==0)
       {
        TOld=TNow;
        TF=TOld;
        FirstPass=1;
        }
        else
        {
         TF= ( TNow * Kfilter) + (1-Kfilter)*TOld;
         TOld=TF;
        }
        Float2Ascii (TF, txt,2);  
        UART1_Write_Text(txt);   UART1_Write(TAB);
        UART1_Write_CText(" Volts");
        CRLF();
       ....
    
    } // while 1



  3. #3
    Super Moderator
    Points: 49,058, Level: 54
    Awards:
    Most Frequent Poster

    Join Date
    Apr 2014
    Posts
    10,063
    Helped
    2403 / 2403
    Points
    49,058
    Level
    54

    Re: 16F877 thermometer problem

    Hi,

    as said in the other thread:

    * Update display only once per second.
    * use filters.

    ************
    Show us your code

    ************
    Please be more descriptive:
    "the units display is flickering" --> describe the "flickering". How often does it happen? What do you see?
    "until it get the right number " --> What is the "right number"? How can it be defined?
    "i think its something like the number after DP which i dont need " --> if you donīt need it, why do you display it?
    "how to ignore the unwanted values of my ADC ?" --> What are those "unwanted" values.

    Often as soon as you can describe the effects in words you are able to define it in software.
    When those effects are defined, then usually you can avoid them with software.

    Obvioulsy you can not write a program like this: "If ADC_value == unwanted then ignore it..."
    "unwanted" needs to be defined. Still itīs unclear how you decide it to be unwanted.
    "ignore" needs to be defined. Here it could be to use the ADC_value of the measurement before.

    Klaus



    •   Alt18th March 2016, 10:30

      advertising

        
       

  4. #4
    Full Member level 4
    Points: 2,239, Level: 10
    Achievements:
    7 years registered

    Join Date
    Jan 2010
    Posts
    210
    Helped
    2 / 2
    Points
    2,239
    Level
    10

    Re: 16F877 thermometer problem

    - - - Updated - - -

    here is my code give me ur ideas plz
    its not calibrated yet im just testing how it works
    & sorry i couldnt find word to explain the real problem im not tht good with english
    & i couldt find another way to get the ANA reading i hope the long table is ok
    Code:
    Main	call	DispRoutine
    		call	ad_portc
    		movf    ADRESH,W        ;Write A/D result to W       						
    		call	ADCtable
    		call	BinBCD
    		call	Main
    		
    
    ;****************************************************************
    ;* Delay 10mS 		10 x 1,000uS			*
    ;****************************************************************
    D_10mS	movlw	0Ah
    		movwf	temp2
    D_a		nop
    		decfsz temp1,1
    		goto 	D_a
    		decfsz temp2,1
    		goto 	D_a	
    		retlw 	00
    ;****************************************************************
    ;* Bin2BCD 		Converter *
    ;****************************************************************
    BinBCD  clrf    MSD	;Tens
    		movwf   LSD ;Units
    gtenth  movlw   .10
    		subwf   LSD,W
    		BTFSS   STATUS,C
    		goto    over
    		movwf   LSD
    		incf    MSD, F
    		goto    gtenth
    	over    retlw   0
    
    DispRoutine
    		movlw	b'00000001'	;Activate Right Display
    		movwf	portE
    		;movf	units,0
    		movf	LSD,0
    		call	table
    		movwf	portD
    		call	D_10mS
    		;clrf	portB
    		movlw	b'00000010'	;Activate Left Display
    		movwf	portE
    		;;movf	tens,0
    		movf	MSD,0
    		call	table
    		movwf	portD
    		call	D_10mS
    retlw	0x00
    
    ad_portc
                                    ;wait for acquision time (20uS)
                                    ;(non-critical for this test)
            bsf     ADCON0,GO       ;Start A/D conversion
    Wait
            btfsc   ADCON0,GO       ;Wait for conversion to complete
            goto    Wait
            ;movf    ADRESH,W        ;Write A/D result to W       						
    return
    
    
    table	addwf   PCL,F           ;02h,1  add W to program counter 
            retlw   b'00111111'     ; "0"   -|F|E|D|C|B|A
            retlw   b'00000110'     ; "1"   -|-|-|-|C|B|-
            retlw   b'01011011'     ; "2"   G|-|E|D|-|B|A
            retlw   b'01001111'     ; "3"   G|-|-|D|C|B|A 
            retlw   b'01100110'     ; "4"   G|F|-|-|C|B|-
            retlw   b'01101101'     ; "5"   G|F|-|D|C|-|A
            retlw   b'01111101'     ; "6"   G|F|E|D|C|-|A
            retlw   b'00000111'     ; "7"   -|-|-|-|C|B|A
            retlw   b'01111111'     ; "8"   G|F|E|D|C|B|A
            retlw   b'01101111'     ; "9"   G|F|-|D|C|B|A
    		retlw	b'01110011'		; "P"
    		retlw	b'01101101'		; "S"
    
    ADCtable	addwf   PCL,F           ;02h,1  add W to program counter
    		retlw	0x00
    		retlw	0x00
    		retlw	0x00
    		retlw	0x00
    		retlw	0x00
    		retlw	0x00
    		retlw	0x00
    		retlw	0x00
    		retlw	0x00
    		retlw	0x00
    		retlw	0x00	;10
    		retlw	0x00
    		retlw	0x01
    		retlw	0x01
    		retlw	0x02
    		retlw	0x02
    		retlw	0x03
    		retlw	0x03
    		retlw	0x04
    		retlw	0x04
    		retlw	0x05	;20
    		retlw	0x05
    		retlw	0x06
    		retlw	0x06
    		retlw	0x07
    		retlw	0x07
    		retlw	0x08
    		retlw	0x08
    		retlw	0x09
    		retlw	0x09
    		retlw	0x0A	;30
    		retlw	0x0A
    		retlw	0x0B
    		retlw	0x0B
    		retlw	0x0C
    		retlw	0x0C
    		retlw	0x0D
    		retlw	0x0D
    		retlw	0x0E
    		retlw	0x0E
    		retlw	0x0F	;40
    		retlw	0x0F
    		retlw	0x10
    		retlw	0x10
    		retlw	0x11
    		retlw	0x11
    		retlw	0x12
    		retlw	0x12
    		retlw	0x13
    		retlw	0x13
    		retlw	0x14	;50
    		retlw	0x14
    		retlw	0x15
    		retlw	0x15
    		retlw	0x16
    		retlw	0x16
    		retlw	0x17
    		retlw	0x17
    		retlw	0x18
    		retlw	0x18
    		retlw	0x19	;60
    		retlw	0x19
    		retlw	0x00
    		retlw	0x00
    		retlw	0x00
    		retlw	0x00
    		retlw	0x00
    		retlw	0x00
    		retlw	0x00
    		retlw	0x00
    		retlw	0x00	;70
    Last edited by janosandi; 18th March 2016 at 13:53.



  5. #5
    Super Moderator
    Points: 49,058, Level: 54
    Awards:
    Most Frequent Poster

    Join Date
    Apr 2014
    Posts
    10,063
    Helped
    2403 / 2403
    Points
    49,058
    Level
    54

    Re: 16F877 thermometer problem

    Hi,

    * Update display only once per second.
    Where do you take care of this? It seems you update the display about 30 times per second..

    Klaus



  6. #6
    Full Member level 4
    Points: 2,239, Level: 10
    Achievements:
    7 years registered

    Join Date
    Jan 2010
    Posts
    210
    Helped
    2 / 2
    Points
    2,239
    Level
    10

    Re: 16F877 thermometer problem

    Quote Originally Posted by KlausST View Post
    Hi,


    Where do you take care of this? It seems you update the display about 30 times per second..

    Klaus
    i couldnt find where to make a delay without make a problem
    i've arranged the routines this way but the display routine need no delay so where to make a delay
    wht about my ADCtable is it ok ? its more long for more reading
    or there is another way to do it ?
    im executing the code line by line with mplab sim but my brain has stopped working anymore
    Last edited by janosandi; 18th March 2016 at 13:56.



  7. #7
    Super Moderator
    Points: 49,058, Level: 54
    Awards:
    Most Frequent Poster

    Join Date
    Apr 2014
    Posts
    10,063
    Helped
    2403 / 2403
    Points
    49,058
    Level
    54

    Re: 16F877 thermometer problem

    Hi,

    i couldnt find where to make a delay without make a problem
    WHAT kind of problem?

    *****

    Code:
    Main	call	DispRoutine
    		call	ad_portc
    		movf    ADRESH,W        ;Write A/D result to W       						
    		call	ADCtable
    		call	BinBCD
    		call	Main
    ..
    Shouldnīt this be a "goto" instead of a "call". In my eyes this could cause a stack overflow.

    Klaus



  8. #8
    Full Member level 4
    Points: 2,239, Level: 10
    Achievements:
    7 years registered

    Join Date
    Jan 2010
    Posts
    210
    Helped
    2 / 2
    Points
    2,239
    Level
    10

    Re: 16F877 thermometer problem

    i've tried to put a delay in few places but the units display has stoppd working
    can i run 2 routines same time ?
    sorry for my english im looking for words to describe the real problem
    & m sorry for the code
    i'll try to edit the call to goto but my bad luck there is no electric & the generator has stopped
    thx

    John



    •   Alt18th March 2016, 14:02

      advertising

        
       

  9. #9
    Super Moderator
    Points: 49,058, Level: 54
    Awards:
    Most Frequent Poster

    Join Date
    Apr 2014
    Posts
    10,063
    Helped
    2403 / 2403
    Points
    49,058
    Level
    54

    Re: 16F877 thermometer problem

    Hi,

    Your ADC-table is:
    Code:
    If W < 10 --> retlw 0
    If W >= 61 --> retlw 0
    W = W -10
    shift W one bit right.
    ret
    Klaus



    •   Alt18th March 2016, 14:08

      advertising

        
       

  10. #10
    Full Member level 4
    Points: 2,239, Level: 10
    Achievements:
    7 years registered

    Join Date
    Jan 2010
    Posts
    210
    Helped
    2 / 2
    Points
    2,239
    Level
    10

    Re: 16F877 thermometer problem

    Quote Originally Posted by KlausST View Post
    Hi,

    Your ADC-table is:
    Code:
    If W < 0x10 --> retlw 0
    If W >= 61 --> retlw 0
    W = W -10
    shift W one bit right.
    ret
    Klaus
    i cant use this in assembly i guess?



  11. #11
    Super Moderator
    Points: 49,058, Level: 54
    Awards:
    Most Frequent Poster

    Join Date
    Apr 2014
    Posts
    10,063
    Helped
    2403 / 2403
    Points
    49,058
    Level
    54

    Re: 16F877 thermometer problem

    Hi,

    can i run 2 routines same time ?
    on a PIC you can never run two routines the same time. Only one after the other.


    ***
    If you can run a 10ms delay once .. then I canīt find why you canīt run it 100 times.

    ...anywhere in the main loop


    Klaus



  12. #12
    Full Member level 4
    Points: 2,239, Level: 10
    Achievements:
    7 years registered

    Join Date
    Jan 2010
    Posts
    210
    Helped
    2 / 2
    Points
    2,239
    Level
    10

    Re: 16F877 thermometer problem

    Dear Klaus
    i've got pic basic pro.
    do u suggest to learn the basic language or keep learning assembly ?



  13. #13
    Super Moderator
    Points: 49,058, Level: 54
    Awards:
    Most Frequent Poster

    Join Date
    Apr 2014
    Posts
    10,063
    Helped
    2403 / 2403
    Points
    49,058
    Level
    54

    Re: 16F877 thermometer problem

    Hi,

    this is a "mathematical example" not a program.

    it consists of
    * two contitional branchs
    * a subtract
    * and a shift

    it should be very easy.

    But I donīt know the PIC assembler...

    Klaus



  14. #14
    Full Member level 4
    Points: 2,239, Level: 10
    Achievements:
    7 years registered

    Join Date
    Jan 2010
    Posts
    210
    Helped
    2 / 2
    Points
    2,239
    Level
    10

    Re: 16F877 thermometer problem

    in assembly its complicated alot as i search for tutorials or sample codes
    do u suggest basic language ? i was doing well with visual basic along time ago



  15. #15
    Super Moderator
    Points: 49,058, Level: 54
    Awards:
    Most Frequent Poster

    Join Date
    Apr 2014
    Posts
    10,063
    Helped
    2403 / 2403
    Points
    49,058
    Level
    54

    Re: 16F877 thermometer problem

    Hi,

    do u suggest to learn the basic language or keep learning assembly ?
    I have no preference.

    Klaus



  16. #16
    Full Member level 4
    Points: 2,239, Level: 10
    Achievements:
    7 years registered

    Join Date
    Jan 2010
    Posts
    210
    Helped
    2 / 2
    Points
    2,239
    Level
    10

    Re: 16F877 thermometer problem

    Quote Originally Posted by KlausST View Post
    Hi,


    I have no preference.

    Klaus
    ok thx for ur help i'll take some time this evening looking for this i guess its easier to learn the Pic Basic & convert my project to it coz i coulnt find easy ways in Assembly
    thx again ur help is very appriciated

    John



  17. #17
    Junior Member level 3
    Points: 1,076, Level: 7

    Join Date
    Jan 2012
    Location
    CA.
    Posts
    27
    Helped
    5 / 5
    Points
    1,076
    Level
    7

    Re: 16F877 thermometer problem

    John,
    You will find Pic Basic Pro to be worth every penny. It will save you hours of coding. On this project and every one to follow.
    You will be able to test the value coming from the thermistor several times, and when you get the same value a few times in a row, tell the Micro
    to change the LED display to the new reading. This is better than just a delay, because the speed of the temperature value will change upon varying conditions.
    -Lisa



  18. #18
    Full Member level 4
    Points: 2,239, Level: 10
    Achievements:
    7 years registered

    Join Date
    Jan 2010
    Posts
    210
    Helped
    2 / 2
    Points
    2,239
    Level
    10

    Re: 16F877 thermometer problem

    i'v found something similar to my problem in Gooligum tuorial (lesson 11 -integer arithmetic and arrays)
    i was ignoring on anything tht i dont need in any project i work on
    there is a very valuable Info's in this tutorials

    - - - Updated - - -

    Quote Originally Posted by LISA_DALTON View Post
    John,
    You will find Pic Basic Pro to be worth every penny. It will save you hours of coding. On this project and every one to follow.
    You will be able to test the value coming from the thermistor several times, and when you get the same value a few times in a row, tell the Micro
    to change the LED display to the new reading. This is better than just a delay, because the speed of the temperature value will change upon varying conditions.
    -Lisa
    thx Lisa
    i have the pic basic pro but i didnt try to use it yet &
    i have a good knowledge about Basic along time ago so do u think learning PIC Basic Pro needs the same time to learn how to solve my problem in assembly ?
    i'll try to work on it this evening any good start you suggest ?

    thx
    John



  19. #19
    Junior Member level 3
    Points: 1,076, Level: 7

    Join Date
    Jan 2012
    Location
    CA.
    Posts
    27
    Helped
    5 / 5
    Points
    1,076
    Level
    7

    Re: 16F877 thermometer problem

    John,
    If you have programmed in Basic before, this will be easy and faster for you to get results than assembly.
    I'd start by simply flashing an led on 1 pin of 1 port, and go from there. Try port B pin 1 for simplicity. No need to worry about the open collector output.
    On Pin 1 Port A. Use a high output LED and you will get decent brightness without drawing too much current
    from the Micro pin. Be to use a 470 Ohm resistor (Approx) to limit current.
    Things should go much easier with Pic Basic Pro.
    Good Luck!
    -Lisa



    •   Alt19th March 2016, 20:23

      advertising

        
       

  20. #20
    Full Member level 4
    Points: 2,239, Level: 10
    Achievements:
    7 years registered

    Join Date
    Jan 2010
    Posts
    210
    Helped
    2 / 2
    Points
    2,239
    Level
    10

    Re: 16F877 thermometer problem

    Quote Originally Posted by LISA_DALTON View Post
    John,
    If you have programmed in Basic before, this will be easy and faster for you to get results than assembly.
    I'd start by simply flashing an led on 1 pin of 1 port, and go from there. Try port B pin 1 for simplicity. No need to worry about the open collector output.
    On Pin 1 Port A. Use a high output LED and you will get decent brightness without drawing too much current
    from the Micro pin. Be to use a 470 Ohm resistor (Approx) to limit current.
    Things should go much easier with Pic Basic Pro.
    Good Luck!
    -Lisa
    thx Lisa
    i've tried the Blink example with small edit
    ive changed the led Varible to PORTB,1
    but when i swicth it on the led on portB its not flashing still on all the time
    i've tried to change the pause number to 900 but the same& as i see its a simple test but why its not working with me ?
    Code:
    ' Configure pins for digital operation (uncomment as needed).
    ' These settings are intended as simple examples.  For more detail,
    ' see the appropriate device datasheet for register descriptions.
    'ANSEL =  %00000000  ' 16F88, 16F688, 16F690, 16F88x
    'ANSELH = %00000000  ' 16F690, 16F88x
    ADCON1 = %00000111  ' 16F87x, 16F87xA, 18F452
    'ADCON1 = %00001111  ' 18F4620 
    
    LED    VAR  PORTB.1   ' Assign name "LED" to PORTB.0
    
    mainloop:
       High LED        ' Turn on LED connected to PORTB.0
       Pause 500       ' Delay for .5 seconds
    
       Low LED         ' Turn off LED connected to PORTB.0
       Pause 500       ' Delay for .5 seconds
    
       Goto mainloop   ' Go back to loop and blink LED forever
       
       End
    im using pic 16F877 with 20 Mhz Crystal

    - - - Updated - - -

    its Flashing But the delay is about 10 seconds
    Last edited by janosandi; 20th March 2016 at 13:49.



--[[ ]]--