ATMEGA128 and DS2438 ?

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Visit site
Activity points
9,442
Hello Guys,

Does anyone of you have experience with battery monitoring ?
Which one is good for monitoring 12V battery ?
I saw DS248....what do you reckon ?

I want to monitor my battery with it and display the voltage status on LCD..

Any clues will be very appreciated,

Thank you
 

No need for special IC, just use uC ADC with voltage divider.

If you plan to monitor remote battery over 1-wire then use 1-wire IC.



Best regards,
Peter
 

That's good idea any circuit and code example ?

Nothing special, you can find tons of examples on EDABoard for this. See examples in my blog (ADC:0-5V Input:0-20V). Just use voltage divider with adequate resistors, put one capacitor for averaging and zener 5,1V for ADC protection. You can even log that value periodically in EEPROM.


Best regards,
Peter
 

Yes, try to play with resistor calculation or try with small trimmer.

This ensures input voltages in 0-5V range, and in my blog you can find various codes for this in MikroC.

Use OpAmp if you have small voltage on input, such as voltage drop on current shunt resistor, and appropriate circuit to make 0-5V voltage for ADC.

Zener diode is safety for ADC pin.

For 20V try for R1 3,9K and for R2 1,3K.

You can play with voltage divider and OpAmp without ADC and uC, just use voltmeter, when you define configuration use on uC ADC.





In your Blog you have posted images of Blue LCD. In which simulator you got the Blue LCD?

Its LCD Screenshot Generator, you can download from here:

https://avtanski.net/projects/lcd/

Its fast and usefull for documenting code or project.




Best regards,
Peter
 
I created like this :
Code:
uint16_t read_adc1(void)
{
	ADMUX=(1<<REFS0) | (1<<ADLAR) | ADC_1;    // Conversion on channel 1, AVCC reference, 10 bit mode
	ADCSRA |= (1<<ADSC);                     // Start conversion
	loop_until_bit_is_clear (ADCSRA, ADSC);         // Wait for conversion complete
	return(ADCH);
}

I want to measure the voltage from channel 1 of ADC on ATMEGA128

- - - Updated - - -

Which Compiler do you use? Atmel Studio or mikroC AVR PRO? I can give you code which is for mikroC PRO AVR Compiler.

I use Atmel Studio

- - - Updated - - -

I've done :

Code:
void adc_init()
{
	// enable ADC, select ADC clock = F_CPU / 128 (i.e. 125 kHz)

	ADCSRA = (1<<ADEN | 1<<ADPS2 | 1<<ADPS1 | 1<<ADPS0 );

	//Do a conversion to get rid of rubbish

	ADMUX=(1<<REFS0 | ADC_0);                  //Conversion on channel 0, thermistor input
	//Internal VCC Voltage Reference
	ADMUX=(1<<REFS0 | ADC_1);                  //Conversion on channel 0, thermistor input
	//Internal VCC Voltage Reference

	ADCSRA |= (1<<ADSC);                      //Start conversion
	loop_until_bit_is_clear(ADCSRA, ADSC);    //Wait for conversion complete
}


uint16_t read_adc1(void)
{
	ADMUX=(1<<REFS0) | (1<<ADLAR) | ADC_1;    // Conversion on channel 1, AVCC reference, 10 bit mode
	ADCSRA |= (1<<ADSC);                     // Start conversion
	loop_until_bit_is_clear (ADCSRA, ADSC);         // Wait for conversion complete
	return(ADCH);
}

double resistor_get_voltage(long adcresistence)
{
	
	double t;
	t = log( adcresistence );
	return t;
}

Code:
	adc_result=read_adc1(); //read the voltage from ADC1
		adcA = ((int)(adc_result*5.0)/1024.0)*1000; 
		d = resistor_get_voltage(adcA);

		
		if (adcA != 0)
		{
			adcresistance = (long)(10230000/adc_result-10000);	
			sprintf(voltage,"%.2f",d);
			lcd_string(voltage);
		}

Please correct me if I missed something here,
thanks
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…