Maker Pro
Maker Pro

Microcontroller controlled by pushbutton for LED flashlight

Hello,
I want to make an electronic switch that will handle 5a dc, at no more than 5v. It will be controlled by a miniature tactile dome momentary switch. Operation is as follows:
I want the output to be momentary if the switch is pressed for <500ms, mantained if pressed for >500ms. I was considering using an AT TINY4 to fire a couple FET's. All of the components will need to fit on a 14mm round board. Am I on the right track, or is there a better solution? Really looking forward to some advice. Thanks!
 
Last edited:

KrisBlueNZ

Sadly passed away in 2015
Yes, you're on the right track. I would use a small micro such as an ATtiny or a PIC10F200 for an application like this. You could do it with discrete logic but it would be physically quite a lot bigger once you include latch/unlatch and debouncing.

Why do you need two MOSFETs? Does the output need to be push-pull?

How many boards do you plan to make?

Will you hand-assemble or use reflow?

What components have you chosen so far?

Can you tell us more about the power source and the load that needs to be controlled?
 
I chose 2 MOSFETs, as I couldn't find a single that would handle that much current alone. Maybe I didn't look hard enough. I planned on 2 in parallel. I plan on making a couple prototypes by hand, then farming out the rest. Probably 100 or so. Power sources will be Li-Ion, NiMH and alkaline cells. The load will be LED drivers. I haven't chosen components yet. The ATTINY4 just caught my eye due to it's size.
 
Last edited:

KrisBlueNZ

Sadly passed away in 2015
Right. The PIC10F200 is the same size and a bit cheaper, and is also up to the task.

ATtiny4: http://www.digikey.com/product-detail/en/ATTINY4-TSHR/ATTINY4-TSHRCT-ND/2477315 USD 0.69@100x
PIC10F200: http://www.digikey.com/product-detail/en/PIC10F200T-E/OT/PIC10F200T-E/OTCT-ND/2178264 USD 0.39@100x

There are lots of suitable MOSFETs. Here's one: http://www.digikey.com/product-detail/en/DMN1019UFDE-7/DMN1019UFDE-7DICT-ND/3451602 USD 0.30@100x
That one is in a no-lead package so hand soldering would not be feasible; reflow would be required. It may not be the cheapest suitable part either. I found that part on Digi-Key using a filter for N-channel SMT MOSFETs with logic level gate and RDSon less than 10 mΩ. Unfortunately, Digi-Key's selection information has only one RDSon specification per device; mostly, it applies at VGS=10V, not at lower VGS voltages like 4.5V or less, where you will be operating the device. So to be sure, you really need to download each data sheet and look at the RDSon maximum specification for the lowest VGS voltage you can guarantee, given the battery voltage range.

Edit: Maximum RDSon is the most important parameter because you need to limit power dissipation when the MOSFET is ON.

P = I2 × R and I2 = 25 so R = P / 25. Power dissipation for a little package like that should be limited but I'm not sure how much - I haven't worked with such small devices before. Their size implies lower dissipation but the board will provide some heatsinking. My gut feeling is that you should be fine at 0.25W which is why I suggested 10 mΩ RDSON. If you do some research you may be able to get a real life number.
 
Last edited:

KrisBlueNZ

Sadly passed away in 2015
Yes that may be OK. 17 mΩ at 5A will dissipate 425 mW. That seems pretty high for such a small package without an intimate bond to the PCB.

Have a look at these documents:
www.analog.com/static/imported-files/tutorials/MT-093.pdf
ww1.microchip.com/downloads/en/AppNotes/00792a.pdf
www.maximintegrated.com/en/app-notes/index.mvp/id/3930
Give some thought to what will turn it off also.
I assume that pressing the button when it's latched ON will turn it OFF.

Edit: Other suggestions:
http://www.digikey.com/product-detail/en/DMN1019USN-13/DMN1019USN-13DICT-ND/4898885 RDSon(max)=10mΩ@VGS=4.5V SOT-23 USD 0.26@100x
http://www.digikey.com/product-detail/en/AO4402/785-1549-1-ND/3621495 RDSon(max)=5.5mΩ@VGS=4.5V SO-8 USD 0.68@100x
 
Last edited:
Correct, if the output in on, pressing the switch for any duration would turn off. Thanks for the suggestions. I'm not very familiar with package sizes, so it takes me a while to narrow down suitable devices. Quick question: If voltage remains the same, does RDSon remain the same if the load is increased/decreased?
 
I cannot find a better MOSFET than the 2 that you suggested, so I'll get a couple of each of those. Hopefully I'll have room for the larger one that will run cooler. I may be able to center it on the board and mount the switch on top of it. Does the PIC and the TINY use the same programming language? Is there any advantage other than price? Next up would programming. What would be the simplest, most cost effective way to connect & program. I'm new to this, but the little research I have done has shown me that what I am intending to do is very basic. Just define the input and output, then define input conditions that would force the output high or low. This will be a fun learning experience for me, but I don't want to tie up too much time doing it. I will be working with Windows7 laptops & desktops. Thanks again!
 
I cannot find a better MOSFET than the 2 that you suggested, so I'll get a couple of each of those. Hopefully I'll have room for the larger one that will run cooler. I may be able to center it on the board and mount the switch on top of it. Does the PIC and the TINY use the same programming language? Is there any advantage other than price? Next up would programming. What would be the simplest, most cost effective way to connect & program. I'm new to this, but the little research I have done has shown me that what I am intending to do is very basic. Just define the input and output, then define input conditions that would force the output high or low. This will be a fun learning experience for me, but I don't want to tie up too much time doing it. I will be working with Windows7 laptops & desktops. Thanks again!
Hi TT, if you go the PIC route you would need a programmer like:
Pic Kit 3
This is a complete solution. There is a programming IDE and software to upload your code to the pic itself and it comes with the necessary cables. I don't think you will have room on the board for a ICSP so you would probably want to build a dev. board to program the chips. I would build one with a zif socket and a sot adapter so that you can pop the pic's out easily and quickly. There are other programmers that you could use with MPLab's software, but for the current reasonable price, why bother with potential conflicts.
 

KrisBlueNZ

Sadly passed away in 2015
Does the PIC and the TINY use the same programming language?
Both are normally programmed in C or assembly language. Microchip's free programming environment for the PIC includes a C compiler and an assembler. I think Atmel's equivalent does too.

They are very resource-constrained devices and the C language implementations have a number of limitations but would be fine for what you want to do. Writing in assembly language requires more learning, and the PIC and AVR have different instruction sets.
Is there any advantage other than price?
Well, in my opinion the AVR is a much tidier architecture, but this is only really significant if you're programming in assembly language. If you're programming in C, the compilers take care of those details, so no. Both devices have similar built-in peripherals - reset on power-up and brown-out, simple timer, on-board clock oscillator, weak pullups.

PIC and AVR are both fairly widely used, but I think the PIC is more popular. I think they're a pretty poor architecture, so that's unfortunate, but they certainly are cheap!
Next up would programming. What would be the simplest, most cost effective way to connect & program.
Like chopnhack, I have used the PICkit 3 programming adapter, which plugs into a USB port and is supported by the MPLAB X development environment. It's a long time since I used the AVR, and back then I used a very simple programming interface using the PC's parallel port, but modern machines don't have parallel ports, and USB parallel ports don't work, and I don't know what Atmel's entry level programming system is now.
I'm new to this, but the little research I have done has shown me that what I am intending to do is very basic. Just define the input and output, then define input conditions that would force the output high or low. This will be a fun learning experience for me, but I don't want to tie up too much time doing it. I will be working with Windows7 laptops & desktops. Thanks again!
Yes, you're right. You'll need to program the important internal peripherals - set the brown-out voltage, enable the watchdog if you want to use it, configure the I/O directions and weak pullups, configure the timer, and structure your code so that it does the debouncing, timing and output control, and is tidy and reliable.

We have several members here, including me, who can advise you on how to implement your requirements, once you've made a start.
 

KrisBlueNZ

Sadly passed away in 2015
Right, that adapter isn't suitable - you would have to solder the device into the adapter, program it, desolder it, and solder it into your board. Micros are normally programmed in-circuit and Microchip have lots of documentation for how a programming header can be added as part of the design.

You don't have the space or money to waste putting an actual connector on the board, but you could make the programming connections using small pads in various places on the board, or directly to the pads that the micro is soldered onto, using a custom-made programming jig with five individually spring-loaded sharp points made from pins (or old gramophone needles, if you have any!). Like an upside-down "bed of nails" of the kind that's used for board testing.

You can probably find products ready-made to do this. I don't know what keywords to Google or what companies to try, sorry, but someone else here probably does!
 
Any socket solution is likely to be too large for your 14mm diameter board.

The kind of pins for making temporary connects that Kris referred to are called spring-loaded contacts.

http://www.digikey.com/product-sear...ee=0&rohs=0&quantity=&ptm=0&fid=0&pageSize=25

You would use these by making pads on your target board in a specific pattern, then soldering the spring-loaded contact to another board in the same pattern and connecting them to a header for the PICKIT. Then you just press the pins onto the contacts on your target board when programming.

I have not used these myself, but have heard of others using them successfully to solve this problem.

Bob
 
My thought was to use a socket like that to program a few micros for prototypes, not mount it on the board. Not worth the price for that purpose though. Thanks for the link to the pins.
 
My thought was to use a socket like that to program a few micros for prototypes, not mount it on the board. Not worth the price for that purpose though. Thanks for the link to the pins.
This is what I was referring to as well - using the socket on a developer board to make it easy to program all your chips. They could be popped out and then soldered into the final device. The sockets are pricey as you have found.

Another option would be to make contacts at the edge of the board, maybe you can fashion an appliance on a hinge that when closed will make contact with the edge pads on the board. Think like the ram slots of computers.

FYI - the pictured item is a counterfeit MPLab's device. Look at the logo, its a w (see pic below, its a M). See if you can cancel. The reason its close to home is a bit of a lie, its a bulk chinese distributor that states they have a "local" warehouse. This may or may not be true. Most of the Chinese sellers that offer e-packets for shipping have very good transit time.

$_12.JPG
 

KrisBlueNZ

Sadly passed away in 2015
Yeah, chopnhack is right that the one you ordered is a counterfeit. It's best to order direct from Microchip. It might cost a bit more, but it's a lot more likely to work, and if it doesn't, you have some kind of recourse.

I strongly recommend providing in-circuit programming using spring-loaded pins - either through pads scattered around the board, or by direct contact with the device's pins on its mounting pads - because there's a pretty good chance you'll be wanting to reprogram devices after they've been soldered into your board, at least during the early stages of the project.
 
Well shit, I wasn't aware that these were being counterfeited. It's too late to cancel through eBay, but I contacted him and asked for a refund before he ships. I'm sure he'll respond with the typical lie "it's too late, it already shipped". If so, I'll open a case with eBay when it arrives. Looks like I may have just thrown away $30.
 
Top