Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems reading an analog input
07-02-2013, 03:53 AM, (This post was last modified: 07-02-2013, 04:05 AM by TuxD3v.)
#1
Problems reading an analog input
Hi Guys,

I have a problem reading an analog input in my Pinguino 26j50, this is the code:


int level;
void setup() {
TRISAbits.TRISA0 = 1; //setting RA0 to input
LATAbits.LATA0 = LOW; //setting latch of RA0 to LOW
TRISCbits.TRISC2 = 0; //seting RC2 for output
LATCbits.LATC2 = LOW; //putting the latch of RC2 low...put off the Board Led
delay(5000); //only to debug the problem...the led goes off for 5 secs
}

void loop() {
level=analogRead(13); //analog read from RA0
if (level>512)
LATCbits.LATC2 = HIGH; // if voltage applied on RA0 > 2,5V set pin RC2(board led)
else LATCbits.LATC2 = LOW; // else reset RC2(board led off)
}

My problem is...I set the RA0 to be an input port(so with nothing attached in will be in high impedance) but it have all the time 3.12v?????

Also...
RA1=RA2=RA3=1.82v ??? without nothing attached??(confirmed with a voltimeter)

VDDCORE/VCAP=2.48v(confirmed with a voltimeter)

I also have Vdd(3.3?)=4.08v...is this not to much??the zener regulator is heating...

My idea is reding analog pin RA0 and if the value is great than 2.5 volts the board led will turn on...

I'm a newbe in Pics, and Pinguino...

whats wrong with my program??My Board Led is Always ON...without nothing connected to RA0...

thanks in advance guys

regards
Reply
07-02-2013, 02:25 PM,
#2
RE: Problems reading an analog input
Code:
void setup()
{
}

void loop()
{
    int level;

    level = analogRead(13);     // analog read from RA0
    CDC.printf("level=%d\r\n", level);
    delay(1000);
}

My 26j50 with the prog. above has :

VDD = 3.4V (must be <3.6V)
VDDCORE = 2.45V (must be between 2.0 and 2.7V)
Digital pins = 0V

RA0 connected to VDD : level = 1023
RA0 connected to GND : level = 1
RA0 connected to 1.3V battery : level = 395 ( 1024 / VDD * 1.3 )
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
07-02-2013, 02:34 PM,
#3
RE: Problems reading an analog input
Tux - Sounds like faulty power.

Also, don't measure an unconnected input. Inputs do not like to float!

John
Reply
07-02-2013, 06:36 PM, (This post was last modified: 07-02-2013, 06:36 PM by TuxD3v.)
#4
RE: Problems reading an analog input
Hi,

This is my values:
Gathered Through debug mode, with the code regis post above.

VDD = 4.11V (must be <3.6V)????
VDDCORE/VCAP=2.48v(confirmed with a voltmeter)
Digital pins = 0V

RA0 connected to VDD : level = 1023(4.11v measured with voltmeter)
RA0 connected to GND : level = 1
RA0 connected to 1.3V battery : level = ( I don't have a battery connected Sad )

I think that the zener that gives the power to the system is from a value above...

I buyed this kit from Pinguino this week...

Another thing...the bootloader when i mounted the board, have the voltages above, but i think that the blinking of the leds its diferent from what it is doing now...

I have disconnected it from usb, made a svn update in x.4 branch and after that he don't blink in the same way that before...in bootloader mode.

The bootloader i think it have is v4.8.
Can i flash it?how?

So is this a problem with the board...i am powering it from usb(but the usb has ~5 v).

the kit have a resistor 10 hom//diode zener, and is direct attached to the pic..?!

thanks in advance...

regards
Reply
07-02-2013, 10:18 PM, (This post was last modified: 07-02-2013, 10:30 PM by regis.)
#5
RE: Problems reading an analog input
VDD = 4.11V is quite dangerous for your PIC18f26j50 !!!
Are you sure you have connected the Zener Diode properly ?

All Zener Diodes from the Kits are 1/2W, 3.3V (marked as 3v3).
They are used as Voltage regulator (reverse bias).
The maximum current flowing through the zener diode is
Iz max = Watts / Voltage = 0.5W / 3.3V = ~ 150 mA
The minimum value of the resistor is
Rs min = [Vin - Vout] / Iz max = (5 – 3.3) / 150 = ~ 10 Ω

   

So 2 things to check :
- is the zener cathode (black band) connected to the 10 Ohm resistor ?
- is the resistor connected to the zener cathode, a 10 Ohm resistor ?

   

I don't think the problem comes from the bootloader, but just for your information :
All boards are tested with a blink test. So the first time you connect the board you should see :
- bootloader : built-in led blinking for 10 sec (500ms On, 500ms Off)
- test prog. : built-in led blinking "ad vitam aeternam" (50ms On, 50ms Off)
If you press the reset button you can count how many times the led is on. You should have 10 sec / 500ms = 20.
If not, take a look at the crystal. Do you have 20.000 written on it ?
Of course, it's always possible to burn a new bootloader : http://wiki.pinguino.cc/index.php/PIC18F...programmer
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
08-02-2013, 01:51 AM,
#6
RE: Problems reading an analog input
Hi,
the zener is like you have said 3v3, but i don know the wattage of it?!
it seems to have someting below like 5T os ST, i don t sure about...
it is mounted correctly to regulate the power...

Maybe the problem stays in IZmin...i don know but the zener needs(i think) to pass through him a minimal current to start to function in reverse zone..?!

Izmax supported(if it is for 0.5 watts), is (0.5w/3.3v)=~151,5mA.

the PIC consumes ~14mA...are passing about 89mA through the resistor 10 ohm, so to the zener goes with 75mA.

More or less half the Izmax suported(if it is 0.5W...it seems ti be very small for 0.5w, but i don't have sure about)...it is heating...and after a wile i can't continue to touch him(to hot)...

I will try to find a new one and test...

regards
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)