PIC18F4550 ADC RESPONCE PROBLEM

General discussion on mikroElektronika development boards.
Post Reply
Author
Message
hIMANSh
Posts: 158
Joined: 01 Jan 2011 17:48

PIC18F4550 ADC RESPONCE PROBLEM

#1 Post by hIMANSh » 12 Aug 2011 11:00

I AM GETTING SOME PROBLEM WITH ADC RESPONCE TIME ITS TOO SLOW. I AM WEIGHING AMOUNT OF LOAD ON LOADCELL AND THEN DISPLAYING DATA ON LCD. WHEN I PUT 2kg WEIGHT IT SHOW 2 KG ON LCD BUT VERY SLOWLY AND SAME WHEN I REMOVE. BELOW IS INITIALIZATION THAT I USED. PLZ HELP ME OUT

//CONVERT FUN
void convert{
adc_rd = ADC_Read(0);
tlong = (long)adc_rd * 5000; // Convert the result in millivolts
tlong = tlong / 1023; // 0..1023 -> 0-5000mV
tlong = tlong * (factor/1000);
}

void main() {
INTCON = 0;
ADCON0= 0b00000011;
ADCON1= 0b00001110;
ADCON2= 0b00000000;
// ADCON1 = 0x82; // A/D voltage reference is VCC
TRISA = 0xFF; // All port A pins are configured as inputs
TRISD = 0xFF;
PORTD = 0xFF;
CMCON |= 7; // Disable comparators
}

hIMANSh
Posts: 158
Joined: 01 Jan 2011 17:48

Re: PIC18F4550 ADC RESPONCE PROBLEM

#2 Post by hIMANSh » 15 Aug 2011 08:50

plz some one help me

piort
Posts: 1379
Joined: 28 Dec 2005 16:42
Location: Laval,Québec,Canada,Earth... :-)
Contact:

Re: PIC18F4550 ADC RESPONCE PROBLEM

#3 Post by piort » 15 Aug 2011 11:45

hi,
the problem isnt in the showing code... is somewhere else. Can you put all the code ? specially the one making conversion (adc to Kg) and how you use it and the one command the LCD. BTW what is slow ? The time between action or the time the text appear on the LCD ? When something is slow with this MCU few thing are possible... time consuming loop somewhere else ( usart, usb ...) , loop waiting for a input if is between action. For lcd, to many action in same time make the text appear slowly, not enough voltage to LCD make that too... As you see, we need more info to be able to hlp you ;-)

hIMANSh
Posts: 158
Joined: 01 Jan 2011 17:48

Re: PIC18F4550 ADC RESPONCE PROBLEM

#4 Post by hIMANSh » 15 Aug 2011 19:31

piort wrote:hi,
the problem isnt in the showing code... is somewhere else. Can you put all the code ? specially the one making conversion (adc to Kg) and how you use it and the one command the LCD. BTW what is slow ? The time between action or the time the text appear on the LCD ? When something is slow with this MCU few thing are possible... time consuming loop somewhere else ( usart, usb ...) , loop waiting for a input if is between action. For lcd, to many action in same time make the text appear slowly, not enough voltage to LCD make that too... As you see, we need more info to be able to hlp you ;-)

code is as below

// LCD module connections
sbit LCD_RS at RB7_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_D4 at RB5_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D7 at RB2_bit;

sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;
// End LCD module connections

sbit MENU at RD7_bit;
sbit NEXT at RD6_bit;
sbit UP at RD5_bit;
sbit ENTER at RD4_bit;
sbit HOLD at RD3_bit;
sbit TARE at RD2_bit;

char *txt, tnum[3], ch, np;
unsigned char A1, A2, A3, A4, MODE, CAL, sec, min1, hr, week_day, day, mn, year;
unsigned int adc_rd, COUNT, D1, D2, D3, D4, D5, D6, X0, X1, X2, VALUE1, VALUE2;
long tlong, TareValue, factor;

const char character[] = {0,0,5,5,7,5,5,0};

void CustomChar(char pos_row, char pos_char) {
char i;
Lcd_Cmd(64);
for (i = 0; i<=7; i++) Lcd_Chr_CP(character);
Lcd_Cmd(_LCD_RETURN_HOME);
Lcd_Chr(pos_row, pos_char, 0);
}

void Zero_Fill(char *value) { // fill text repesentation
if (value[1] == 0) { // with leading zero
value[1] = value[0];
value[0] = 48;
value[2] = 0;
}
}//~

void ReadData(unsigned int L1, unsigned int L2){

VALUE1 = EEPROM_Read(L1);
VALUE2 = EEPROM_Read(L2);
}

void LCDInit(){
unsigned int s1,s2,s3,s4;

Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)

Lcd_Out(1, 1,"TORQUE:");
Lcd_Out(1, 15,"NM");
Lcd_Out(2, 1,"00/00/00 00:00");
ReadData(0,1); // read factor value

s1=EEPROM_Read(10);
s2=EEPROM_Read(11);
s3=EEPROM_Read(12);
s4=EEPROM_Read(13);
factor = s1*1000+s2*100+s3*10+s4;
factor = factor / 1000;

ReadData(2,3);
TareValue = (VALUE1*100) + VALUE2;
}

void DATA_READ(char pos_row, char pos_col){
long oldtlong;

if(MODE==ADC_ON){
if(HOLD==0) oldtlong = tlong;
adc_rd = ADC_Read(0);
tlong = (long)adc_rd * 5000; // Convert the result in millivolts
tlong = tlong / 1023; // 0..1023 -> 0-5000mV
// factor= factor/1000;
tlong = tlong * factor;
tlong = tlong - TareValue;
if(tlong>0) {Lcd_Chr(1, 8, ' '); np=0;}
if(tlong<0) {Lcd_Chr(1, 8, '-'); np=1; tlong = tlong*(-1);}
Lcd_Chr(1, 13, ' ');
// if(tlong>9999) Lcd_Out(1, 9,"OVER");

}
if(HOLD==0){
if(tlong<oldtlong) tlong = oldtlong;
CustomChar(1,13);
}

ch = tlong / 1000; // Extract volts (thousands of millivolts) from result
Lcd_Chr(pos_row,pos_col,48+ch); // Write result in ASCII format
UART1_Write(48+ch);

if(MODE==ADC_OFF) Lcd_Chr_CP(46);

ch = (tlong / 100) % 10; // Extract hundreds of millivolts
Lcd_Chr_CP(48+ch);
UART1_Write(48+ch);
ch = (tlong / 10) % 10; // Extract tens of millivolts
Lcd_Chr_CP(48+ch); // Write result in ASCII format
UART1_Write(48+ch);
ch = tlong % 10; // Extract digits for millivolts
Lcd_Chr_CP(48+ch); // Write result in ASCII format
UART1_Write(48+ch);
UART1_Write(',');
Delay_ms(1);
}

void main() {
// Analog input setup
ADCON0 = 0;
ADCON2 = 0;
ADCON1 |= 0x07; // Configure PortB As digital IO
CMCON |= 7; // Disable comparators

// Setup port A (4:0 - analog inputs)
LatA = 0;
PortA = 0;
// TrisA = 0b0001111;
TrisA = 0b0000001;

/* INTCON = 0; // All interrupts disabled
CMCON = 0x07; // deactivate comparators
ADCON1 = 0x0B; // RA0-RA3: Analog, the rest: Digital, voltage references: Vss and Vdd
ADCON2 &= 0x80; // Adc_read() will return a right-justified binary value
TRISA = 0x0F; // Analog: RA0-RA3: In*/
// TRISA = 1;
// ADCON1 = 0x4E;

// INTCON = 0;
// ADCON1 = 0x07;
// TRISA = 0xFF;
/* CMCON = 0x07;
ADRESL = 0b10000000;
ADRESH = 0b10000000;
ADCON0 = 0b00000000; //AN0 as analog input but ADC module is disabled
ADCON1 = 0x0E; // AN0 port is selected as anolog input

INTCON = 0;
ADCON0= 0b00000011;
ADCON1= 0b00001110;
ADCON2= 0b00000000;
CMCON |= 7; // Disable comparators
*/ // TRISA = 0xFF;
TRISC = 0x80;
PORTC = 0x80;
TRISD = 0xFF;
PORTD = 0xFF;

UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
I2C1_Init(100000); // initialize I2C communication
Lcd_Init(); // LCD display initialization
Delay_ms(1000);

UART1_Write_Text("TORQUE WENTCH TESTER");
newline();
LCDInit();

while(1){
DATA_READ(1,9);
if(MENU==0) SetupFun();
if(TARE==0) TareFun();
}
}

Post Reply

Return to “Development Boards”