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.

[AVR] Attiny13A + pushbutton + LEDs

Status
Not open for further replies.

bob808

Newbie level 3
Joined
Oct 20, 2013
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
62
Hello all,

I got a cheap headlamp with a powerful LED and the trouble is that the driver inside is real bad. On High mode the cheap mosfet gets at over 100 degrees C.
So I decided to build myself a proper driver board.
I want to have 3 modes on it. Low (moonlight mode), Medium (1.4A) and High(3A).
I didn't want to mess with pwm and so I went this route: for the moonlight mode I use 1x AMC7135 current sink at 350mA. For the Medium mode I have another arrangement of 4x AMC7135 totalling 1.4A. And for the full output I'm using a PSMN0R9-25YLC N-Channel Mosfet.
These three modes need to be triggered from the pins of the Attiny13A.
Another input pin is to be used for the pushbutton.
Basically I'm looking to program the Attiny13A in this sequence. On each press of the button to cycle High the next output pin, and low the others. After I cycle through all 3 output pins, to pull low all of them.
I managed to adapt some pieces of software to flash all of them at once, or to flash each one. But can't figure out how to use the button and cycle through all of them.
I also provisioned on the board a sense pin for the battery voltage, so I maybe implement a shut-down feature when the voltage is below a threshold. But right now that is not important.

Right now the pins are as follow:
PB0 - Moonlight (1x AMC7135)
PB1 - Mosfet (full power - 3A)
PB2 - input from battery with voltage divider
PB3 - Button input
PB4 - Half output (4x AMC7135 1.4A)

This is the way I designed my pcb, can't change it as I've already soldered everything apart from the mcu.
I attached a photo of the pcb. If there's anyone who wants the pcb files I can provide them for free :)
I find this setup nice as it doesn't messes with PWM. And has about everything that's needed (low, mid, high, battery monitoring).
Also I provisioned the board for the button to be pull up and pull down (smd resistor pads that can be used as jumper pads). There's a status led for when it's on etc.
Now, where do I look so I can manage to figure out how to first cycle through the PB0 - PB4 - PB1 pins (as output) and then pull all of them down (and enter sleep mode after all pins are pulled down to save battery when I don't use the headlamp) ?
I tried to find some help on budgetlightforum.com but received none. Probably because my project is open and there's enough people selling their stuff over there so ... yeah.
Basically this is a XM-L2 3A driver used for the cheap headlamps found on ebay. Fits in place of the crappy original ones.
Any help is appreciated.
Thank you.
 

Attachments

  • IMG_5339.JPG
    IMG_5339.JPG
    889.6 KB · Views: 84
  • Screen Shot 2016-03-16 at 23.43.12.png
    Screen Shot 2016-03-16 at 23.43.12.png
    53.5 KB · Views: 96
  • Screen Shot 2016-03-16 at 23.42.12.png
    Screen Shot 2016-03-16 at 23.42.12.png
    104.6 KB · Views: 97

So far I managed so far:

Code:
#include <avr/io.h>
#include <util/delay.h>

void ProcessPressedButton(int ButtonPressed);
void ProcessReleasedButton(int ButtonReleased);

int Pressed_Confidence_Level[2];
int Released_Confidence_Level[2];
int Pressed[2];
int LEDNumber[2];

int main(void)
{
	DDRB = 0b00010011;
	PORTB = 0b00001100;
	
	while (1)
	{
		if (bit_is_clear(PINB, 3))
		{
			ProcessPressedButton(0);
		}
		else
		{
			ProcessReleasedButton(0);
		}
	}
}

void ProcessPressedButton(int ButtonPressed)
{
	Pressed_Confidence_Level[ButtonPressed] ++;
			if (Pressed_Confidence_Level[ButtonPressed] > 500)
			{
				if (Pressed[ButtonPressed] == 0)
				{
			
		                  //This needs work.
						
				}
				Pressed_Confidence_Level[0] = 0;
			}
}

void ProcessReleasedButton(int ButtonReleased)
{
	Released_Confidence_Level[ButtonReleased] ++;
	if (Released_Confidence_Level[ButtonReleased] > 500)
	{
			Pressed[ButtonReleased] = 0;
			Released_Confidence_Level[ButtonReleased] = 0;
	}
}


I managed to get here thanks to Patrick Hood-Daniel from youtube. I followed his tutorials, and managed to adapt his work for my needs. I still need to go through the three pins but right now I'm just up in the air. I added the button debouncing stuff as well.
Any ideas?

Also haven't cleaned the arrays. He used them for two buttons. Hope I find some time to work on it.
 
Last edited:

Apart from the programme , your schematic needs certain clarification.


What is BAT+ voltage?
There is a connection from all Vdd pins of AMC 7135 to
PB4?
Do you intend to switch on the driver with this pin?

Key is connected to R8 and R10.
How the switch is connected to KEY?

PB1 controls MOSFET which is in parallel with out of AMC 7135.

If your intention of having three modes of light control to be done , may be you have to redesign the circuit.
 

The battery voltage will come from 2x18650 batteries in parallel, so between 3.6V - 4.2V
There is a connection from all Vdd pins of only 4 out of 5 AMC 7135 to PB4. The Vdd pin of a single AMC7135 is connected to PB0. On PB1 is the gate of the mosfet.
AMC7135 are switched on on the VDD pin and they sink 350mA of current.
I intend to pull up in turns each PB0, PB1 and PB4 pins. First PB0, then PB4, then PB1. When the next one is pulled up, the previous one must be pulled down. After PB1 is high the next button press must take all of them low and start from PB0 again on the next press.
Key is connected to R8 and R10, depending if I use the key to pull up or down. I can leave R10 uninstalled and solder bridge across R8 for pull down action on the button. The button itself can be wired on gnd or +V that is present on the LED. (Button is in led heatsinked case, away from the box that has batteries+driver).
The mosfet has it's gate connected on PB1. It is in parallel with the AMC7135 chips but if their Vdd is low, then they don't sink current, it goes only through the mosfet if it's gate is pulled up. Or at least I hope it does that :)
I don't understand why I can't have three modes in this format.
 

Now it is clear.

First PB0, then PB4, then PB1.

You can have three modes.

The folw can be:

for each key press,
cycle thro:

PB0 PB4 PB1
1 0 0
0 1 0
0 0 1

fourth press: all 0 0 0.


The values of R12 and R13 , R11?
 
  • Like
Reactions: bob808

    bob808

    Points: 2
    Helpful Answer Positive Rating
I haven't decided yet. 100R -1K or so I think.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top