CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Wrong ADC measure, with offset.
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Jun 04, 2020 6:27 am     Reply with quote

Two things.

First have you read this in the Vref data sheet?
Quote:

However, the load transient response can improve with an additional
1 μF to 10 μF output capacitor placed in parallel with the 0.1 μF capacitor.

The chip does not have a good load transient response and your board
does nothing to help this..

But then the second thing. Why the 10R resistor?.
This means the voltage will drop when the load increases. Even if the
chip gave perfect regulation. Not the amount that would be involved
here, but still makes it worse....
afk_pic



Joined: 02 Jun 2020
Posts: 19

View user's profile Send private message

PostPosted: Fri Jun 05, 2020 12:21 am     Reply with quote

I don't remember...i made this pcb months ago haha. Yes, should have it.

I use a 10R for two reasons:
- To avoid fast transitions and coupling in the nearest tracks. In this case, is not "mandatory".
- and In case of error/debugging, I can unplug the Vref, removing this resistor.

Anyway, you always can replace by 0R res.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Jun 05, 2020 12:30 am     Reply with quote

Why should you have 'fast transitions' on a Vref?.
The resistor makes 'sense', if you have a large reservoir capacitor after
it, since this can help prevent oscillation (some Vref designs don't like
too much output capacitance and can go unstable if this exists).

OK, so you can remove the resistor. Do you have a regulated bench
supply available?. If so, take out the resistor, add a wire to feed in
at this point, and feed in 2.5v from the bench supply. If everything then
suddenly starts working correctly, you have identified where the problem
lies....
afk_pic



Joined: 02 Jun 2020
Posts: 19

View user's profile Send private message

PostPosted: Fri Jun 05, 2020 1:03 am     Reply with quote

Hi,



I created a basic project, read the ADC (created with the CCS Wizard) and CCS IDE and it works, read the correct value...


The other project was created with Eclipse and CCS compiler, I've checked all the #include, #use, setup...it's ok and i still reading wrong value.

Eclipse project:


Code:

#include <33FJ256GP710A.h>

#device ADC=12
#build (stack=512)//importante para los printf y los floats

#device PASS_STRINGS=IN_RAM
#device CONST=READ_ONLY
                  
#device ICSP=1
#use delay(clock=20MHz,crystal=8MHz)

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOJTAG                   //JTAG disabled

#use rs232(UART1, baud=9600, parity=N,bits=8,stop = 1, restart_wdt, stream=RS232_PORT1)
#use spi(SLAVE, SPI1, MODE=0, BITS=8, ENABLE=PIN_B2)
#use spi(MASTER, SPI2, MODE=1, BITS=8, BAUD=115200)



CCS IDE
Code:

#include <33FJ256GP710A.h>
#device ADC=12

#device ICSP=1
#use delay(clock=20000000,crystal=8000000)

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOJTAG                   //JTAG disabled

#use rs232(UART1, baud=9600, restart_wdt, stream=UART_PORT1)

#define LED PIN_D15
#define DELAY 1000

Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Jun 05, 2020 1:42 am     Reply with quote

So it is somewhere further into the code. Look for:

1) What is stored immediately in front of the variable being used for the
adc value in RAM?. (look at the sym listing). Any possibility an array
access is overrunning?.
2) Are you using interrupts?. If so, any possibility that you are accessing
values that may still be changing (so non granular accesses between the
interrupt and the main code)?.
3) Triple check every I/O operation that talks to the ports as a whole
and the particularly the port bits that the analog (and Vref) is on.
Any 'word wide' I/O operations on portA?.

This is now a debugging exercise. Disable parts of the code. If you can
'narrow down' what is making the ADC go wrong, then you have a
chance of finding what is actually causing the problem.

You are also on an old enough compiler that it assigns stack space in bytes
not in 'levels'. So beware that stack=512, only gives 256 levels, and some
things seem to always use more levels than the LST reports. The latest
compilers have switched so that STACK=512, allocates 512 levels.
Is is possible that the stack is actually overflowing?.
Your chip does not give a stack reset. Add a handler for #INT_STACKERR
Simply have this set a value in memory. Then if this gets set, you know
what is happening...
afk_pic



Joined: 02 Jun 2020
Posts: 19

View user's profile Send private message

PostPosted: Fri Jun 05, 2020 3:43 am     Reply with quote

Finally i got it, it's caused by an analog pin, if I disable this pin, the adc gives me the correct value. This pin is actually floating, if I set to GND, the adc reads fine all other analog pins...


I know it, pins never should be left floating! Never I've seen before, what an analog floating "hack" the others analog pins. In this case, a bunch of components is attached to this pin and I removed all, because I'll never use it, finally, the analog pin it's floating.

Thanks for all, Ttelmah.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Jun 05, 2020 6:47 am     Reply with quote

The FET's that form the input multiplexer all inherently have reverse
diodes in them, so if an input voltage goes above the Vref, it'll conduct
and raise the internal Vref....
Would guess the 'bunch of components' is either itself coupling in a
signal, or acting as an antenna...

Fun....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group