Menu

PIC16F1828 Internal Ref

2017-07-08
2017-07-17
<< < 1 2 3 > >> (Page 2 of 3)
  • Daniel Cioba

    Daniel Cioba - 2017-07-11

    http://microchipdeveloper.com/8bit:fvr
    I will see if ADC works well ( full range , liniarity , etc ) at 1V REF after I can select that ... thats my problem now . Anyway I can't select neither 1V nor 2V .

     
    • Anobium

      Anobium - 2017-07-11

      I think we should wait until I get a sample from Microchip. I used the info posted in the previous post to create the library.... hence my puzzlement.

       
  • David Stephenson

    I've had no problem implimenting it on a 12F1522
    it's just a matter of setting the bits in the the FVRCON and the ADCON1

    fvrcon=b'10000010' 'bit 7 ref on,bits1and zero set to give 2.048V
    set adcon1.1 on
    set adcon1.0 on 'use the fixed voltage ref as ADC ref

    Not entirely convinced you need a library for this.
    (I've also done it on a 16F1788 and in that case you also need to set bits in ADCON2 as well).
    As nobody is taking it on I will repeat it isn't going to work for 1.024V (see electrical specifications)

     
    • Anobium

      Anobium - 2017-07-12

      Always listening and learning.

      @David. Can you point me to the 1.024V constraint information please?

       
    • Anobium

      Anobium - 2017-07-14

      what chip is this? 12F1522 is not recognised.

       
  • Daniel Cioba

    Daniel Cioba - 2017-07-12

    In datasheet at Electrical Specifications "For proper operation, the minimum value of the ADC positive voltage reference must be 1.8V or greater. When selecting the FVR or the VREF+ pin as the source of the ADC positive voltage reference, be aware that the voltage must be 1.8V or greater"

    But thats a separate issue , ADC will work anyway with degraded performance ( analog part ) . May be still usefull for some applications . Every ADC with external Ref has a minimum voltage , you can't go under 1V and expect good performance

     

    Last edit: Daniel Cioba 2017-07-12
  • David Stephenson

    I've tried it with 1.024V on the ADC reference and it does not work at all. On a 12 bit ADC (16F1788) it gives a full scale value no matter what the input is to the ADC. You may be able to get away with 1.7V but 1.024 is just too low to get operation.

     
  • Anobium

    Anobium - 2017-07-13

    I have dicussed with Microchip consulting - summary of these discussions.

    Using the the device's datasheet, as a general case,
    http://ww1.microchip.com/downloads/en/DeviceDoc/40001419F.pdf
    that can be downloaded from the device's page,
    http://www.microchip.com/wwwproducts/en/pic16f1828
    parameter AD06 in table 30-8 at page 359, and the corresponding Note 4, tell us that the Vref voltage (Vref+ minus Vref-) should not be less than 1.8V, regardless of the reference voltage used, in order for the ADC module to work within the datasheet specifications.

    Also, as Vref- cannot be a negative voltage (voltages below GND) the lowest voltage on it is 0V. Then an FVR of 1.024V cannot be used as VREF+ for the ADC, but only 2.048 and 4.098 values.

    The 1.024V FVR value exists for usage with other modules not the ADC module.

     
  • Anobium

    Anobium - 2017-07-14

    Back to the original ask.... @Daniel Cioba what is the status?

    I am now thinking that we ok as I get everything working ok here.

    Let us know please.

     
  • Daniel Cioba

    Daniel Cioba - 2017-07-15

    Hi , the same as before ... have you discovered something ? Is working ok in simulation or practical ?

     
    • Anobium

      Anobium - 2017-07-16

      I been throught the code, discussed this with Microchip and I cannot any error - yet.

      @Daniel. Can you describe what you think the issue is. There a few uses of FVR to drive different modules and I am wondering if I have 'got the wrong end of the stick' - I can sometimes get on a track of understanding that is 100% different to what we need to achieve. :-)

       
      • Daniel Cioba

        Daniel Cioba - 2017-07-16

        The issue is simple ... non selectable Vref with GC ADC library . Why is not working and how to resolve , of course i don't know yet .

         
  • kent_twt4

    kent_twt4 - 2017-07-16

    From a practical standpoint, the internal voltage reference is not all that accurate, the data sheet says -7 to +6%. You might get lucky and have one that is close.

    For a logger project I just used a good quality linear regulator which can be in the 1-2% range as the reference. Then used a 1% resistor divider (use <= 10k ohm values), matched or paired for increased accuracy, as the Vref+ input. The output should be within a couple handfull of millivolts compared to a DVM.

    If even more accuracy and stability required, then a lot of vendors make precision voltage references like the TL431 that can go sub 1% accuracy.

     
    • Daniel Cioba

      Daniel Cioba - 2017-07-16

      You are right , but for one project ( not mass production ) it is simple to measure exactly the Vref for that chip ( in this case indirect measurement of input voltage at which we have full scale reading 1023 ), and adjust the software .

       

      Last edit: Daniel Cioba 2017-07-16
  • William Roth

    William Roth - 2017-07-16

    A bit of testing has shown that the FVR Module needs to be disabled prior to changing Reference voltage values. This info may or may not be in the datasheet as I did not look. . The following is example code that works on 16F1829 and should also work on other chips.

    Note that using an FVR reference voltage of 1.024 works perfectly well on the 16F1829 with the adval reaching 255 at about 1.024V. I used a 10K pot as the signal source.

    NOTE: Using FVR 1.024 with ADC is not officially supported by Microchip. Use at your own risk.
    .

    ''' Test Code for Changing FVR On-The-Fly
    ''' William R
     ;
     #chip 16f1829,16
     #config FOSC_INTOSC , WDTE_OFF , PWRTE_OFF , MCLRE_OFF
     #Config CLkOUTEN = ON
    
      ;Software I2C For LCD
     #define I2C_MODE Master
     #define I2C_DATA PORTB.6
     #define I2C_CLOCK PORTB.5
     #define I2C_DISABLE_INTERRUPTS ON
    
     #define LCD_IO 10
     #define LCD_I2C_Address_1 0x7E ; default to 0x4E
     #define LCD_SPEED FAST
     CLS
    
    Do
       '// Use VCC as Referenec
       FVRCON = 0 '//Disable FVR
       ADPREF1 = 0
       ADPREF0 = 0
       ADVal = ReadAd(AN2)
       Locate 0,0 : Print AdVal : LCDSpace 3
       Locate 0,6 : Print "VREF = Vdd"
    
       '// Use FVR for next three reads
        ADPREF1 = 1
        ADPREF0 = 1
    
       '// use FVR 4096 as Reference
       FVRCON = 0  ' // Disable/reset  FVR
       FVRCON = b'10000011'   '// Change to 4.096 and enable
       ADVal = ReadAd(AN2)
       Locate 1,0 : Print AdVal : LCDSpace 3
       Locate 1,6 : Print "VREF = 4.096"
       Wait 100 ms
    
       FVRCON = 0  ' // Disable FVR
       FVRCON = b'10000010'  '// Change to 2.048 and enable
       ADVal = ReadAd(AN2)
       Locate 2,0 : Print AdVal : LCDSpace 3
       Locate 2,6 : Print "VREF = 2.048"
       Wait 100 ms
    
       FVRCON = 0  ' // Disable FVR
       FVRCON = b'10000001'   ' Change to 1.024 and enable
       ADVal = ReadAd(AN2)
       Locate 3,0 : Print AdVal : LCDSpace 3
       Locate 3,6 : Print "VREF = 1.024"
       Wait 100 ms
    
    Loop
    
     

    Last edit: William Roth 2017-07-16
  • Anobium

    Anobium - 2017-07-16

    Revised library and code.

    #chip 16F1828, 32
    
    'this will set the ADC to the FVR source.
    #define ADReadPreReadCommand   ADCON0 = ADCON0 or b'01111100'
    
    ADFVR_Initialize ( ADFVR_2x )  'set to 2.048
    do
      readadval = readad ( an0 )
      'do youR stuff
    
    loop
    
     

    Last edit: Anobium 2017-07-16
  • Daniel Cioba

    Daniel Cioba - 2017-07-16

    OK , with William's program ( setting registers manualy ) I can change Vref 1 , 2 , 4V , and is working as it should be .

    But Anobium , using #define ADReadPreReadCommand ADCON0 = ADCON0 or b'01111100'
    and ADFVR_Initialize ( ADFVR_2x ) I just got one "garbage" value around 450 which won't change even if the input is grounded , ADC is not working properly .

     

    Last edit: Daniel Cioba 2017-07-16
  • Anobium

    Anobium - 2017-07-17

    We have a baseline that works with Bill's code. Excellent.

    I made an error in asking you to add ADReadPreReadCommand .

    Please adapt the attachments for you chip. Please ensure you put the .h in your include folder.

    I have attached the same library and two test programs. The first test program used Bill's code as the baseline. I am using the LCD Serial Redirection to an ANSI terminal to keep the original code and I have changed the ADC port for my Xpress board. The second program uses the library.

    The results of FVR001

    The results of FVR002 as same input value as FVR001

    Give this a test please. I would lilke to resolve.

     

    Last edit: Anobium 2017-07-17
  • Daniel Cioba

    Daniel Cioba - 2017-07-17

    Ok , I tested , FVR001 is changing Vref and is working ok , FVR002 is not , the reading is good for Vref = 4V but not changing

     

    Last edit: Daniel Cioba 2017-07-17
    • Anobium

      Anobium - 2017-07-17

      Upload both ASM files please. This has me puzzled, as you can see it works here.

       
  • Daniel Cioba

    Daniel Cioba - 2017-07-17

    Here you have both test programs , just adapted for my setup .
    In this case it seems that simulation is far far away from reality .

    Edit: Sorry , I made myself a mistake , Vref non selectable was allways at Vdd not 4V , but i only have 4,6V power supply and Vref = 4,096 is in fact allmost 4,4V on this chip , they are pretty close. So internal reference can't be selected at all with GC instructions .

     

    Last edit: Daniel Cioba 2017-07-17
    • Anobium

      Anobium - 2017-07-17

      Even more puzzled.

      But, I have a 16F1829 which is the larger memory version of your chip. The code works here. See below.

      When VREF=1.024 and the returned value was 255 the measure voltage is 1.020 - which is acceptable. note the VDD on this board is 4.80v so you will see smaller values for the first two values.

      My code is attached.

      Please ensure you have updated the ADC library. If you think you have the correct one and you want to verify please post.

       

      Last edit: Anobium 2017-07-17
  • Anobium

    Anobium - 2017-07-17

    Attached is code and HEX for your microcontroller, your LCD and ADC port. Based on your tests I have compiled and provided you the HEX.

    Worth a shot. If this works then then it points to a setup file somewhere.

     

    Last edit: Anobium 2017-07-17
  • Daniel Cioba

    Daniel Cioba - 2017-07-17

    Sorry , not changing , same value for ADFVR_OFF , 4x , 2x , 1x , still using Vdd as Vref , the library is from the archive you uploaded , it was made ( last time modified ) in 16-07-2017 .
    These microcontrollers are for sure very closed related like many more that use FVR register , but are not identical ... since don't share the same datasheet .

     

    Last edit: Daniel Cioba 2017-07-17
  • Anobium

    Anobium - 2017-07-18

    Oh yes. These registers and bits can be tough to get settled.

    Please compile the attachment - send me the HEX and ASM. I am trying to understand the differences.

    You are good to keep trying these tests - but, we always need to test to add a new library. :-)

     

    Last edit: Anobium 2017-07-18
<< < 1 2 3 > >> (Page 2 of 3)

Log in to post a comment.