pot reading either min or max

Thread Starter

emzdanow

Joined Jun 14, 2010
23
Hello,

I am using a simple 10kΩ to varry an analog voltage that I can read on an A/D input on a PIC. The reading I get is always 255 (max) or 0-10 (near min). I believe this is a ciruit problem. I have one pin on pot connected to ground and the other to +5V. The center wiper is connected directly to my input pin on my PIC (PIC16F690). When I just connect ground and power and measure center pin with multimeter the voltage varries fine, but when I hook it up to the PIC, the voltage does nothing while turning the knob, then drops to zero or 5V (depending on starting point). Any suggestions? Do I need other componenets in circuit?
 

someonesdad

Joined Jul 7, 2009
1,583
It's pretty hard to fool the hardware, so if it works when you measure it, it's your code. If you download the Low Pin Count Demo Board applications from Microchip, their examples do exactly what you want (with the same processor you're using).
 

Thread Starter

emzdanow

Joined Jun 14, 2010
23
I have used the code before successfully from the development board, but now I am using seperate breadboard. Also, once I put output of pot to chip, I measure voltage with multimeter and see the sudden drop in voltage. It only happens when connected to pic. I will post my code later, I am on mobile.
 

Thread Starter

emzdanow

Joined Jun 14, 2010
23
here is my code, the lcd works fine, but value on screen is always around 0 or around 255, does not change linearly as I turn the knob.

Rich (BB code):
#include <pic.h>
#include "lcd.h"
void pause (unsigned short msvalue);
void msecbase( void );
__CONFIG (INTIO & WDTDIS & MCLRDIS & UNPROTECT );
#define number 0x30;
int level = 0;
char ans = 0;
char d0, d1, d2, d3;
char str;
 
main()
{
CM1CON0 = 0;
CM2CON0 = 0;
PORTC = 0x00;
PORTB = 0x00;
PORTA = 0x00;
TRISC = 0x00;
TRISA = 0b00000001;
TRISB = 0xFF;
ANSEL = 1;
ADCON0 = 0b00000001;
ADCON1 = 0b00111111;
lcd_init();
 while(1)
 {
 GODONE = 1;
  while(GODONE == 1)
  {
  }
 level = ADRESH;
 d3 = level % 10;                  /* d2 <-- 7 */
 d2 = (level / 10) % 10;           /* d1 <-- 3 */
 d1 = (level / 100) % 10;    /* d0 <-- 1 */
 d0 = (level / 1000) %10;
/* continue like this for even more digits */
 /* convert digit (numbers) to ASCII (text characters) */
 d0 += '0';   /* same as d0 = d0 + ‘0’ same as d0 = d0 | 0x30 */
 d1 += '0';
 d2 += '0';
 d3 += '0';

 lcd_goto(0);
 lcd_puts("Ans");
 lcd_goto(0x05);
 lcd_putch(d0);
 lcd_goto(0x06);
 lcd_puts(".");
 lcd_goto(0x07);
 lcd_putch(d1);
 lcd_goto(0x08);
 lcd_putch(d2);
 lcd_goto(0x09);
 lcd_putch(d3);
 lcd_goto(0x0A);
 lcd_puts("Alc");
 pause(500);

}
}
 

Thread Starter

emzdanow

Joined Jun 14, 2010
23
The TRISA =0b00000001 command sets RA0 to an input and this is the pin I am using for a/d. It is very bizzare, the voltage varries like it should when not connected to the PIC, I even hooked it to an LED and the brightness varried linearly. Its just when it is connected to the PIC it reads 255-250 or zero. Again, it is a 10k pot with one pin connected to ground, another to supply voltage (approx 5v from 4 AA batteries) and the wiper connected to the a/d pin on PIC.
 

Thread Starter

emzdanow

Joined Jun 14, 2010
23
Problem solved, trixheim was correct. The main program was correct, however, the lcd_int() function in the lcd.c file sets the A port to all outputs. Sorry for any wasted time on anyones part seeing as this was a stupid mistake.
 
Top