News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

External ADC positive voltage reference for 12F1840

Started by david, Jul 15, 2021, 12:43 PM

Previous topic - Next topic

david

Hi All,
I'm dabbling with a Lipo ESR meter (battery resistance meter) and I'm currently using a 2V internal voltage reference but it would be convenient to use an external reference voltage.  I have no problems selecting 1 of 3 different internal voltages or the Vdd as reference but I can't connect an external pin as a reference input. 
I'm using RA0 for the ADC input and RA4 (AN3) as the external voltage reference but it always behaves as though I have Vdd as reference voltage.  Am I correct to assume the ext ref voltage pin should be configured as an analog input?
Relevant code for the 12F1840 as follows-

Declare Xtal = 16 'Internal OSC
OSCCON = %01111010    '16MHz=01111010, 4MHz=01101010, 8MHz =01110010
TRISA = %00011111     '
FVRCON=0               'FVR off
'FVRCON=%11000010      'FVR on and set for 2V
ANSELA=%00010001       'ANSA0, ANSA4 selected as analog
ADCON0=%00000001       'AN0 selected,ADC on
ADCON1=%11010010       'rt justified, Fosc/16, ext Vref
PORTA.5=1
OPTION_REG.7=0     'WPUs enabled
WPUA=8             'RA3 pullup enabled
Declare Hbus_Bitrate 1000    '100kHz, 400kHz, 1000kHz
SSPCON1=%00111000        'enable port, 7 bit address, master mode
Symbol OLED_W= %1111000  'OLED address and write
Symbol sw1=PORTA.3
Symbol pulse=PORTA.5


Any help would be appreciated but I fear it may be yet another senior moment.

Regards to all,
David

trastikata

Hello,

I am not sure why you connect the external reference to PORTA.4 since PORTA.1 (AN1) is the Vref pin?

Regards

david

Thank you!   Yes that would muck things up.
If you look at my first attachment (ADC.gif) it clearly shows AN3 pin  being connected to the Vref.  AN3 is RA4 or pin 3 on the 8 pin device.
If I had read more carefully I would have been confused at the conflicting data but probably tried both and been happy with the outcome.   Thanks again.

Cheers,
David

trastikata

#3
Quote from: david on Jul 15, 2021, 01:33 PMIf you look at my first attachment (ADC.gif) it clearly shows AN3 pin  being connected to the Vref. 

Ah, I see the source of confusion, usually on 8pin devices Vref is AN1 -  indeed in this case seems to be an Errata in the Datasheet.

david

Quote from: trastikata on Jul 15, 2021, 02:13 PMAh, I see the source of confusion, usually on 8pin devices Vref is AN1 -  indeed in this case seems to be an Errata in the Datasheet.

Hi,
I did check the available errata for this device but didn't see any mention of this error.  Sadly AN1 is not really an option for me as I want to retain the hardware I2C for the display.
Thanks again for sorting me out so quickly.

Cheers,
David

Giuseppe

The manual external vref must be connected on AN1 pin 6 of 1840. There is no possibility to move it.
Could you change the I2c pin?

david

Hi Giuseppe,
Thanks for your reply.
Yes I accept the ext Vref is only available via AN1 and not AN3 as shown in the ADC diagram. Do you think they would send a cap or T-shirt if I politely pointed out their error?

I've not yet tried running these little OLED displays off software I2C.  I'm sure it may be possible but certainly not at the 1MHz rate I'm doing with the hardware I2C port.
I have since found a way to work with the internal Vref sources which is working out well so the panic is over.

Best regards,
David

Giuseppe

From the photos you put already manage the display.
But do you manage it with the 12f1840?

top204

Even with Declare HBus_Bitrate set for 1MHz, the compiler's built-in I2C commands will not always reach it, because they have a lot of safeguards built in that slow things down. These are always required with built-in commands to try and stop lockouts if something goes wrong with the interface.

To achieve 1MHz I2C, you will need to create your own procedures that talk to and control the I2C bus, because they can remove the safeguards and run at full speed. You will be also be surprised at how fast software I2C can be if you create your own procedures for it by toggling pins.
 

david

Hi Giuseppe and Les,
Yes the little 12F1840 is great for small projects with the I2C display and the driver plus font table is under 1k but then the print is pretty small. No graphics or variable font sizes but they are easy to write to.
Les - you could well be right and I initially started with the standard I2C rate of 100kHz but noticed it was relatively slow when clearing the random start up status of the display memory.  I then tried 400kHz and it was definitely faster so I lived with that for a while before changing to 1000kHz. This was so fast there was no obvious sequence in clearing the display, just a blink but I now clear the display before enabling the OLEDs anyway so it's very slick. Whatever speed it's doing it's certainly fast enough. Software drive of the display would add a bit more flexibility and I would like to try it before long.
BTW - I have attached the proposed final schematic of the battery ESR meter I was dabbling with.  The micro generates a 12mS drive to the gated current sink and also samples a biased voltage before and during the current pulse.  It's a little odd in that it's AC coupled but the time constant is long enough to provide an accurate pulse amplitude to the ADC input.  I'm running the ADC int ref voltage at 1V which is considered too low to meet specs but for a fixed supply voltage and temperature it's acceptable. This gives 1mV resolution and hence with a 10A current pulse it's good for 100uR resolution which is more than I need.  The other waveform is a simulated -ve going 90mV battery pulse as seen by the ADC input. Cursor positions are roughly where sampling takes place.

Cheers,
David

trastikata

Quote from: david on Jul 17, 2021, 12:32 PMI initially started with the standard I2C rate of 100kHz but noticed it was relatively slow when clearing the random start up status of the display memory.  I then tried 400kHz and it was definitely faster so I lived with that for a while before changing to 1000kHz.

Hello David,

just a pointer - I saw your pull-up resistors are 4.7k which is a bit high for 1MHz I2C bus.It might work now, but you could have problems in future. For high speed I2C (still depending on the total bus capacitance) use around 2k resistors.

david

Quote from: trastikata on Jul 17, 2021, 03:17 PMHello David,

just a pointer - I saw your pull-up resistors are 4.7k which is a bit high for 1MHz I2C bus.It might work now, but you could have problems in future. For high speed I2C (still depending on the total bus capacitance) use around 2k resistors.

Yes I totally agree.  I'm aware that the active low of the signal will be fast but the passive high is dependent on the pull-up resistor value and any track/input capacitance.  The circuit is on breadboard at the moment and every time I power it up I think I must change those resistors but never do. 
I appreciate the warning.

Cheers,
David