Ghost Glitch in hardware, software, ARG!!?

magudaman

Member
So I have a hall current sensor that in debug mode with just a readadc10 command gives a nice steady 512 from my 08m picaxe. As soon as I start running my full fledged code that has one other ADC running and a PWM output that same sensor in the debug mode now reads around 420 about 90% of the time and reads 620 on the rest of the reads. Averages out to about 440.

My code doesn't change this reading that I can see and I can't figure out what the heck is happening. I had this unit working a while back and now this messes my code all up because it expects zero to be at 512.
 

westaust55

Moderator
It might help folks determine possible causes if you provided moreinformation.

You state:
I had this unit working a while back and now this messes my code all up because it expects zero to be at 512.
What precisely have you changed since it was working a while back.

My code doesn't change this reading that I can see
nor can we see if that is the case without the program listing - is there an overlap in your program between a word variable for the ADC and a byte variable for some other task?

Is the PWM generating electrical/RF noise that is affecting the analogue signal from the hall effect device?

Posting the following will be helpful:
  1. A link to the hall effect current sensor,
  2. A copy of your schematic,
  3. Program code listing, and
  4. Clear photos of the project showing proximity of wiring for ADC and PWM etc
 

g6ejd

Senior Member
This almost certainly due to power supply regulation, supply filtering or device characteristics.

1. Do you have a capacitor, say 10uF across your supply e.g. between +5V and Gnd?
2. Do you have any de-coupling capacitors across the supply, say 0.01uF, perhaps more than 1 at opposite ends of your PCB.
3. There is likely to be some interaction between a device read and the next read if the device has not had enough time to settle, check the device data sheet to see how long inter-reads can be, could be you need to add a delay after the device read, perhaps 100mS, maybe more maybe less, which is what you have been doing with your debug command in effect.
 

geoff07

Senior Member
PWM can play havoc with ADC inputs. You need a rock-solid PSU with a low impedance (i.e. big caps and big wires or traces) and you need to ensure that the PWM current does not go through the ground circuit of the ADC pin.
 

magudaman

Member
Sorry for the delay in response. I believe this problem maybe have been happening before but I adjusted the timing to compensate.

I have the output of my hall device running through a 10K resistor to allow my to short it to ground to function as a reset button. It seems with the ADC samples that port at around 1hz I don't see any drop, but when it is running in the program doing 60hz or so it pulls that signal down a little bit. It seems to remain linear so I just adjusted my codes zero point.

I think my PSU is pretty solid. I'm using a high quality DC-DC unit good for up to 400ma and I only using about 50ma tops.

Thanks for all the input guy!
 

westaust55

Moderator
Another thought . . .

What is the PWM output driving?

The PWM output waveform is in effect a square wave and if driving a motor or other inductive load in close proximity to the hall effect device (which is a magnetic field sensor) then there could be interaction.
 

Armp

Senior Member
As stated in post #2

Posting the following will be helpful:

A link to the hall effect current sensor,
A copy of your schematic,
Program code listing, and
Clear photos of the project showing proximity of wiring for ADC and PWM etc
I don't think we can help much without some detail...
 

hippy

Technical Support
Staff member
I have the output of my hall device running through a 10K resistor to allow my to short it to ground to function as a reset button. It seems with the ADC samples that port at around 1hz I don't see any drop, but when it is running in the program doing 60hz or so it pulls that signal down a little bit.
As suggested, details of the sensor, your circuit diagram and actual program used will help.

Varying ADC is in my experience usually down to reading the wrong ADC pin; it's either a floating value or you see the result of the decaying sample and hold capacitor voltage having read some other ADC channel first.

Analogue sources can be affected by the execution of READADC but in most cases this would be minimal and certainly not of the scale seen, nor 'jumping all over the place'.

When it's suspected there is some interaction - say PWM affecting ADC - the simple course is to disable the PWM and see if the affect goes away or not. It's also worth creating test programs which test just a specific aspect of the circuit to determine what works and what doesn't, add more to those to determine when issues start to occur. That usually gives some pointer to what the underlying problem is.
 

Goeytex

Senior Member
As stated in post #2

I don't think we can help much without some detail...
@MADUGAMAN

As a relatively new poster, you need to understand that the level of the help you can get is related to the level of the
information you are willing to provide. With no code or schematic to look at about the best you can hope for is some educated
guesses. Some very knowledgeable folks won't even attempt to help if the person requesting help is unwilling to post the code
& schematic.

My "guess" is that if you put your DVM on the ADC pin in question and read the voltage you will see the voltage jumping around.
But with no schematic to look at I am unwilling to guess any further. Help us to help you and take the time to post your code
and a good schematic. Also, a clear photo is many times very helpful.
 

g6ejd

Senior Member
Switch your DVM to AC and a low range, 20 or 50mV and measure your DC supply line, see what you get - zero voltas, I doubt it. You might think it's a nice smooth supply, but it's probably not. IF not, then this is almost certainly your problem - PSU and importantly circuit smoothing issues. What do you have on the PICAXE adjacent to its pins for supply decoupling - need to see your circuit.

Failing that, why not increase the size of the 10K R to say 100K, probably won't affect the operation, as the PIC input current is so low. Do you think your code is maintaining that Pin as an input and are the pull-ups enabled, suggest you disable them if so.
 

MPep

Senior Member
Switch your DVM to AC and a low range, 20 or 50mV and measure your DC supply line, see what you get - zero voltas, I doubt it. You might think it's a nice smooth supply, but it's probably not. IF not, then this is almost certainly your problem - PSU and importantly circuit smoothing issues. What do you have on the PICAXE adjacent to its pins for supply decoupling - need to see your circuit.
Good call. This is the best way to find if you really do have a rock-solid supply.

Failing that, why not increase the size of the 10K R to say 100K, probably won't affect the operation, as the PIC input current is so low. Do you think your code is maintaining that Pin as an input and are the pull-ups enabled, suggest you disable them if so.
If you search for ADC and potentiometer resistance, and the manuals, you'll find that the maximum recommended value is 10k. Do not go higher.
 

Armp

Senior Member
sensor in the debug mode now reads around 420 about 90% of the time and reads 620 on the rest of the reads.
The lack of randomness indicates it's probably not noise related. Could possibly be coding error, wiring error, the PWM or the other ADC.

IMHO Just pointless speculation until we hear from the OP.... Time for a beer.
 
Last edited:

Goeytex

Senior Member
A bit of ripple on the DC supply will not necessarily cause the ADC to jump around that much. If the same supply is used for the Picaxe and the Hall sensor it will tend to cancel out. For example, I measure 30 t0 40 mv of ripple using the USB Vbus as the supply for both a Pot feeding an ADC and a Picaxe. The variation only is +- 2 LSB with 10 bit ADC. For the ADC to vary as much as the OP says it is likely something other than supply ripple.
 
Last edited:
Top