Menu

LCD2SerialRedirect on 18F26K22

Help
2018-11-09
2021-01-06
1 2 > >> (Page 1 of 2)
  • George Towler

    George Towler - 2018-11-09

    Still very new to this, so forgive me if it's a daft question or if I've posted in the wrong place.

    I tried changing the device in the demo "Fixed Voltage Reference @ 16f1829" to 18F26K22. I added a blinky after the existing code in the main loop. I see no serial output on either TX1 or TX2 and the blinky doesn't blink. Is there some limitation to LCD2SerialRedirect on 18F26K22.

    My hardware seems to be ok, the hello world demo generated serial data and a blinky ran as expected at the correct speed (both on 18F26K22).

     
  • Anobium

    Anobium - 2018-11-09

    No limitation.

    Post the code as an attachment so we can review.

     
  • George Towler

    George Towler - 2018-11-09

    Device changed and blinky added. Dir's added experimentally.

    '''A demonstration program for GCGB and GCB.
    '''--------------------------------------------------------------------------------------------------------------------------------
    '''This program shows the Fixed Voltage Reference capabilities of Great Cow Basic
    '''The Fixed Voltage Reference, or FVR, is a stable voltage reference, independent of VDD, with 1.024V,
    '''2.048V or 4.096V selectable output levels. The output of the FVR can be configured to supply a reference
    '''voltage to the ADC positive reference
    ''':
    ''':
    '''@author  EvanV
    '''@licence GPL
    '''@version 1.0a
    '''@date    17.7.2017
    '''********************************************************************************
    
    ; ----- Configuration
        #Chip 18F26K22, 64
    
        ' THIS CONFIG OF THE SERIAL PORT WORKS WITH A  MAX232 (or equiv) THEN TO PC
        ' USART settings - CHANGE PORTS if required
        #define USART_BAUD_RATE 19200
        #define USART_TX_BLOCKING
        Dir PORTc.6 Out
        Dir PORTc.7 In
    
        #include  <LCD2SerialRedirect.h>
        ; Required to LCD to Serial redirection
        #define LCD_IO 0
        dir porta.4 out
    
         CLS
    
         Locate 4,0 : Print "Fixed Voltage Reference"
    
         Do
    
               '// Use VCC as Reference
               FVRInitialize ( FVR_off )
               wait while FVRIsOutputReady = false
               ADVal = ReadAd(AN0)
               Locate 0,0 : Print AdVal : LCDSpace 3
               Locate 0,6 : Print "VREF = Vdd"
    
               '// use FVR 4096 as Reference
               FVRInitialize ( FVR_4x )
               wait while FVRIsOutputReady = false
               ADVal = ReadAd(AN0)
               Locate 1,0 : Print AdVal : LCDSpace 3
               Locate 1,6 : Print "VREF = 4.096"
               Wait 100 ms
    
               '// Change to 2.048 and enable
               FVRInitialize ( FVR_2x )
               wait while FVRIsOutputReady = false
               ADVal = ReadAd(AN0)
               Locate 2,0 : Print AdVal : LCDSpace 3
               Locate 2,6 : Print "VREF = 2.048"
               Wait 100 ms
    
               '// Change to 1.024 and enable
               FVRInitialize ( FVR_1x )
               wait while FVRIsOutputReady = false
               ADVal = ReadAd(AN0)
               Locate 3,0 : Print AdVal : LCDSpace 3
               Locate 3,6 : Print "VREF = 1.024"
               Wait 100 ms
    
            wait 500 ms
            porta.4 = NOT  porta.4
    
            Loop
    
    ''' GCB Optimisation file
    
    'Optimise A-d.h
        'Standard family chips
        #define USE_AD0 TRUE
        #define USE_AD1 FALSE
        #define USE_AD2 FALSE
        #define USE_AD2 FALSE
        #define USE_AD3 FALSE
        #define USE_AD4 FALSE
        #define USE_AD5 FALSE
        #define USE_AD6 FALSE
        #define USE_AD7 FALSE
        #define USE_AD8 FALSE
        #define USE_AD9 FALSE
        #define USE_AD10 FALSE
        #define USE_AD11 FALSE
        #define USE_AD12 FALSE
        #define USE_AD13 FALSE
        #define USE_AD14 FALSE
        #define USE_AD15 FALSE
        #define USE_AD16 FALSE
        #define USE_AD17 FALSE
        #define USE_AD18 FALSE
        #define USE_AD19 FALSE
        #define USE_AD20 FALSE
        #define USE_AD21 FALSE
        #define USE_AD22 FALSE
        #define USE_AD23 FALSE
        #define USE_AD24 FALSE
        #define USE_AD25 FALSE
        #define USE_AD26 FALSE
        #define USE_AD27 FALSE
        #define USE_AD28 FALSE
        #define USE_AD29 FALSE
        #define USE_AD30 FALSE
        #define USE_AD31 FALSE
        #define USE_AD32 FALSE
        #define USE_AD33 FALSE
        #define USE_AD34 FALSE
    
        'Family of chips based on 16f1688x with ADCON3 register
        #define USE_ADA0 FALSE
        #define USE_ADA1 FALSE
        #define USE_ADA2 FALSE
        #define USE_ADA3 FALSE
        #define USE_ADA4 FALSE
        #define USE_ADA5 FALSE
        #define USE_ADA6 FALSE
        #define USE_ADA7 FALSE
        #define USE_ADB0 FALSE
        #define USE_ADB1 FALSE
        #define USE_ADB2 FALSE
        #define USE_ADB3 FALSE
        #define USE_ADB4 FALSE
        #define USE_ADB5 FALSE
        #define USE_ADB6 FALSE
        #define USE_ADB7 FALSE
        #define USE_ADC0 FALSE
        #define USE_ADC1 FALSE
        #define USE_ADC2 FALSE
        #define USE_ADC3 FALSE
        #define USE_ADC4 FALSE
        #define USE_ADC5 FALSE
        #define USE_ADC6 FALSE
        #define USE_ADC7 FALSE
        #define USE_ADD0 FALSE
        #define USE_ADD1 FALSE
        #define USE_ADD2 FALSE
        #define USE_ADD3 FALSE
        #define USE_ADD4 FALSE
        #define USE_ADD5 FALSE
        #define USE_ADD6 FALSE
        #define USE_ADD7 FALSE
        #define USE_ADE0 FALSE
        #define USE_ADE1 FALSE
        #define USE_ADE2 FALSE
    
     

    Last edit: George Towler 2018-11-09
  • Anobium

    Anobium - 2018-11-09

    Minimise the code. Does serial work?

      #Chip 18F26K22, 64
    
        #define USART_BAUD_RATE 19200
        #define USART_TX_BLOCKING
        Dir PORTc.6 Out
        Dir PORTc.7 In
    
        wait 100 ms
    
        HserPrint "Hello World"
        HserPrintCRLF
    

    Do you have a TTL convertor? or, not?

    When you have something on the terminal then text the LCD emulator.

     
  • George Towler

    George Towler - 2018-11-09

    Thanks for responding so quickly.

    Yes, the minimal example works

    As I said I have a working serial chain (device - TTL to RS232 - COM port)

    I amended the minimal example to

    #Chip 18F26K22, 64
    
        #include  <LCD2SerialRedirect.h>
        ; Required to LCD to Serial redirection
        #define LCD_IO 0
    
        CLS
    
        #define USART_BAUD_RATE 19200
        #define USART_TX_BLOCKING
        Dir PORTc.6 Out
        Dir PORTc.7 In
    
        do
    
        wait 100 ms
    
        'HserPrint "Hello World"
        'HserPrintCRLF
        Locate 4,0 : Print "Fixed Voltage Reference"
    
        loop
    

    I get the expected output.

    So I quess the problem is in the FVR code?

     
  • Anobium

    Anobium - 2018-11-09

    So, that emulates the LCD?

    If yes,

    Then, now out the ADC - ONLY the readad. Does that work?

     

    Last edit: Anobium 2018-11-09
  • George Towler

    George Towler - 2018-11-10

    adding "ADVal = ReadAd(AN0)" to the modified minimal code produces the same output ie the string "Fixed Voltage Reference"

     
  • Anobium

    Anobium - 2018-11-10

    Can you clarify please? Does the ADVal when display on the LCD emulator show a value that represents the ADV value of the pot?

     
  • Anobium

    Anobium - 2018-11-10

    @George et al.

    Updated ADC library. This will be included in future releases. So, for now download and put in the C:\GCB@Syn\GreatCowBasic\Include\lowlevel directory. This is the updated library: https://sourceforge.net/p/gcbasic/code/816/tree/GCBASIC/trunk/include/lowlevel/a-d.h?format=raw

    The library has been updated to handle the 18F FVR. Previous release support 16F only.

    Should work like this.

               255   VREF = Vdd
               64    VREF = 4.096
               127   VREF = 2.048
               255   VREF = 1.024
    Fixed Voltage Reference 
    
     

    Last edit: Anobium 2018-11-11
  • George Towler

    George Towler - 2018-11-11

    Thanks for all your effort, I'll give the new ADC library a spin as soon as I get back,

    Added later.

    I tried the following but I'm missing something because the actual Vdd values are wrong

    '''A demonstration program for GCGB and GCB.
    '''--------------------------------------------------------------------------------------------------------------------------------
    '''This program shows the Fixed Voltage Reference capabilities of Great Cow Basic
    '''The Fixed Voltage Reference, or FVR, is a stable voltage reference, independent of VDD, with 1.024V,
    '''2.048V or 4.096V selectable output levels. The output of the FVR can be configured to supply a reference
    '''voltage to the ADC positive reference
    ''':
    ''':
    '''@author  EvanV
    '''@licence GPL
    '''@version 1.0a
    '''@date    17.7.2017
    '''********************************************************************************
    
    ; ----- Configuration
        #Chip 18F26K22, 64
    
        ' THIS CONFIG OF THE SERIAL PORT WORKS WITH A  MAX232 (or equiv) THEN TO PC
        ' USART settings - CHANGE PORTS if required
        #define USART_BAUD_RATE 19200
        #define USART_TX_BLOCKING
        Dir PORTc.6 Out
        Dir PORTc.7 In
    
        #include  <LCD2SerialRedirect.h>
        ; Required to LCD to Serial redirection
        #define LCD_IO 0
        dir porta.4 out
        dim adval as Word
        dim VDD as Word
    
         CLS
    
         Locate 4,0 : Print "Fixed Voltage Reference"
    
         Do
    
               '// Use VCC as Reference
               FVRInitialize ( FVR_off )
               wait while FVRIsOutputReady = false
               ADVal = ReadAd10(AN0)
               Locate 0,0 : Print AdVal : LCDSpace 3
               Locate 0,20 : Print "VREF = Vdd"
    
               '// use FVR 4096 as Reference
               FVRInitialize ( FVR_4x )
               wait while FVRIsOutputReady = false
               ADVal = ReadAd10(AN0)
               VDD = 41943/Adval
               Locate 1,0 : Print AdVal : LCDSpace 3 : Print "Vdd * 10 = ": Print VDD
               Locate 1,26 : Print "VREF = 4.096"
               Wait 100 ms
    
               '// Change to 2.048 and enable
               FVRInitialize ( FVR_2x )
               wait while FVRIsOutputReady = false
               ADVal = ReadAd10(AN0)
               VDD = 20971/Adval
               Locate 2,0 : Print AdVal : LCDSpace 3 : Print "Vdd * 10 = ": Print VDD
               Locate 2,26: Print "VREF = 2.048"
               Wait 100 ms
    
               '// Change to 1.024 and enable
               FVRInitialize ( FVR_1x )
               wait while FVRIsOutputReady = false
               ADVal = ReadAd10(AN0)
               VDD = 10486/Adval            ' 1.024 * 1024 = 1048.6 (10486 To get 1/10th's)
               Locate 3,0 : Print AdVal : LCDSpace 3 : Print "Vdd * 10 = ": Print VDD
               Locate 3,26 : Print "VREF = 1.024"
               Wait 100 ms
    
            wait 500 ms
            porta.4 = NOT  porta.4
    
            Loop
    
    ''' GCB Optimisation file
    
    'Optimise A-d.h
        'Standard family chips
        #define USE_AD0 TRUE
        #define USE_AD1 FALSE
        #define USE_AD2 FALSE
        #define USE_AD2 FALSE
        #define USE_AD3 FALSE
        #define USE_AD4 FALSE
        #define USE_AD5 FALSE
        #define USE_AD6 FALSE
        #define USE_AD7 FALSE
        #define USE_AD8 FALSE
        #define USE_AD9 FALSE
        #define USE_AD10 FALSE
        #define USE_AD11 FALSE
        #define USE_AD12 FALSE
        #define USE_AD13 FALSE
        #define USE_AD14 FALSE
        #define USE_AD15 FALSE
        #define USE_AD16 FALSE
        #define USE_AD17 FALSE
        #define USE_AD18 FALSE
        #define USE_AD19 FALSE
        #define USE_AD20 FALSE
        #define USE_AD21 FALSE
        #define USE_AD22 FALSE
        #define USE_AD23 FALSE
        #define USE_AD24 FALSE
        #define USE_AD25 FALSE
        #define USE_AD26 FALSE
        #define USE_AD27 FALSE
        #define USE_AD28 FALSE
        #define USE_AD29 FALSE
        #define USE_AD30 FALSE
        #define USE_AD31 FALSE
        #define USE_AD32 FALSE
        #define USE_AD33 FALSE
        #define USE_AD34 FALSE
    
        'Family of chips based on 16f1688x with ADCON3 register
        #define USE_ADA0 true
        #define USE_ADA1 FALSE
        #define USE_ADA2 FALSE
        #define USE_ADA3 FALSE
        #define USE_ADA4 FALSE
        #define USE_ADA5 FALSE
        #define USE_ADA6 FALSE
        #define USE_ADA7 FALSE
        #define USE_ADB0 FALSE
        #define USE_ADB1 FALSE
        #define USE_ADB2 FALSE
        #define USE_ADB3 FALSE
        #define USE_ADB4 FALSE
        #define USE_ADB5 FALSE
        #define USE_ADB6 FALSE
        #define USE_ADB7 FALSE
        #define USE_ADC0 FALSE
        #define USE_ADC1 FALSE
        #define USE_ADC2 FALSE
        #define USE_ADC3 FALSE
        #define USE_ADC4 FALSE
        #define USE_ADC5 FALSE
        #define USE_ADC6 FALSE
        #define USE_ADC7 FALSE
        #define USE_ADD0 FALSE
        #define USE_ADD1 FALSE
        #define USE_ADD2 FALSE
        #define USE_ADD3 FALSE
        #define USE_ADD4 FALSE
        #define USE_ADD5 FALSE
        #define USE_ADD6 FALSE
        #define USE_ADD7 FALSE
        #define USE_ADE0 FALSE
        #define USE_ADE1 FALSE
        #define USE_ADE2 FALSE
    

    383 VREF = Vdd
    1023 Vdd * 10 = 41 VREF = 4.096
    1023 Vdd * 10 = 20 VREF = 2.048
    511 Vdd * 10 = 20 VREF = 1.024

    But I see you're about to release a new version. So I'l wait for that and give it another spin.

     
    • Anobium

      Anobium - 2018-11-11

      Wrong direction George. Use the upadated library. Your approach is a tad incorrect. {=)

       
      • George Towler

        George Towler - 2018-11-12

        Given the results I pretty sure you're correct but I think my problem is with the raw numbers not my math which in my non-GCB example produces results that tally with multimeter reading off Vdd.

         

        Last edit: George Towler 2018-11-12
  • George Towler

    George Towler - 2018-11-11

    FWIW the following produces the correct Vdd albeit not using GCB 18F26K22
    ~~~
    GetVdd:
    VREFCON0 = %10010000 ' FVR Enable, 1.024V
    ADCON0 = %01111101 ' Select FVR, ADC on
    ADCON1 = %00000000 ' pos = VDD NEG = VSS
    ADCON2 = %10111110 ' right justified, acquisition time = 20TAD, Clock = FOSC/64
    While FVRST = 0 : Wend ' Wait For 1.024v reference To stabilize

    DelayUS 15 ' Wait for sample/hold capacitors to charge
    GO_DONE = 1 ' Start conversion
    While GO_DONE = 1 : Wend ' Poll the GO_DONE flag for completion of conversion
    ADCON0 = %01111100 ' Select 1.024, ADC off
    FVREN = 0 ' FVR Disable
    EchoResult = Ad_Result
    VDD = 10486/Ad_Result ' convert input reading to VDD voltage *VDD must be a Word
    ' 1.024 * 1024 = 1048.6 - 10486 To get 1/10th's
    Return
    ~~~

     

    Last edit: George Towler 2018-11-11
  • Anobium

    Anobium - 2018-11-11

    try the library - the results I posted are real - direct from the device with no maths.

     
  • David Stephenson

    Just a reminder you cannot use the 1.024 V ref+ for the ADC.

     
    • George Towler

      George Towler - 2018-11-12

      Are you refering to A20. I think perhaps you are misinterpreting Microchips confusing numbers. The only restrictions I see are that FVR maynot exceed Vdd, so you could not use 4.096 if Vdd was 3.3V

       
  • William Roth

    William Roth - 2018-11-15

    Deep in the bowels of the the 18F266K22 Datasheet under Electrical Specifications ( Page 451 - Table 27-21 - parameter A20)

    There is no misinterpretation.

    A20 is the delta minimum between VREF+ and VREF-. If VREF- is assumed to to be ground or 0V then the "minimum" VRFEF+ is 2.0V where specified accuracy is guaranteed. This precludes FVR 1.024.

    However Microchip Developer Help ( FVR) ignores this and indicates that that all 3 FVR voltages can be used.

    So it is not that it cannot be used, it is that it should not be used if accuracy is critical.

    That being said, I have used FVR 1.024 sucessfully and with good accuracy on several projects but care must be taken to assure that accuracy.

    1) The ADC device ground must be tied as close ae possible to the PIC ground pin. Not somewhere on the other side of the board where it snakes around all over the board on a thin trace before it gets to a point common to the PIC ground pin. Use "star" grounding if possible. Bad or improper grounding can cost you 10 lsb or more.

    2) Likewise the signal line to the ADC input should connect as close as possible to the PIC ADC pin and not snake around all over the board.

    3) The ADC impedance should not exceed 10K Ohms.

    4) A clean power source. No dodgy power supplies

    5) A proper bypass capacitor across the PIC VDD and ground pins ( 100nF)

    6) If considerable loads are drawn from the same supply as the PIC is using then fit a 10uF to 47uF bulk capacitor on the board.

    Good Luck !

     

    Last edit: William Roth 2018-11-15
  • George Towler

    George Towler - 2018-11-15

    Thanks for the input, you obviously have a better handle on Microchipess than I. I also have successfully used the 1.024V ref to measure Vdd. I wonder what happens on some of the earlier devices that only had 1.024V?

    Anyway I still can't get the Vdd measurement to work. I tried using ReadAd (which I assume returns a 8 bit result) but that just returns all ones.

     
  • Anobium

    Anobium - 2018-11-15

    Works here... post your code as an attachment,

     
  • William Roth

    William Roth - 2018-11-15

    Anyway I still can't get the Vdd measurement to work. I tried using ReadAd (which I assume returns a 8 bit result) but that just returns all ones.

    By all ones, I assume you mean a decimal value of 255. This seems to indicate that the input voltage to the ADC pin is > 1.024v.

    To measure VDD using FVR 1024 you will need a voltage divider from VDD to Ground.

    For good resolution and easy maths the use a 10K fixed resistor over a 2K Trimer. Connect the center of this divider to the ADC input. Then use "ADC10" in your code .

    Adjust the trimmer so that when VDD = 5V the ADC value is 500. This will give you a resolution of 10 mv and good accuracy.

     
  • George Towler

    George Towler - 2018-11-16

    @William, you're knowledge of electronics is infinitely greater than mine and I would not disagree with anything you've posted (as much as I understand it). But the fact remains that using non-GCB code I have successfully measured Vdd using the 1.024v FVR to better than 0.1V (according to my cheap ebay multimeter) without any additional hardware. I will take your advice and from now on will use 2.048V FVR (where available) to measure VDD. Soon as I get a chance I'll try 2.048v and the hardware you suggest.

    @Anobium. Same code as 5 days ago. I've tried ReadAd with AdVal declared as a byte. I'm obviously missing something. ADC timing? I don't understand how variables used in libraries are declared, for instance Adval, should I declare it or does the lib do that?

     
    • Anobium

      Anobium - 2018-11-16

      @George. Post your code, as an attachment, and then we can help.

      We can explain the internals of the libraries when we know what methods you are using. You may not need to know the library variables as the majority are not intended to be used in a user program.

       
  • George Towler

    George Towler - 2018-11-16

    I think I might know whats wrong, in the 16F1829 FVR demo code, the ReadAd command is being passed the parameter AN0, I'm pretty sure thats not the correct value. Sorry if my terminology is incorrect.

    The code I'm using is the 11th. post in this thread. In my non-GCB code above I have
    ADCON0 = %01111101, I'm not sure how this equates to the parameter passed to ReadAd.

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.