HC908JK8CPE: Severe EMI or incorrect ADC code?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HC908JK8CPE: Severe EMI or incorrect ADC code?

3,140 Views
AveryZ
Contributor I
Hey Guys,
I have a circuit which used to work flawlessly but I started messing around with it and now I am having a problem with what I think is severe EMI. I am using a standard breadboard (the really good pale yellow kind with V/G rails along both sides) and trying to do ADC conversions on two pins about every 500ms. If i use a pulldown resistor on both pins, I get 0 and 0 as the values (correct operation) but as soon as voltage starts getting applied to one of them, the other one goes crazy as well!
My code is as follows:
1) The program recieves an SCI Recieve interupt and get a 'S' char... it then executes:
START_ADC_CONVERSION(0x06); //Start conversion on PTB2
LIGHT_LEVEL = GetADCValue();
START_ADC_CONVERSION(0x07); //Start conversion on PTB3
DISTANCE_LONG = GetADCValue();
char GetADCValue(void) {
while(!ADSCR_COCO) {} //Wait until data is ready
return ADR; //return the value
}
2) The program then sends these values back in a 4-byte packet, as follows:
//Now transmit a packet containing all the sensor data
TransmitChar('S'); //Indicate that this is a sensor detail packet
TransmitChar(LIGHT_LEVEL);
TransmitChar(DISTANCE_LONG);
TransmitChar(END_CHAR); //Indicate end of packet transmission
With both items grounded, this is the (as expected) output:
83 0 0 69 (S 0 0 E)
83 0 0 69 (continues forever...)
With voltage (literally directly from V) applied to only ONE of the pins, this is the crazy output over a few seconds:

83 255 0 69 (seems about right, but on the wrong pin) (500ms)

83 255 255 69 (where did the 255 on the second input come from?) (1000ms)

83 0 255 69 (now it switched!?) (1500ms)

83 0 255 69 (still switched...) (2000ms)

83 0 71 69 (71, WHAT THE HECK!) (2500ms)

It goes on like that forever, just throwing crazy numbers everywhere. Has anyone seen anythign like this before? Am I the victim of EMI here or is somethign else going on? I swear this same circuit used to work just fine...

-Avery



Alban edit: Added part number in subject line according to msgid=5172

Message Edited by Alban on 2007-03-13 10:35 PM

Labels (1)
0 Kudos
7 Replies

563 Views
erooll
Contributor II
What is your bus frequency?, the datasheet indicates that fadc should be set to approximately 1MHz, this can be done with ADICLK register, other thing is about configuration of selected channel, PTB2 and PTB3... if START_ADC_CONVERSION(value) its equal to ADSCR = value, then you need to write 0x02 for PTB2, and 0x03 for PTB3

Regards.
0 Kudos

563 Views
AveryZ
Contributor I
My bus is 2.4576mhz (using an external 9.8404 osc) and I use a prescaler of 4 to give me a 614khz ADC frequency, which is the only value that is within the range defined as acceptable by PE. The comments in the code about PTB2/PTB3 when i was actually testing on 6 and 7 were just because I had been playing around with which pins to use; believe me, I wish that was the problem!
 
I am starting to think there must be some kind of timing issue. It will often copy the value it just read from one pin onto the other pin! And sometimes it is working great, reading correctly in the right spot, but then it will just miss 3 readings in a row (or misreading and sending a 0 instead of the value) and then return to normal.
 
This is very puzzling because I had this EXACT same setup working on another processor (GR8), and they are similiar enough.
 
-Avery
0 Kudos

563 Views
bigmac
Specialist III
Hello Avery,
 
It is probably stating the obvious, but have you tried another JK8 device, just in case the first one is faulty.  The analog inputs may be susceptible to transients, unless there is protection circuitry present.  I assume from your previous post, you have already tried different pairs of analog channels.
 
Regards,
Mac
 
0 Kudos

563 Views
bigmac
Specialist III
Hello Avery,
 
Could there be any possibility that the applied voltage could exceed Vdd of the MCU?  My understanding is that this can lead to interaction between ADC channels.  You could try the same test with one of the inputs set to Vdd/2, and with the other connected to ground, and see if you get a similar result.  Perhaps there might also be a possibility of 50/60 Hz hum present on the test voltage which could cause it to exceed Vdd - you could check this out with an oscilloscope.
 
Regards,
Mac
 

Message Edited by bigmac on 2007-03-1412:52 AM

0 Kudos

563 Views
Nabla69
Contributor V
Hi,

I confirm that current injection in ADC pins does influence global readings.
If voltage is above Vdda, the voltage reference for the conversion is altered.

Also there is cross-talk between pins. There is no product mentioned in the post, so it could not be specified for your device. The cross-talk is limited by talking physically pins far from each other.
There are Application Notes detailing both the ADC jargon and how to optimize their use.

Alfreda.
0 Kudos

563 Views
AveryZ
Contributor I
I tried increasing the stack size, didn't do the trick.
 
I tried decreasing the test voltage (signifigantly) to make sure it wasn't going over, no luck - same spastic output.
 
I tried switching the pins to each be on an opposite side of the MCU, since that is as far away as they can get from one another, no luck...
 
The MCU is a JK8 (CPE), I should have mentioned that in my origional post :smileyhappy:
 
-Avery
 
0 Kudos

563 Views
HamNcheez
Contributor I
Try increasing your stack size as this usually is the culprit when I have erratic ADC readings.
 
Best,
HamNcheez
0 Kudos