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.

Analogue To Digital & PIC18F4520 & Battery 6V & MikroC

Status
Not open for further replies.

Linspire

Full Member level 5
Joined
Sep 1, 2011
Messages
303
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
M'sia
Activity points
3,279
Guys,
Any idea how to write a proper coding for ATD for showing the voltage level of my battery 5V ?
I want to implement this to check whether the battery face low battery scenario.

I'm not used to ATD field.
Hope someone can guide me.
I have tried simple coding for mikroC.
Here's the coding:
Code:
unsigned int temp;


// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RA1_bit;
sbit LCD_D5 at RA2_bit;
sbit LCD_D6 at RA3_bit;
sbit LCD_D7 at RA4_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISA1_bit;
sbit LCD_D5_Direction at TRISA2_bit;
sbit LCD_D6_Direction at TRISA3_bit;
sbit LCD_D7_Direction at TRISA4_bit;
// End LCD module connections

void main() {
       ADCON0  = 0x13;
       ADCON1  = 0x0E;
       CMCON   = 0x07;
       TRISA   = 0x10;
       ADC_Init();
       Lcd_Init();
       LCD_CMD(_LCD_CURSOR_OFF);
       do{
       temp= ADC_Read(0); // Port A0: AN0
       InttoStr(temp,output);
       Lcd_Out(1,1,output);
       delay_ms(500);
       Lcd_cmd(_LCD_CLEAR);
       }while(1);
}

However, the result shows 5V = 1203
0V = 0
I have tried used variable resistor result's weird.

Regards
Linspire
 

Hi,

Cannot help you with C, but the 4520 has a 10 bit ADC so the result can only be between dec 0 and 1023, so your reading of 1203 must be down to a coding error.
 

Ok.
How about other people ?
Does anyone can guide me ?


Linspire
 

Hmm...Does anyone implement battery indicator ?
I'm still stuck.


Linspire
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top