picavr
Active Member
Offline
Posts: 176
Thank You
-Given: 267
-Receive: 101
|
|
« on: August 14, 2012, 02:39:34 14:39 » |
|
hello every bady. i build a mini project with 18f4550 ,but when a test it in pcb ;evry analogic input attached to the gnd with aresistor (33k and less) give a result (perhaps) a noise but it s very big (33k give 100 (for 10bit adc resolution).
in the pcb (attached) only two input are used to demenstrate the problem but in the reality i use the 4052 ic.
i cant use a filter with capacity because i use many input (4ms max for each)
my native mcu family is atmel avr i would use 18f4550 because it s more disponible.
the same project with atmega32 give (0 for 33k /10bit) why its possible with atmega32 but with 4550 its not? javascript:void(0); is there a software solution ?javascript:void(0); with isis it give 0 (see file attached ,proton picbasic and eagle winpic800 are used)
|
|
|
Logged
|
|
|
|
Pasca
Newbie
Offline
Posts: 34
Thank You
-Given: 27
-Receive: 42
|
|
« Reply #1 on: August 14, 2012, 05:36:24 17:36 » |
|
Hi picavr, if you short circuit (0ohm) the analogue channel which value give the adc? If value is correct 0, you have to drive analog input with buffer op-amp.
Bye Pasca
Posted on: August 14, 2012, 06:18:07 18:18 - Automerged
I dont know pic 18f4550 so i read datasheet. Capter 21.1 said: "The maximum recommended impedance for analog sources is 2.5 kΩ."
Bye Pasca
|
|
|
Logged
|
More I know, more I need to know. Less I know, meglio sto!!!
|
|
|
picavr
Active Member
Offline
Posts: 176
Thank You
-Given: 267
-Receive: 101
|
|
« Reply #2 on: August 14, 2012, 06:09:30 18:09 » |
|
when i shurtcut the input analogic with 0 ohm it give arround (1) when i shurtcut the input analogic with 2.2k it give arround ( 2.2k is < rs(2.5k) it s not good if its normal in case of 18f i think the microchip mcu is not good because in avr series like atmega32 i can put the 33k in shorcut it s give arround ZERO where is the problem
|
|
|
Logged
|
|
|
|
Wizpic
Global Moderator
Hero Member
Offline
Posts: 1204
Thank You
-Given: 554
-Receive: 409
|
|
« Reply #3 on: August 14, 2012, 06:59:02 18:59 » |
|
Picavr Not sure what the voltage range is you want to measure or how you dislplay it, I don't have eagle installed so can't look at your pcb. The 18F4550 has 13 A/D channels why not jut use them instead of switching a 4052 ? If you need to measure with 4ms how are you displaying the data on the lcd and how do you know which channel your reading. I would use the 8 inputs on the pic then just display data on GLCD all 8 channels or 2 x 16 and just set a routine to display 2 or 4 channels on it.
ISIS is limited and does not pick or allow for noise issues this is whay it reads 0, The noise could be cuased by fast switching of the 4052 have you put a scope on the a/D pins to see what the signal is like upload your board in PDF or image and I will have a look at it
|
|
|
Logged
|
When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
|
|
|
Pasca
Newbie
Offline
Posts: 34
Thank You
-Given: 27
-Receive: 42
|
|
« Reply #4 on: August 14, 2012, 07:03:51 19:03 » |
|
Avr has internal analog buffer 18f no, so you have to externally provide it. In this situation avr is better.
Bye Pasca
|
|
|
Logged
|
More I know, more I need to know. Less I know, meglio sto!!!
|
|
|
picavr
Active Member
Offline
Posts: 176
Thank You
-Given: 267
-Receive: 101
|
|
« Reply #5 on: August 14, 2012, 07:19:02 19:19 » |
|
the program attached is for demonstrate the problem i use 4ms max because i amlimited by the 100ms (timer1) because my systeme is an real time and the voltage output come from sensor do not stabilise in time <=3.5ms for the lcd display i each cycle of timer1 i display one input the glcd display "eat" a lot of time (i am limited by 100ms)
is ther a solution for when i chortcut the input with 33k or less and the result give 0 or 1 or 2 not 100 its so big ?!! or for 18f4550 i slike this
|
|
|
Logged
|
|
|
|
Pasca
Newbie
Offline
Posts: 34
Thank You
-Given: 27
-Receive: 42
|
|
« Reply #6 on: August 14, 2012, 07:36:24 19:36 » |
|
Could you put schematics in png? I dont have eagle.
I dont understand what is value of adc with 2.5k resistor.
|
|
« Last Edit: August 14, 2012, 07:40:25 19:40 by Pasca »
|
Logged
|
More I know, more I need to know. Less I know, meglio sto!!!
|
|
|
Wizpic
Global Moderator
Hero Member
Offline
Posts: 1204
Thank You
-Given: 554
-Receive: 409
|
|
« Reply #7 on: August 14, 2012, 08:13:48 20:13 » |
|
Can't understand your PCB, you are not using any A/D input's, MCLR is feeding AN0 feeding your LCD ?? lookig at your code your LCD is connected to RD port, for a pic normally MCLR pin(1) is tied to +5 via 4K7 resistor, Cant understand what is the purpose of the 2 33K resistors on PORTD, The first thing that jumps out as well you have no GND plane(polygon) hence why you have got a lot of noise in your PCB. Normally best practice to have an analogue GND and digital GND in A/D conversion, I got a feeling that the noise/bounce is been casued by the switching of the LCD and 4052 thsat's why you would have the two GND planes, Pic/LCD on the digital and PSU/4052 on the analogue GND, Hold on I think I just worked it out about the PCB
If my understanding is correct you are inserting your pic the opposite way has to me pin 1 is in the top left corner and not the bottom right ??
Another thing I noticed where or how are you connecting the analogue input for the PIC, Have you tried a 10K to GND
|
|
« Last Edit: August 14, 2012, 08:16:11 20:16 by Wizpic »
|
Logged
|
When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
|
|
|
picavr
Active Member
Offline
Posts: 176
Thank You
-Given: 267
-Receive: 101
|
|
« Reply #8 on: August 14, 2012, 10:27:02 22:27 » |
|
Can't understand your PCB, you are not using any A/D input's, MCLR is feeding AN0 feeding your LCD ?? lookig at your code your LCD is connected to RD port, for a pic normally MCLR pin(1) is tied to +5 via 4K7 resistor, Cant understand what is the purpose of the 2 33K resistors on PORTD, The first thing that jumps out as well you have no GND plane(polygon) hence why you have got a lot of noise in your PCB. Normally best practice to have an analogue GND and digital GND in A/D conversion, I got a feeling that the noise/bounce is been casued by the switching of the LCD and 4052 thsat's why you would have the two GND planes, Pic/LCD on the digital and PSU/4052 on the analogue GND, Hold on I think I just worked it out about the PCB
If my understanding is correct you are inserting your pic the opposite way has to me pin 1 is in the top left corner and not the bottom right ??
Another thing I noticed where or how are you connecting the analogue input for the PIC, Have you tried a 10K to GND
in the real pcb i insert the pic in opposite side,sorry Posted on: August 14, 2012, 10:55:18 22:55 - Automerged
Can't understand your PCB, you are not using any A/D input's, MCLR is feeding AN0 feeding your LCD ?? lookig at your code your LCD is connected to RD port, for a pic normally MCLR pin(1) is tied to +5 via 4K7 resistor, Cant understand what is the purpose of the 2 33K resistors on PORTD, The first thing that jumps out as well you have no GND plane(polygon) hence why you have got a lot of noise in your PCB. Normally best practice to have an analogue GND and digital GND in A/D conversion, I got a feeling that the noise/bounce is been casued by the switching of the LCD and 4052 thsat's why you would have the two GND planes, Pic/LCD on the digital and PSU/4052 on the analogue GND, Hold on I think I just worked it out about the PCB
If my understanding is correct you are inserting your pic the opposite way has to me pin 1 is in the top left corner and not the bottom right ??
Another thing I noticed where or how are you connecting the analogue input for the PIC, Have you tried a 10K to GND
for the mclr pic its configurated like input digital (mclre =off) my output impedance sensors have between 33k and 1k every 04 imput are multiplixed with 4052 to an analogic imput there is a total 19 sensor, i cant put a capacitor in every adc imput when i put a 10nf the result decrease from 100 to 47 but its not sufisant. i cant put a capacitor big as 10nf (time multiplexing limitation) in case of atmega32 work fine without capacitor with the same GNDplane with the same circuit and program and lcd position and the same 4052 atmega32 work fine (work since 04 years) "no signal result =0 " Posted on: August 14, 2012, 11:10:47 23:10 - Automerged
Could you put schematics in png? I dont have eagle.
I dont understand what is value of adc with 2.5k resistor.
for 2.2k the result is 7 (10bit resolution) for 2.67k -----------9------------------ for 10k -------------31---------------- for 33k--------------100------------------ Posted on: August 14, 2012, 11:16:19 23:16 - Automerged
the input is sensor represented by a 33k Posted on: August 14, 2012, 11:21:41 23:21 - Automerged
the shematic is in proteuse
|
|
|
Logged
|
|
|
|
titi
Active Member
Online
Posts: 230
Thank You
-Given: 3838
-Receive: 834
|
|
« Reply #9 on: August 14, 2012, 10:43:49 22:43 » |
|
Hi, About grounding, a good article is available from Analog Device : http://www.analog.com/library/analogDialogue/archives/46-06/staying_well_grounded.pdffigure 2 page 3, show a current problem with only one ground. About your design, it is a good pratice to put a small capacitor of 100nF between pin 1 and 2 of LM7805 and from 2 and 3 as close as possible from the regulator, to reduce noise and avoid the regulator to oscillate. It is not necessary to put big capacitors of 1000uF every where, more the capacitor is bigger, more inductive it is, so prefere big capacitor for power supply, but use low ESR capacitor like small tantale capacitor of 10uF near the microcontroler and the LCD power pins and allway put a 100nF or 220nF as close as possible of microcontroler power pins. Generaly, I use 100nF SMD ceramic capacitor solder under the microcontroler between power pins. Best regards.
|
|
|
Logged
|
|
|
|
picavr
Active Member
Offline
Posts: 176
Thank You
-Given: 267
-Receive: 101
|
|
« Reply #10 on: August 14, 2012, 11:04:47 23:04 » |
|
in real pcb there are more the 6 six capacitor one 100nf near 7805 one 100nf near 12v two 100nf near 4450 one 100nf near 4052 one 100nf near the lcd one 400nf in the usb pin (without influence because the usb regulator is disabled by the config VREGEN = off)
is there a a configuration setup by software that can reduce the noise ? or is there a source of noise created by the mcu 18f4550 caused by an bad "fuse-bits configuration " or by the mcu registre manipulation
Posted on: August 14, 2012, 11:59:57 23:59 - Automerged
the value gived by conversion of input attached with 33k is 100 this value represente 100*(5/1023)=488mv its so big without signal !!!!!! 488mv caused only by a 33k placed near the mcu its not good
|
|
|
Logged
|
|
|
|
Pasca
Newbie
Offline
Posts: 34
Thank You
-Given: 27
-Receive: 42
|
|
« Reply #11 on: August 14, 2012, 11:19:37 23:19 » |
|
Hi picavr, if your sensors have so high internal resistance the only think that you can do is to condition their signal. You can to condition signal after 4052 so your circuit need only five rail-to-rail op-amp (es. lmv324 http://www.ti.com/lit/ds/snos012f/snos012f.pdf). Lower internal resistence is needed for reduce the settling time less to 4ms so i think that you have no other chance. There is no a noise problem, but injection charge of internal capacitor of ADC, in my opinion ( http://www.analogzone.com/acqt1003.pdf). Bye Pasca
|
|
|
Logged
|
More I know, more I need to know. Less I know, meglio sto!!!
|
|
|
picavr
Active Member
Offline
Posts: 176
Thank You
-Given: 267
-Receive: 101
|
|
« Reply #12 on: August 14, 2012, 11:30:09 23:30 » |
|
i am restricted by the pcb-dimesion ,i know i can use ampli-op to reduce the impedance with a lm358 follower and a 2.2k in output the result is big as the zero. with atmega32 the 33k give me ZERO with the same pcb /gnd-plane. can i said the 18f4550 or 18f series is not good for an analogic interface??
|
|
|
Logged
|
|
|
|
Wizpic
Global Moderator
Hero Member
Offline
Posts: 1204
Thank You
-Given: 554
-Receive: 409
|
|
« Reply #13 on: August 14, 2012, 11:43:04 23:43 » |
|
Has some one pointed out AVR has buffers already built in pic does not, If that is the size of yor PCB why not use SMT op-amps mounted under-neath the PCB. My logic of thinking if it's worked well for 4 years with AVR why try and re-invent the wheel sort of thing. Don't give up yet you will get there, Like I said best practice is to use GND plane not sure about AVR but pic's might be slightly different. I will have a look at the code and see if there might be another way of doing it
|
|
|
Logged
|
When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
|
|
|
motox
Cracking Team
Active Member
Offline
Posts: 189
Thank You
-Given: 258
-Receive: 327
|
|
« Reply #14 on: August 15, 2012, 12:48:57 00:48 » |
|
Picavr, I know what your problem is, too many mistakes. You’re running the PIC18F4550 at 48MHz. According to register ADCON2 the acquisition time is zero (first mistake) and Tad is Fosc/2 = 24MHz (second mistake). Also “The maximum recommended impedance for analog sources is 2.5 kΩ.” (third mistake).
I pointed out the mistakes, now go read the PIC data sheet chapter 21. “10-BIT ANALOG-TO-DIGITAL CONVERTER (A/D) MODULE.”.
I’m not going to tell the solution because you MUST read the data sheet first. It takes 5min max. and is very easy to understand.
|
|
|
Logged
|
|
|
|
picavr
Active Member
Offline
Posts: 176
Thank You
-Given: 267
-Receive: 101
|
|
« Reply #15 on: August 15, 2012, 12:29:14 12:29 » |
|
dear MOTOX the configuration is remplacedt in the program look at osccon register Device = 18F4550 Declare Xtal 8 OSCCON.6=1 OSCCON.5=1 OSCCON.4=1 OSCCON.1=1 OSCCON.0=1 8MHZ internal oscillator look at the simulation in oscilloscope the cycle is 100ms the same timing in my real DSO -------------------------------------- the fuse configuration on winpi800 is not taked, because its remplaced by the proton picbasic configuration (config start ----config end ) Config_Start FOSC = INTOSCIO_EC PBADEN = On MCLRE = off PLLDIV = 1 USBDIV = 1 IESO = OFF PWRT = OFF BOR=On VREGEN = off WDTPS = 512 WDT = On LPT1OSC = OFF CCP2MX = On STVREN = On LVP = off ICPRT = OFF XINST = OFF WRTD = OFF Config_End ------------------------------------------------ look at the adc register ADCON2.7 = 1 ADCON1 = %00001001 'an0-an5 analogic input ADCON0.0=1 Declare Adin_Res = 10 ' 10-bit result required Declare Adin_Tad = FRC ' RC oscillator chosen Declare Adin_Stime = 50 ' Allow 50us sample time 50us sampling time you can see : PORTC.7=1 valadcge=ADIn 5 PORTC.7=0 in the simultion the with of this pulse (sampling time)is about 75us the same pulse is looked on my scope i think there is not a problem in timing
|
|
|
Logged
|
|
|
|
motox
Cracking Team
Active Member
Offline
Posts: 189
Thank You
-Given: 258
-Receive: 327
|
|
« Reply #16 on: August 15, 2012, 01:16:01 13:16 » |
|
Dear picavr, Yes, the Fosc is only 8MHz. Still is too high for the ADC module. Analyzing the machine code (HEX file) the ADCON2 register is 0b10000000. Like I told you before the acquisition time is zero and Tad is Fosc/2. According to uC data sheet “TABLE 21-1: TAD vs. DEVICE OPERATING FREQUENCIES”, if ADCS2:ADCS0 = 0b000 then the maximum Fosc is 2.5MHz. You are overclocking the ADC by 3.2x times. This is not an AMD cpu I don’t know what you mean by this: “Declare Adin_Res = 10 ' 10-bit result required Declare Adin_Tad = FRC ' RC oscillator chosen Declare Adin_Stime = 50 ' Allow 50us sample time”Is this basic?
|
|
|
Logged
|
|
|
|
picavr
Active Member
Offline
Posts: 176
Thank You
-Given: 267
-Receive: 101
|
|
« Reply #17 on: August 15, 2012, 02:00:08 14:00 » |
|
Dear picavr, Yes, the Fosc is only 8MHz. Still is too high for the ADC module. Analyzing the machine code (HEX file) the ADCON2 register is 0b10000000. Like I told you before the acquisition time is zero and Tad is Fosc/2. According to uC data sheet “TABLE 21-1: TAD vs. DEVICE OPERATING FREQUENCIES”, if ADCS2:ADCS0 = 0b000 then the maximum Fosc is 2.5MHz. You are overclocking the ADC by 3.2x times. This is not an AMD cpu I don’t know what you mean by this: “Declare Adin_Res = 10 ' 10-bit result required Declare Adin_Tad = FRC ' RC oscillator chosen Declare Adin_Stime = 50 ' Allow 50us sample time”Is this basic? adcon2.7 =1 is not the same as adcon2=0b10000000 adcon2.7 affect only bit N 7 adcon2.7 =1 =A/D Result Format Right justified the others bit of adcon2 will be affected by the instructions: Declare Adin_Res = 10 ' 10-bit result required Declare Adin_Tad = FRC ' RC oscillator chosen Declare Adin_Stime = 50 ' Allow 50us sample time” my programme is in proton pic basic dear motox if i need configure my adc at: 10bit,50us sampling speed,rc osclliator (internal oscillator 8MHZ) can you tel me how i can writing the adc register give me the code an i will test it in proteuse and in the real pcb thank you in avance
|
|
|
Logged
|
|
|
|
motox
Cracking Team
Active Member
Offline
Posts: 189
Thank You
-Given: 258
-Receive: 327
|
|
« Reply #18 on: August 15, 2012, 02:11:29 14:11 » |
|
the others bit of adcon2 will be affected by the instructions: Declare Adin_Res = 10 ' 10-bit result required Declare Adin_Tad = FRC ' RC oscillator chosen Declare Adin_Stime = 50 ' Allow 50us sample time”
Those lines of code are definitions (constants) and not instructions. They are defined but not used anywhere in the code. Add the following code (adapt to picbasic if necessary): ADCON2 = 0b10111001;
|
|
|
Logged
|
|
|
|
picavr
Active Member
Offline
Posts: 176
Thank You
-Given: 267
-Receive: 101
|
|
« Reply #19 on: August 15, 2012, 06:16:40 18:16 » |
|
Those lines of code are definitions (constants) and not instructions. They are defined but not used anywhere in the code.
Add the following code (adapt to picbasic if necessary): ADCON2 = 0b10111001;
i will test it Posted on: August 15, 2012, 06:36:01 18:36 - Automerged
it tested without change the new code is attached ichorcuted the (an0 GND(7805))with jumper it give 3 (3/1023) with jumper its not normal 33k give me 100 (100/1023) the plan of pcb-gnd is attached red=5v white=gnd
|
|
|
Logged
|
|
|
|
motox
Cracking Team
Active Member
Offline
Posts: 189
Thank You
-Given: 258
-Receive: 327
|
|
« Reply #20 on: August 15, 2012, 06:44:36 18:44 » |
|
First configure all ADC registers and after that turn on the ADC module. You’re still violating the ADC limits doing it in the wrong sequence. No one knows what could happen to the ADC!
Let’s make this clear. What is you analog input? The above schematic doesn’t correspond to your hardware. Show us a complete schematic. Is the picture 'the pcb corrected.png' or the 'the schematic.png'?
|
|
« Last Edit: August 15, 2012, 06:48:56 18:48 by motox »
|
Logged
|
|
|
|
picavr
Active Member
Offline
Posts: 176
Thank You
-Given: 267
-Receive: 101
|
|
« Reply #21 on: August 15, 2012, 07:04:45 19:04 » |
|
the pcb gived is a part of the real-pcb its an representation of a gnd plane and 18f4550 the other part is not interessant there are 3 cards (21cm*18cm) my problem is "in" or "near" the mcu
in proton picbasic only there tree instruction Declare Adin_Res = 10 ' 10-bit result required Declare Adin_Tad = FRC ' RC oscillator chosen Declare Adin_Stime = 50 ' Allow 50us sample time” ADCON2.7 = 1 "result right justifie ADCON1 = %00001001 'an0-an5 analogic input
if you have" isis" installed on your pc you can see it work
and if you read adin 0 'for input 0 adin 5 'for input 0
|
|
|
Logged
|
|
|
|
Wizpic
Global Moderator
Hero Member
Offline
Posts: 1204
Thank You
-Given: 554
-Receive: 409
|
|
« Reply #22 on: August 15, 2012, 07:11:30 19:11 » |
|
if you have" isis" installed on your pc you can see it work
and if you read adin 0 'for input 0 adin 5 'for input 0
Has I've said once before ISIS will work spot on and using the scope in ISIS will not show noise like it would in real time.
|
|
|
Logged
|
When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
|
|
|
motox
Cracking Team
Active Member
Offline
Posts: 189
Thank You
-Given: 258
-Receive: 327
|
|
« Reply #23 on: August 15, 2012, 07:36:51 19:36 » |
|
if you have" isis" installed on your pc you can see it work
I use MPLAB to import the HEX file and then simulate the code using MPLAB SIM with register injection to test the ADC. Now I can confirm that your code is writing the ADCON2 register to select the Frc clock. The simulation shows no problems…
|
|
|
Logged
|
|
|
|
Pasca
Newbie
Offline
Posts: 34
Thank You
-Given: 27
-Receive: 42
|
|
« Reply #24 on: August 15, 2012, 08:14:58 20:14 » |
|
Hi all, Assuming that the ADC is working correctly now and assuming that the signal of the sensors changes slowly, you may connect the capacitors to the input of multiplexer (one for sensor) and ground for dynamically reduce the internal resistance of the sensor.
Bye Pasca
|
|
|
Logged
|
More I know, more I need to know. Less I know, meglio sto!!!
|
|
|
|