Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to select acquisition time in A/D?

Status
Not open for further replies.
I guess, you expect highbyte to be copied to the upper byte of full_value?
Code:
full_value = ((high_byte<<8)|low_byte);
But according to C language rules it isn't. high_byte<<8 is still an int8 value. (int16)high_byte<<8 will do.
With CCS C, you'll possibly want to use the built-in make16() function for this purpose, or even more comfortable, use the respective ADC functions.
 
yes when i tried using inbuilt functions, it works perfectly. for 0V, it shows 0 in LCD and for 5V it shows 1023 in LCD display.

Now the problem is solved. i have changed the line
HTML:
unsigned int8 low_byte,high_byte;
to
HTML:
unsigned int16 low_byte,high_byte;
.Now simulated in proteus, it works good. Tomorrow ill run it in hardware and check. thank you so much tahmid and jayanth for your help :):)...
 

I tested with real hardware. It works. but the problem is, display value is haunting. i rotated the pot to some value and kept silent.
for eg. if lcd value is 910. and it rolling over from 890 to 920. why is it so?
 

It's good in proteus. But in hardware, value in LCD fluctuates.
HTML:
#include "18F2520.h"
#include "f2520_regs.h"
#fuses INTRC_IO					// Internal clock
#use delay(clock=4000000) 		// 4MHZ

#define RS PIN_A2  	// LCD RS pin connected to uC PIN_A2
#define EN PIN_A1	// LCD EN pin connected to uC PIN_A1

void lcd_init();
void lcd_cmd(unsigned char);
void lcd_data(unsigned char);

unsigned int16 low_byte,high_byte;
unsigned int16 full_value; 

void main()
{
lcd_init(); 				// lcd initialization
TRISA  = 0b00100000;		// RA5 -input, rest as output
ADCON0 = 0b00010000;		// analog channel 4, A/D on
ADCON1 = 0b00001010;		// ref volt. VSS and VDD. AN4 to AN0 as analog
//ADCON2 = 0b10110100;		// Right justified, 16 TAD, 1/4Tosc
//ADCON2 = 0b10110101;       //FOSC/16
 ADCON2 = 0b10111100;
ADON = 1;
while(1)
{
delay_us(10);   
GO = 1;  					// to start conversion	
while(GO==1);				// wait for bit to be cleared
low_byte = ADRESL;			 
high_byte = ADRESH;
full_value = ((high_byte<<8)|low_byte);
lcd_cmd(0x80);
printf(lcd_data,"%4lu",full_value);
delay_ms(100);
}
}

void lcd_init()
{
lcd_cmd(0x30);      // Configure the LCD in 8-bit mode, 1 line and 5x7 font
lcd_cmd(0x0c);      // display on and cursor off
lcd_cmd(0x01);      // clear display screen
lcd_cmd(0x06);      // increment cursor
lcd_cmd(0x80);      // set cursor to 1st line
}

void lcd_cmd(unsigned char c)
{
output_b(c);
output_low(RS);
output_high(EN);
delay_ms(15);
output_low(EN);
}

void lcd_data(unsigned char z)
{
output_b(z);
output_high(RS);
output_high(EN);
delay_ms(15);
output_low(EN);
}
 

This is the circuit, i used inbuilt functions. It works good. But when using the registers in the program, it makes some problem
 

Attachments

  • lcd.rar
    60.1 KB · Views: 75


Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top