wrong positive and negative voltages on lcd 20x4


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Jul 2022
    Posts
    26

    Unhappy wrong positive and negative voltages on lcd 20x4

    I am in a symmetrical source project with pic 16f886, but in the proteus simulation the voltage values displayed on a 20x4 lcd, and these values are different from the registers in the proteus dc voltmeters.
    and the negative voltage displayed on the 20x4 lcd is displayed very fast.
    and the positive voltage displayed on the 20x4 lcd is displayed normal


    If someone could please review the code and correct it, I would appreciate it and thank you

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: wrong positive and negative voltages on lcd 20x4

    I think you gonna have to post the code, otherwise it's kind of hard...

  3. #3
    Join Date
    Jul 2022
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Re: wrong positive and negative voltages on lcd 20x4

    Code:
    'Config for 16f886
    #CONFIG
        __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_ON & _CPD_ON
    #ENDCONFIG
    
    
    include "fp2032.bas"    ' Include file for 14-bit core with RAM at $20 (32-bit)
    define OSC  8
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTC
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTC
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    
    
    
    
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_ SAMPLEUS 50
    '********************************************************************
    LED VAR PORTC.4
    TXD VAR PORTC.6
    B1 VAR WORD
    B2 VAR WORD
    VALOR1 VAR BYTE
    VALOR2 VAR BYTE
    fpplaces  var  byte     ' Used to define number of decimal places in fpdisplay,fpdisplayr
    ahold    var   word     ' Required by fpdisplay
    bhold    var   word     ' Required by fpdisplay
    '********************************************************************
    INICIO:
             TRISC.6 = 0          'in
             TRISC.7 = 1          'out
             TRISA = 255          'Port_A = in
             ADCON1 = %11000010   'left alignment
             TRISB.6 = 0          'out
    
    
             LCDOUT  $FE,2,"  FUENTE SIMETRICA  "     '1_line
             LCDOUT  $FE,$C0," JOSE LUIS COMAS LL "   '2_line
             LCDOUT  $FE,$94,"VOLT.NEGATIVO:-"        '3_line
             LCDOUT  $FE,$D4,"VOLT.POSITIVO:+"        '4_line
    COMENZAR:
             ADCIN 1, B1    'read negativ via chanal_1_ADC
             ADCIN 2, B2    'read positiv via chanal_2_ADC
    
             'send ADC to terminal
             SEROUT2  TXD,188,["$", "$", DEC4 B1,"$", "$",DEC4 B2,10,13]
    
             aint = B1      'read -volt_to+B1
             gosub itofa    'Conviertelo a punto flotante
             bint = 2000    'Carga el valor 2000 (5*400)
             gosub itofb    'Conviertelo en punto flotante
             gosub  fpmul   'ADCres * 2000
             bint = 52224   'Carga el valor de la cuenta maxima del ADC * 51
             gosub itofb    'Conviertelo en punto flotante
             GOSUB  fpdiv   '(ADCres * 2000)/52224
    '++++++++++++++
    'pv         LCDOUT  $FE,$A3,"     "    'Limpia el espacio donde se coloca el voltaje negativo
             LCDOUT  $FE,$A3
    '++++++++++++++
             fpplaces = 2 : Gosub fpdisplayr    ' Call display routine
    
             aint = B2      'Transfiere el valor del ADC del voltaje positivo
             gosub itofa    'Conviertelo a punto flotante
             bint = 35      'Carga el valor 35 (5*7)
             gosub itofb    'Conviertelo en punto flotante
             gosub  fpmul   'ADCres * 35
             bint = 1024    'Carga el valor de la cuenta maxima del ADC
             gosub itofb    'Conviertelo en punto flotante
             GOSUB  fpdiv   '(ADCres * 35)/1024
    '++++++++++++++
    'pv         LCDOUT  $FE,$E3,"     "    'Limpia el espacio donde se coloca el voltaje positivo
             LCDOUT  $FE,$E3
    '++++++++++++++
             fpplaces = 2 : Gosub fpdisplayr    ' Call display routine
    
    
             HIGH LED
            GOTO COMENZAR
    
    ' The fpdisplayr routine checks for number of places, then adds the appropriate
    ' value to achieve rounding.  To save RAM space, the values are hard coded
    ' in floating point format.
    
    
    fpdisplayr: If fpplaces=0 Then                  ' Set floating point barg to 0.5
                            bexp = $7E
                            bargb0 = $00
                            bargb1 = $00
                            bargb2 = $01
                      Endif
                      If fpplaces=1 Then                  ' Set floating point barg to 0.05
                            bexp = $7A
                            bargb0 = $4C
                            bargb1 = $CC
                            bargb2 = $CD
                      Endif
                      If fpplaces=2 Then                  ' Set floating point barg to 0.005
                            bexp = $77
                            bargb0 = $23
                            bargb1 = $D7
                            bargb2 = $0B
                      Endif
                      If fpplaces=3 Then                  ' Set floating point barg to 0.0005
                            bexp = $74
                            bargb0 = $03
                            bargb1 = $12
                            bargb2 = $6F
                      Endif
                      If fpplaces=4 Then                  ' Set floating point barg to 0.00005
                            bexp = $70
                            bargb0 = $51
                            bargb1 = $B7
                            bargb2 = $17
                      Endif
    
    
                      Gosub fpadd                         ' add barg to aarg
                      
    ' The fpdisplay routine outputs the signed value of aarg in decimal floating point format. It
    ' can display a positive value of 65535, and decimals to 4 places. The number of decimal
    ' places should be stored in fpplaces before calling the routine. The routine reads the
    ' floating point value of aarg. This value should NOT be converted to an integer before
    ' calling fpdisplay. The integer conversion will be perfomed as part of this routine, and
    ' aint will be returned to the calling program just as from the itofa routine.
    
    
    fpdisplay:  bexp = aexp                         ' Store the FP value of aarg to the barg variables
                      bargb0 = aargb0
                      bargb1 = aargb1
                      bargb2 = aargb2
    
    
                      Gosub ftoia                   ' Convert aarg to integer
                      ahold = aint                        ' Save this value for the final display
                      
                      Gosub itofa                   ' Convert integer back to float
    
    
                      Swap aexp,bexp                      ' Swap the FP values of aarg and barg before subtraction
                      Swap aargb0,bargb0
                      Swap aargb1,bargb1
                      Swap aargb2,bargb2
    
    
                      Gosub fpsub                   ' Subtract the integer portion from the full number
    
    
    
    
                      bint = 10                     ' Make bint = 10 E fpplaces
                      If fpplaces=2 Then
                            bint = 100
                      Endif
                      If fpplaces=3 Then
                            bint = 1000
                      Endif
                      If fpplaces=4 Then
                            bint = 10000
                      Endif
    
    
                      bhold = bint                        ' Save the integer value of bint for zeros loop
    
    
                      Gosub itofb                   ' Convert bint to integer prior to FP multiply
                      Gosub fpmul                   ' Multiply the decimal portion x 10 E fpplaces
    
    
                      Gosub ftoia                   ' Convert result to aint integer
    
    
                      Lcdout dec ahold              ' Display integer portion
                      If fpplaces > 0 Then                            
                            Lcdout "."              ' Display decimal point
    zeros:                  bhold = bhold / 10                                          ' Set bhold to be next place to right
                            If (aint < bhold) AND (bhold > 1) Then          ' Check for leading zero in decimal
                                  Lcdout "0"                                            ' Display leading zero
                                  Goto zeros                                            ' loop to check for another zero
                            Endif
                            Lcdout dec aint               ' Display the rest of the decimal portion
                      Endif
    
    
                      aint = ahold                        ' Restore the original value of aint
    
    
                      Return              
    'pv         LCDOUT  $FE,$A3,"     "    'Limpia el espacio donde se coloca el voltaje negativo
    'pv         LCDOUT  $FE,$A3
    'pv         LCDOUT  $FE,$E3,"     "    'Limpia el espacio donde se coloca el voltaje positivo
    'pv         LCDOUT  $FE,$E3
    
    
    thanks for answering
    I attach the code
    Last edited by Ioannis; - 17th April 2023 at 08:58.

  4. #4
    Join Date
    Jul 2022
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Re: wrong positive and negative voltages on lcd 20x4

    https://drive.google.com/file/d/11pN...uhMMrPdIk/view
    I attached a video link where you will see the code failure.


    You will see in the ldc 20x4 the negative voltage is displayed very quickly, the lcd will register voltage 12.45 and in the proteus dc voltmeter it registers 12.5V


    in the 20x4 lcd it registers a positive voltage of 12.58, it displays normal and in the dc voltmeter of proteus it will register a voltage of 12.6V.
    You will see that the decimals record different values of both positive and negative voltages.
    I hope that the video can serve you better to see and correct the code.
    thank you

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


    Did you find this post helpful? Yes | No

    Default Re: wrong positive and negative voltages on lcd 20x4

    and the negative voltage displayed on the 20x4 lcd is displayed very fast.
    and the positive voltage displayed on the 20x4 lcd is displayed normal

    i doubt many would risk unvetted zipped content from google drive, youtube would be safer.
    what does displayed very fast mean ?
    what does displayed normal mean ?
    has it ever worked or is it just a proteus simulation, proteus does not really work for some real time things.
    there is no schematic.
    why use fp ,can you really expect accuracy to 2 decimals.
    what does symmetric power supply mean ,the code is just a display
    two dp accuracy from single asynchronous adc results is not plausible afaics esp without a stable voltage reference for adc

    [same old same old]

  6. #6
    Join Date
    Jul 2022
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Re: wrong positive and negative voltages on lcd 20x4

    Quote Originally Posted by richard View Post
    i doubt many would risk unvetted zipped content from google drive, youtube would be safer.
    what does displayed very fast mean ?
    what does displayed normal mean ?
    has it ever worked or is it just a proteus simulation, proteus does not really work for some real time things.
    there is no schematic.
    why use fp ,can you really expect accuracy to 2 decimals.
    what does symmetric power supply mean ,the code is just a display
    two dp accuracy from single asynchronous adc results is not plausible afaics esp without a stable voltage reference for adc

    [same old same old]
    consider that through google drive I was able to share the video so that they could see the proteus simulation, and see the code failure when the positive and negative voltages are displayed, that the negative voltage is displayed very fast and the positive voltage is displayed normally.

    You will see in the ldc 20x4 the negative voltage is displayed very quickly, the lcd will register voltage 12.45 and in the proteus dc voltmeter it registers 12.5V


    in the 20x4 lcd it registers a positive voltage of 12.58, it displays normal and in the dc voltmeter of proteus it will register a voltage of 12.6V.
    You will see that the decimals record different values of both positive and negative voltages.
    I hope that the video can serve you better to see and correct the code.
    thank you

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: wrong positive and negative voltages on lcd 20x4

    I do not use Proteus so maybe I am wrong. But the Proteus voltmeter, does not have any properties to set? Like how many decimal to use?

    Ioannis

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: wrong positive and negative voltages on lcd 20x4

    when corrected for a 2 line display as depicted in your code
    Code:
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTC
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTC
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    it works in proteus much as expected

    Name:  jose.jpg
Views: 579
Size:  490.3 KB
    Warning I'm not a teacher

  9. #9
    Join Date
    Jul 2022
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Re: wrong positive and negative voltages on lcd 20x4

    Name:  Problems with mathematical equations in Symmetric Font.jpg
Views: 464
Size:  246.6 KB
    Quote Originally Posted by richard View Post
    when corrected for a 2 line display as depicted in your code
    Code:
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTC
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTC
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    it works in proteus much as expected

    Attachment 9354
    previously I had this code using pic 16f877a​

    DEFINE LCD_DREG PORTD
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTE
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTE
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2

    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_ SAMPLEUS 50

    TRISC.6 = 0
    TRISC.7 = 1
    TRISA = 255
    ADCON1 = %11000010
    TRISB.6 = %0

    LED VAR PORTB.6
    B1 VAR WORD
    B2 VAR WORD
    VALOR1 VAR BYTE
    VALOR2 VAR BYTE

    STAR:
    ADCIN 1, B1
    ADCIN 2, B2
    VALOR1=B1/9
    VALOR2=B2/12

    SEROUT2 PORTC.6,188,["$", "$", DEC4 B1,"$", "$",DEC4 B2,10,13]
    LCDOUT $FE,2," SYMMETRIC FONT "
    LCDOUT $FE,$C4," JOSE LUIS "
    LCDOUT $FE,$90," VOLTAGE NEGATIVE:-",DEC2 VALOR1
    LCDOUT $FE,$D0," VOLTAGE POSITIVE:+",DEC2 VALOR2
    HIGH LED
    GOTO STAR​

    If you look at the image you will see that the voltages registered in the 20x4 lcd are different from the voltages registered in the proteus dc voltmeter.
    I had errors in the floating point and I was able to correct it with the 32-bit library.
    and the other code is an improvement, but it still has errors, and in the simulation it shows it.
    I hope you can help me correct the code and thanks again​



  10. #10
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: wrong positive and negative voltages on lcd 20x4

    VALOR1=B1/9
    VALOR2=B2/12
    b1 = 329 , b1/9 =35 target is 12.2 why divide by 9 ?
    b2 = 360 , b2/12=30 target is 12.3 why divide by 12 ?


    to get more resolution
    dummy = b1*100
    VALOR = div32 26
    result = 1226 ie 12.26 *100

    an even more accurate result is possible using */
    Warning I'm not a teacher

  11. #11
    Join Date
    Jul 2022
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Re: wrong positive and negative voltages on lcd 20x4

    Quote Originally Posted by richard View Post
    b1 = 329 , b1/9 =35 target is 12.2 why divide by 9 ?
    b2 = 360 , b2/12=30 target is 12.3 why divide by 12 ?


    to get more resolution
    dummy = b1*100
    VALOR = div32 26
    result = 1226 ie 12.26 *100

    an even more accurate result is possible using */
    In my previous code I had many errors due to the mathematical equations and I was able to partially correct these errors using the fp2032.bas library.
    even the code continues with the errors in mathematical equations, for that reason I went to the lighthouse to see if they could help correct the code, thanks


  12. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: wrong positive and negative voltages on lcd 20x4

    I went to the lighthouse to see if they could help correct the code
    if you don't understand the math / pbp language then you can seek assistance
    in this section of the forum [Commercial - Assistance Required] , your problem
    description and solution attempts make little sense to me
    Warning I'm not a teacher

  13. #13
    Join Date
    Jul 2022
    Posts
    26


    Did you find this post helpful? Yes | No

    Thumbs up Re: wrong positive and negative voltages on lcd 20x4

    Quote Originally Posted by richard View Post
    if you don't understand the math / pbp language then you can seek assistance
    in this section of the forum [Commercial - Assistance Required] , your problem
    description and solution attempts make little sense to me
    I will try and thank you very much for your help

  14. #14
    Join Date
    Jul 2022
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Re: wrong positive and negative voltages on lcd 20x4

    Name:  Simulacion Corregida Fuente Simetrica (1).jpg
Views: 332
Size:  98.1 KB

    I have solved the problem, I attach image

Similar Threads

  1. Monitoring negative voltages
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 16th August 2014, 04:17
  2. Pic18f452 with 20x4 LCD Help
    By djmachine in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th November 2008, 22:43
  3. Measuring negative voltages
    By sammy in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th June 2006, 01:36
  4. 20x4 LCD and P18F2680
    By microuser in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 9th June 2006, 19:26
  5. LCD 20X4 connect with DS1820
    By jojokatada in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 9th March 2005, 11:04

Members who have read this thread : 5

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