PDA

View Full Version : "Honey, my PIC ADC pin sagged my peak detector voltage!"



HankMcSpank
- 9th February 2011, 09:58
Ok, to appraise you all, my signal path is....


audio signal in->Half wave rectifier (opamp type)-> 500R resistor-> Diode-> 4.7uf Cap (to ground)-> PIC ADC pin

(in other words a peak detect type circuit)

With the signal path above unconnected to the PIC ADC Pin, I see a nice low ripple DC level moving between 0V & 5V on my scope (ie reflecting the size of the incoming audio) ...but when I connect the PIC ADC pin up - much more ripple & the DC level only gets up to about 2.8V.

The PIC ADC pin is loading the peak detector capacitor :-(

Now I know the traditional solution would be to put a voltage follower in between the output of the cap & the input of the ADC pin, but I really don't have room for an extra opamp (yes I know they're small, but every square millimetre of my board is chocka!)


I'd have imagined that a PIC would have an ADC that's high impedance - & not loaded the cap significantly?

Any top tips/workarounds gratefully recieved as I'm presently pouring light fluid on the circuit - and if it's not sorted by midnight, it's gonna resemble a car in the main square in Cairo.

HankMcSpank
- 12th February 2011, 13:59
Anyone know what to expect (voltage wise) on an analogue input pin configured for ADC with nothing connected? - I'm seeing 5V on mine (as seen on a DVM - but also I'm getting an ADC value of 255 with nothing connected to the pin - I was expecting 0?)

When I connect up say a pot wiper - it reads the incoming coltage properly....I'I'm curious to know what's going on internally at a low level electronics inside?

Edit: It seems this PIC (16f1828), doesn't disable PORTC weak pullups at initialisation, it should, this from the datasheet...

"All pull-ups are disabled on a Power-on Reset"

however I've just added the explicit line WPUC = 0 & now everything is reading 0 as expected on my Analogue/ ADC pins

mackrackit
- 12th February 2011, 14:20
5 volts if the the chip is running on 5 volts and not changing the reference and using 8 bit resolution will equal 255...

HankMcSpank
- 12th February 2011, 15:52
5 volts if the the chip is running on 5 volts and not changing the reference and using 8 bit resolution will equal 255...

Yes I know 5V = 255, but what I was getting at...until I set all the portC pullups disabled (which they should have been at power up anyway), in the absence of an incoming analogue signal, I was geting an ADC reading of 255 (because there was 5V residual on the unconnected pin)...soon as I disable pullups, I got the reading I was expecting ...ie an ADC reading of 0.

Jerson
- 12th February 2011, 17:27
Yes I know 5V = 255, but what I was getting at...until I set all the portC pullups disabled (which they should have been at power up anyway), in the absence of an incoming analogue signal, I was geting an ADC reading of 255 (because there was 5V residual on the unconnected pin)...soon as I disable pullups, I got the reading I was expecting ...ie an ADC reading of 0.

This is expected behaviour. Pullups will put 5V on the ADC input. Unless you meant to ask something else.....

HankMcSpank
- 14th February 2011, 08:26
This is expected behaviour. Pullups will put 5V on the ADC input. Unless you meant to ask something else.....

That's just it - I never asked for or wanted pullups on the ADC pin, so was puzzled when 5V appeared there in the absence of a signal. The datasheet say WPUs are disabled at power up (& my code didn't enable them), so there shouldn't have been 5V on the ADC pin.....what I had to do in the end was disable them myself in my code - even though they should be disabled by default.

In my opinion there's a problem with the PIC16f1828's startup settings vs what Microchip say in their associated datasheet.

rmteo
- 14th February 2011, 15:07
In my opinion there's a problem with the PIC16f1828's startup settings vs what Microchip say in their associated datasheet.
Why don't you contact MCHP, inform them of your findings and have them confirm that the datasheet is in error (or perhaps the datasheet is correct and that you may have discovered a silicon error)?

HankMcSpank
- 16th February 2011, 14:48
Why don't you contact MCHP, inform them of your findings and have them confirm that the datasheet is in error (or perhaps the datasheet is correct and that you may have discovered a silicon error)?

For a few minutes I was overwhelmed by the onset of "global community spirit" to do the right thing ...so visited Microchip's website ...they've even produced a video about how to report back silicon errors.....I grew a beard to rival the guitarists in ZZ Top watching it, & then threw my wife's purse at the screen when it got to the bit about "& having followed the 11 steps we've just outlined, unless you attach scope traces we won't believe you & just assume you're a pleb"

I'm now hoping anyone similar 16f1828 problems will find this thread via Google.

Darrel Taylor
- 16th February 2011, 18:05
Edit: It seems this PIC (16f1828), doesn't disable PORTC weak pullups at initialisation, it should, this from the datasheet...

"All pull-ups are disabled on a Power-on Reset"

however I've just added the explicit line WPUC = 0 & now everything is reading 0 as expected on my Analogue/ ADC pins

Hank,

Weak Pull-ups are disabled at power-up / Reset.
They are turned on by clearing WPUEN (OPTION_REG.7).
All of the WPUx registers are enabled at power-up, so when you clear the WPUEN bit, they all come on unless you specifically disable individual pins WPUC.x.

Does your code change OPTION_REG?

HankMcSpank
- 16th February 2011, 19:41
Hank,

Weak Pull-ups are disabled at power-up / Reset.
They are turned on by clearing WPUEN (OPTION_REG.7).
All of the WPUx registers are enabled at power-up, so when you clear the WPUEN bit, they all come on unless you specifically disable individual pins WPUC.x.

Does your code change OPTION_REG?

Hey Darrel,

this is the point in the proceeedings where I should lie profusely, but nope....

"It's a fair cop guv"

Yes, I do use WUPs on PORT B, so :o yes I have...



OPTION_REG.7 = 0


....which of course, then means all ports are enabled & I need to disable by port.

My excuse is that my code is a heavy cut/paste from a former program, so I didn't enter every single line manually......but, that's lame so I offically declare myself a pleb.

Great spot....... & thanks for chiming in to correct.