Author Topic: PICs: ADC is a "Tad" difficult  (Read 6963 times)

0 Members and 1 Guest are viewing this topic.

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2850
  • Country: se
  • Country: Broken Britain
Re: PICs: ADC is a "Tad" difficult
« Reply #25 on: June 06, 2018, 08:34:52 pm »
Oh dear, scope time?
.  That took much longer than I thought it would.
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: PICs: ADC is a "Tad" difficult
« Reply #26 on: June 07, 2018, 10:09:32 am »
Yippee!  I think I have it!

To check that the readings from the PIC were accurate, I permanently had my Fluke 87V DMM connected to the LM35. Today, I unplugged the DMM and hey presto! The "first reading error" vanished. I plugged it back and the error returned even when the DMM was turned off!

When I measured the DMM it came up as "infinite" resistance (though it's about 11MOhms when on) but 60pF capacitance, again even when off. As an aside, I have a memory of inaccuracies creeping in when I changed the range from Volts to mV.

Could it be that this extra capacitance caused the error? 60pF doesn't sound a lot.


BTW I'm intrigued by "scope time"? Pray tell.
« Last Edit: June 07, 2018, 01:14:04 pm by PerranOak »
You can release yourself but the only way to go is down!
RJD
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: PICs: ADC is a "Tad" difficult
« Reply #27 on: June 07, 2018, 03:58:32 pm »
hm.. was having a problem with erroneous readings, reading a potentiometer

it was like the pot was logarithmic, while it was marked and measured as a linear one.

Connected the scope, i saw a pulse wave with fast rise time and slow/exponential curve fall time at a divisor of the sample rate (SR/n of channels)

duh moment, i forgot to set the channel as an analog input, so when it was its turn to be converted the peripheral priority on the input would override the pin settings for the time of conversion, giving obviously wrong errors
 

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2850
  • Country: se
  • Country: Broken Britain
Re: PICs: ADC is a "Tad" difficult
« Reply #28 on: June 07, 2018, 04:26:44 pm »
Yippee!  I think I have it!

To check that the readings from the PIC were accurate, I permanently had my Fluke 87V DMM connected to the LM35. Today, I unplugged the DMM and hey presto! The "first reading error" vanished.

Yes, that is it, I didn't know you were leaving the DVM permanently connected, I wouldn't have known it was 60pF, but it's quite normal for the outputs of small devices to not be able to drive even small caps or cables.

Quote
Could it be that this extra capacitance caused the error? 60pF doesn't sound a lot.

Well page 14 of the LM35 says:
"Like most micropower circuits, the LM35 device has a limited ability to drive heavy capacitive loads. Alone, the
LM35 device is able to drive 50 pF without special precautions. If heavier loads are anticipated, isolating or
decoupling the load with a resistor is easy"


Quote
BTW I'm intrigued by "scope time"? Pray tell.

Time to do checks with a scope, you'd hopefully have seen the LM35's slight oscillations at power up, and quite a few more checks.
In theory, the ADC should be ready for GO in just a couple of us from turn ON, just the ACQ time would be enough. Don't know about the FVR start time.
« Last Edit: June 08, 2018, 10:45:07 pm by StillTrying »
.  That took much longer than I thought it would.
 
The following users thanked this post: PerranOak

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: PICs: ADC is a "Tad" difficult
« Reply #29 on: June 08, 2018, 10:54:13 am »
I have learned something here. I have always assumed that meters had no effect at all on a circuit - lesson learned.

Why do all my problems stem from not reading the datasheet properly! Will I ever learn that lesson. I assumed that that section was for when you wanted to attach the LM35 to a long cable - still, if I'd read it properly …

I hadn't used the scope yet as I got caught-up in this error but I will now.

BTW capacitance in my "Kryptonite" I've never really got to grips with the subtler effects of it. It seems that the experts are like wizards who sprinkle capacitors throughout a circuit like magic dust and then, "whoosh!" everything works! It seems like magic because I don't get it. Sure I know what capacitors are and can "do all the calculations" (mostly!) but things like capacitative loading and such do throw me. I don't suppose you know of a good book that will help at all?

Thank you for your help and forbearance.
« Last Edit: June 08, 2018, 11:01:11 am by PerranOak »
You can release yourself but the only way to go is down!
RJD
 

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2850
  • Country: se
  • Country: Broken Britain
Re: PICs: ADC is a "Tad" difficult
« Reply #30 on: June 08, 2018, 10:43:25 pm »
"I have always assumed that meters had no effect at all on a circuit - lesson learned."

There are small invisible components all over the place, and once you add a test probe a few more are added, which ones are going to have a noticeable, usually bad! effect depends on impedances, current, speeds.

"BTW capacitance in my "Kryptonite" I've never really got to grips with the subtler effects of it."

Maybe think of it as a flat battery, when a voltage is first applied across it a high current flows while it charges, and stops flowing when it's fully charged, the larger the battery or the faster the voltage rises the higher the charging current will be.

Which method did you use to do binary to decimal in 8 bit ?
.  That took much longer than I thought it would.
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: PICs: ADC is a "Tad" difficult
« Reply #31 on: June 11, 2018, 12:07:15 pm »
Thank you for the continued help.

In fact, I wanted to use the full 10-bits from the ADC but wasn’t sure what the best way was. I set it to make the LSB the 8-bit part with the MSB as the 2-bit. I then took the LSB and subtracted 100 until it went negative: this gives the number of hundreds (put into a variable) and similarly for the tens, the ones being what’s left. I assume that this is the “normal” way? As for the MSB I then realised that this figure can only be 0, 1, 2 or 3. So, I used it as a loop counter to add 256 (2 to the hundreds, five to the tens, 6 to the ones) theMSB-number-of-times”. I reasoned that because the temperatures that I am using (room temp) it will be looping mostly zero or one time and never 2 or 3 whereas if I’d done it the other way (MSB as 8-bit and LSB as 2-bit) it would loop more frequently than just once much  more often - presumably, an average of 1.5 times?
You can release yourself but the only way to go is down!
RJD
 

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2850
  • Country: se
  • Country: Broken Britain
Re: PICs: ADC is a "Tad" difficult
« Reply #32 on: June 13, 2018, 11:49:39 pm »
Subtracting 1000 until you've gone to far, then subtracting 100 until you've gone to far, is the obvious way to do it but needs quite a bit of 2 byte math.

I tried to find a best way a few years ago, the best I came up with is looking at the first few binary bits one at a time. For a 12 bit binary, if bit 11 (2048) is set, you set the value 2 bit in the decimal 1000s, nothing in the 100s, value 4 bit in the 10s and value 8 bit in the 1s, the same can be done for the next binary bit 10(1024), before you have to start adding values into the decimal bytes. The last 5 binary bits can all be added into the decimal 1s. The decimal bytes then look something like 1,5,22,34 but fixing the few over tens is easy in 1 byte math.

The 12 bit (0-4095) version is 67 bytes and 80 CLKs, I don't think it can be done much faster.
« Last Edit: June 13, 2018, 11:54:36 pm by StillTrying »
.  That took much longer than I thought it would.
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: PICs: ADC is a "Tad" difficult
« Reply #33 on: June 15, 2018, 08:04:23 am »
Yes I see. It is adding with carry that causes the most difficulty so anything that minimises this is a boon.
You can release yourself but the only way to go is down!
RJD
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf