• AVR Freaks

AnsweredHot!ADC Block Wrong Readings

Author
FilippoMonti
Starting Member
  • Total Posts : 31
  • Reward points : 0
  • Joined: 2017/11/03 03:10:15
  • Location: 0
  • Status: offline
2019/06/04 00:13:37 (permalink)
0

ADC Block Wrong Readings

Dear Lubin,
 
I am proceeding with my project. I have re-designed the PCB and changed the signal routing. So that I had to change the ADC channels accordingly.
Nothing else is changed on the software, only the ports.
 
V01 I used: AN2, AN6 and AN11
V02 I switched to: AN9, AN10 and AN14
 
The signals sampled are the same and the hardware part is the same as before, just changed the rounting.
The problem is that in V02 I have wrong readings on AN9 and AN10, they are always at 1023 (10bits) even if in the board I have 0V. Also changing the voltage on the board, the reading still 1023. AN14 works properly, though.
 
In V01 all worked properly.
 
Do you have some advice? Maybe I have some wrong setting? All the doc are attached.
Thank you.
 
Filippo

Attached Image(s)

#1
Lubin
Moderator
  • Total Posts : 359
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: ADC Block Wrong Readings 2019/06/04 01:09:23 (permalink)
0
Hi Filippo,
 
I am not finding error so far. Generated code seems ok and changes from version with AN2,6,11 is correct.
Pin AN9, AN10 and AN14 are cleared from other function.
 
If it is a new board, maybe perform check with a blinking led just to make sure your external clock is working properly at 32Mhz.
You might try toggling lines AN9 and AN10 to check the board routing (removing the ADC block, protecting the original analog source first)
 
Lubin
#2
FilippoMonti
Starting Member
  • Total Posts : 31
  • Reward points : 0
  • Joined: 2017/11/03 03:10:15
  • Location: 0
  • Status: offline
Re: ADC Block Wrong Readings 2019/06/04 05:34:22 (permalink)
0
Dear Lubin,
 
thank you very much.
I will perform tests on my board then. I am wondering if the ADC of the dsPIC is damaged.
I will let you know, just for forum's completeness of the topic.
 
Thanks,
Filippo
#3
FilippoMonti
Starting Member
  • Total Posts : 31
  • Reward points : 0
  • Joined: 2017/11/03 03:10:15
  • Location: 0
  • Status: offline
Re: ADC Block Wrong Readings 2019/06/05 23:00:13 (permalink)
0
Dear Lubin,
 
I have tested the physical connections on the board and the signals and they are ok. Also the external clock is ok.
 
Then, since I have channels AN0 and AN1 not connected, I have tried to enable them in Simulink but not linked to some functionality. Then the other inputs AN9 and AN10 start to work properly.
It seems strange to me, I would like to understand the situation. I have read the datasheet but nothing is said. But, I have noticed from the schematic on the datasheet that AN0 and AN1 have a special role in the CH0 of the ADC in some way. I don't know if the thing is correlated.
 
Summary:
 
AN9 and AN10                  --> Both don't work
AN0, AN9 and AN10          -->  All work
AN1, AN9 and AN10          -->  All work
AN0, AN1, AN9 and AN10  --> All work
 
I attach some photos and the slx file.
Can you help me to understand?
Thank you :)
 
Filippo

Attached Image(s)

#4
Lubin
Moderator
  • Total Posts : 359
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: ADC Block Wrong Readings 2019/06/06 02:01:30 (permalink)
0
Hi Filippo,
 
I do not have an explanation for the reported behaviour.
Code is Ok, No such errata on the ADC reported. I did not tested on hardware on my side.
 
I noticed you compare ADC output to a Threshold and report output on a digital output pin. 
Could you perform similar test, ploting ADC output curves ? 


I would suggest to remove the C8 digital output, add 2 blocks:
  • UART Configuration (set Tx on C8)
  • UART Tx-Matlab (connect both ADC output to 2 input of this block)
Then while running, connect C8 on a TTL UART <-> USB cable, and use the "picgui" interface (type picgui) in matlab to connect the UART and plot the incoming data stream.
 
You will get a much better view about what's happening with ADC outputs.
 
Lubin
#5
FilippoMonti
Starting Member
  • Total Posts : 31
  • Reward points : 0
  • Joined: 2017/11/03 03:10:15
  • Location: 0
  • Status: offline
Re: ADC Block Wrong Readings 2019/06/06 03:28:58 (permalink)
0
Dear Lubin,
 
C8 and C9 are connected to two LEDs. I can connect the UART through other pins that I have available.
I am setting up the things to catch the signals through the UART.
 
In the meantime, I have done the debug through MPLAB. I have put a Breakpoint where there is the acquisition of the ADC in the C code.
 
AN9 & AN10             Reading: 1023 always on both channels
AN0 & AN9 & AN10   Reading: proportional to input voltage
AN1 & AN9 & AN10   Reading: proportional to input voltage
 
I will update the thread with the UART acquisitions.
 
Thank you

Filippo
#6
FilippoMonti
Starting Member
  • Total Posts : 31
  • Reward points : 0
  • Joined: 2017/11/03 03:10:15
  • Location: 0
  • Status: offline
Re: ADC Block Wrong Readings 2019/06/06 23:01:34 (permalink)
0
Dear Lubin,
 
I have done the test with the UART and picgui. I have saved the plots.
The conditions are:
 
- plots report acquisitions of AN9 (Blue) and AN10 (Red) through picgui
- the inputs of AN9 and AN10 are manually sweep from an external voltage supply
 
Results:
 
AN0, AN9, AN10 active      -->    AN9, AN10 good (plot "AN0_AN9_AN10_UART")
AN9, AN10 active              -->    AN9 not working and stucked to 1023, AN10 good (plot "AN9_AN10_UART")
 
The LEDs connected to C8 and C9 physically confirm this thing.
It seems that the channel AN10 is linked in some way to AN0 and/or AN1. I have not tried with other channels.
 
Another thing I have noticed is that when a channel work, the signal is not so clear due to physical noise. While, in the case that AN9 does not work, the signal is very very stable and fixed to 1023. Like if it is "emulated".
 
Do you have ideas?
 
Thank you
 
Filippo

Attached Image(s)

#7
Lubin
Moderator
  • Total Posts : 359
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: ADC Block Wrong Readings 2019/06/07 00:47:43 (permalink) ☼ Best Answerby FilippoMonti 2019/06/18 04:43:37
0
Hi Filippo,
 
Thanks for your illustration. 
 
My setup for this chip was old and did not started when I did a quick test. Thus I might give another try later using another chip of the same familly.
 
Still, the generated code seems correct ; I can hardly explain the behaviour you noticed. 
If I or anyone can reproduce such issue, I would definitly look again at the code. 
The workaround is to keep going with one ghost conversion (AN0 or AN1 or maybe any other below 9?) 
 
Don't you have any cross talk between AN9 and AN10 ?
Maybe the input resistance of your analog channel is higher than 10k ? You might try increasing the input impedance set in the ADC block which will increase the sampling time. 
One alternative setup is within the ADC Trig and Time Step: Stet the option: Samples and Conversions are "stretched to fit exactly previosu time step". This will provide you with the maximum sampling time for each channels.
 
picgui is a much better solution for testing than any led togling ;-).
 
Lubin
#8
FilippoMonti
Starting Member
  • Total Posts : 31
  • Reward points : 0
  • Joined: 2017/11/03 03:10:15
  • Location: 0
  • Status: offline
Re: ADC Block Wrong Readings 2019/06/18 00:44:33 (permalink)
0
Dear Lubin,
 
apparently I have solved the issue of the ADC by setting Samples and Conversions are "stretched to fit exactly previosu time step".
 
Do you have an explanation on the reason that led this setting to solve the issue?
 
Thank you for your support.
 
Filippo
#9
Lubin
Moderator
  • Total Posts : 359
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: ADC Block Wrong Readings 2019/06/18 01:35:34 (permalink) ☄ Helpfulby FilippoMonti 2019/06/18 04:43:43
0
Hi Filippo,
 
Thanks for your feedback.
 
The "stretch to fit exactly previous time step" ADC option increase the sampling time of all ADC input.
It makes the overall sampling + conversion time to fit with the time step (thus the time step is triggered at the end of the last conversion, you save one timer)
 
Increasing the sampling time solve the issue ; it's typical from a high impedance on the ADC input line. I do not have further ideas based on the information above.
 
Lubin
 
#10
Jump to:
© 2019 APG vNext Commercial Version 4.5