Volt meter Atmega8

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I want to make a LED driver for my motorcycle but i have some problems with it, the adjustment doesnt really work properly.
I have a shunt resistor(0.68 ohm) in series with the LED group connected to the ground. On ADC1 i measure the voltage between ground and led group input. With the voltage reference set to ex. 0.01V on the shunt resistor, i want to keep this voltage over the shunt resistor even if the main supply voltage isn't stable and varying between 12 and 15V.The led's group is driven at 200Hz.
The positive input of LED's by a mosfet transistor connected to PB2 and the current limiting is made by varying the duty cycle.

The MCU is Atmega 8(4Mhz internal clock) and the reference voltage is 2.5V.
I make the debugging over a LCD display.

#include 
#include  
#include "lcd.h"
#include 
#include 

char s[7];
float voltage;

volatile unsigned char LcdDelay;   // 1 mS signal
static uint32_t new_value;

ISR (TIMER0_OVF_vect) 
{
// timer
 static unsigned char Count1mS = 0;
   static unsigned char Count10mS = 0;
   
   TCNT0 += 6; // Adjust count so we get 250 uS rollover period
   
   if (++Count1mS == 2)
   {
      // Set a flag to indicate 1mS has elapsed
      Count1mS = 0;
    
	if (++Count10mS == 200) // 200ms
	{
	Count10mS = 0;
	LcdDelay = 1;

	}
	
	}
	}
// -------------------------------------------------------------------
void Timer_0_setup(void)
{
// setup timer 0
 TCCR0 |= (1 << CS01); // 8 divider
TCNT0 = 0;            // Initial value 
TIMSK |= (1<<TOIE0); //Timer/Counter0 Overflow Interrupt Enable
 
}
//-------------------------------------------------------------------
void adc_init(void)
{
//ADC init
	ADCSRA |= (1 << ADPS0) | (1 << ADPS2); // Set ADC prescalar to 32 - 125KHz sample rate @ 4MHz

   ADMUX |= (1 << REFS1); // Set ADC reference to AREF
   ADMUX |= (1 << ADLAR); // Left adjust ADC result to allow easy 8 bit reading
   ADMUX |= (1 << MUX0);// ADC1
   ADCSRA |= (1 << ADFR);  // Set ADC to Free-Running Mode
   ADCSRA |= (1 << ADEN);  // Enable ADC
   ADCSRA |= (1 << ADSC);  // Start A2D Conversions

}

//-------------------------------------------------------------------

void pwm(void)
{
// OCI1B

// Set on match, clear on TOP
   TCCR1A  = ((1<<WGM11) | (1 << COM1B1) );

   // Fast PWM, Fcpu speed
   TCCR1B  = ((1<<WGM13) | (1<<WGM12) | (1 << CS11));

   //where 0xA is the desired brightness
   ICR1  = 2499; // 200Hz

}
//-------------------------------------------------------------------

int main(void)

{
DDRB |= (1 << 2); // Set led as output
Timer_0_setup();
adc_init();
pwm();
new_value = 0;
// LCD init
lcd_init(LCD_DISP_ON); /* initialize display, cursor off */
lcd_clrscr(); /* clear the screen*/

  while (1) /* loop forever */
   {
cli();
    //Voltage
voltage = ADCH * 0.0097;

//if (voltage < 0.01)
if (ADCH < 1)
{
new_value ++;
} 
else if (ADCH >= 1)
{
new_value --;
}
OCR1B = new_value;

 sei();

//OCR1B = 1000;

if (LcdDelay==1)
{
lcd_clrscr();

  lcd_gotoxy( 0, 0 );	
lcd_puts("ADCH:");
// voltage display with 2 decimals
lcd_gotoxy( 5, 0 );	
 utoa(ADCH, s, 10);
lcd_puts(s);

lcd_gotoxy( 8, 0 );	
 utoa(new_value, s, 10);
lcd_puts(s);
// Voltage
lcd_gotoxy( 0, 1 );	
lcd_puts("Batt:");

// voltage display with 2 decimals
lcd_gotoxy( 7, 1 );	
dtostrf(voltage,4,2,s);
lcd_puts(s);

lcd_gotoxy( 11, 1 );	
lcd_puts("V");

LcdDelay = 0;
}
}
}

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't think this is going to work well. Three LEDs with (assuming) 3.4V drop each, is 10.4V, so 15-10.4=4.8V across a 0.68R resistor is over 7A. This is very likely many times the absolute max rating of the LEDs.

The normal way is to include an inductor and switch at high frequency; basically a switching power supply.

I think it would be wise to include a resistor in each string to balance the current; unless the LEDs are all from the same batch and have identical properties.

I'd use a dedicated switcher for this; the low dynamic resistance of the LEDs mean there is only a narrow range of voltages/PWM values where it works; an analog chip has infinite resolution.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes i know there are IC's like LM3409,3421,3423,3424,3429 but for each type of LED's I need to recalculate the coil/resistor/capacitor value and the cost is high compared for what i wan to use.
in this example all LED's are the same piranha flat top MAX: 3.4V, 20mA.
The group is made from 3 led's in series(9.9V), 15mA(225mW)/group(dissipation: 76.5mW ). in total is ~60mA(900mW, dissipation: 306mW).At 15V with a resistor of 340 ohm in series with each group those figure should be real.

And back to my code, what is wrong...because it isn't adjust the output current like i need.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
the adjustment doesnt really work properly.

Quote:
4.8V across a 0.68R resistor is over 7A.

Quote:
3.4V, 20mA.

These are already dead. Get new leds.

Quote:
what is wrong...because it isn't adjust the output current like i need.

That is your problem:
Quote:
I make the debugging over a LCD display.

JTAG.

Aren't you exaggerating with this HEXFET a little bit (about 3 orders of magnitude)?
23 Amperes? 50W dissipated power? Vdss at 100V? This transistor is made for switching 2300W devices, while yours is only 1,8W.
Connect those leds directly to AVR.

No RSTDISBL, no fun!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't see why you are bothering with regulators at all, be it a dedicated switcher/driver or MCU. And you can't escape a bit of component tweaking if you want to use wildly different LEDs.

If you want dimming, just use a 555 or so and use a simple BJT as current source for constant intensity.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Looking at the original schematic, I agree with JJ that you need a small resistor in series with each string of LEDs.
The data spec is an approximation. The LEDs will have slighly different Vf drops.

I am not sure what the ADC is actually measuring. The ADC is suppose to have an input source impedance of <= 10K, you have > 100K.
I understand why you did this, but this is way out of spec for the ADC.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use a LED driver IC.

I design LED driver boards for a living and trying to deal with an automotive noisy environment with a software control loop is a major waste of time.

Also, your PWM approach will not work, since you are just turning your main FET 100% on, 100% off. During the on time you have full battery voltage feeding your series string LEDs - you will destroy them. Voltage glitches etc on your motorbike (worse noise than a car) will destroy your LEDs since there's no filtering/protection in your design.

LED driver IC's are EASY to use and I'm not sure why you think you need to change L's/R's/C's etc for different LEDs. Basically all you need to do is set the driver design up for you LED current output and very approximate total Vf and you're good to go.

If you want to get fancy, then use a switcher IC and interface your uC to it to provide dimming and voltage measuring/display features. Linear Tech makes some VERY nice LED driver IC's.

Also, what are you using your little LED array for - is it for backlight for your LCD panel? If so, there's plenty of backlight LED driver IC's out there that are easy to use.

cheers,
george.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The transistor and the led's are for test not for the final project, i don't want to destroy expensive led's.
But in most of case i use much more powerful transistors than the actually needed, because: i don't have space for cooling, no heatsink, the cover box is weatherproof(no air in or out), it must work in most hostile environment without failing: direct sun...high temperature.
At the final i will control the voltage to but first i want to control the current flow.
sorry the resistor is 10k not 100k ... it is a mistake of mine.
The final led's will be: Cree MC-E M,LED Cree XP-E and my favorite LED Cree MP-L(for low/high beam).
For instance take LM3409, it must be 100% like on the datasheet (the PCB, the passive component). for each led,array i need to calculate the peripheral components.On the link below you find a web application Webench led design which help to calculate the correct component value.
I don't know how many led's i will use and the configuration, only after live test and for each time i need to order the peripheral components(the cost will be higher).With MCU i wan to make it more flexible and easy to use.

http://www.national.com/pf/LM/LM3409.html#Overview

In classic case where the supply voltage is stable, i connect in array the amount o led's for the maximum supply voltage but in this case i need to connect for the minimum voltage (which could be below 12 some times)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So you choose a difficult, inferior solution just to save on ordering a few cheap peripheral components; which are just one inductor and the current sense resistor. Even with the MCU solution you just replace the LM3409 as a control element, you still need the inductor, FET and current sense resistor which too need to be matched to the final application. And PCB layout is still as critical.

Have you already thought out the optics and thermal issues? You just can't plonk a few power LEDs into a headlamp and expect to have an useful (and legal) beam pattern. Even retrofitting an HID bulb into a lamp designed for an incandescent light source is a sub-optimal solution because the light spot emitted by the HID burner is different from an incandescent bulb. It looks the same to naked eye but it really is not.

And your favourite LED has a forward drop of 25V; you'd need a step-up converter for that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You know, you can make "LED driver" using two transistor, zener diode and some resistors?
It's also called constant current source, it is very simple, reliable and only disadvantage is, one transistor heats up little bit. I can send you schematic, if you are interested.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
You just can't plonk a few power LEDs into a headlamp and expect to have an useful (and legal) beam pattern.

That is an important issue. Headlights are subject to testing/homologation standards (same as breaks, seat belts..).

No RSTDISBL, no fun!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, it is to soon to tell something about the headlights, what i'm planing is to use ~6 LED Cree MP-L led's(1 for daylights + 2 for the low beam and 3 for high beam). I don't know how i will arrange them(for ex. in matrix) but i want to cover them with projector lens(often is used for xenon) in this mode i don't need to homologate.

something similar only more simple without angel eye.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't think that's ever going to work. The light pattern from the LEDs is vastly different from a HID burner. Of course some light will come out of the lamp, but whether this is useful at all, I highly doubt it.

Headlamp design is not something trivial and it's always optimized for a very specific light source. I don't say it's impossible, but it requires special custom optics.

You also need to move away vast amounts of heat from the LEDs which complicates matters.

There's a reason there are only a handful of cars with LED headlamps now; so I don't expect one person to be able to design such thing from scratch successfully :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the cooling system isn't complicate, i will use a P3 processor cooler, beside this it will be a cooling system like on the new speed bikes with air intake to the headlamp.
My bike is a tourer/naked and the headlamp isn't covered, only by a simple windscreen.With an air tunnel i can get enough air to cool the led's even at low speed.during the day i will use only 1 led(daylight) and at night the rest....low/high beam.