Long button press input?

ac21

Member
Is it possible to code a momentary button's long press at a input?
for instance.. pressing it once turns on a light, pressing it again will turn it off, holding it down for a set amount of time will make it flash.


also on a unrelated topic what do ya'll think about this Mosfet? I should be able to run the gate off a pin right(1k resister in between and 100k gate to source)? and if i were to max out the 15amps, it has a Ipak package how do u heat sink this?

Mosfet http://www.mouser.com/ProductDetail/International-Rectifier/IRLU3410PBF/?qs=sGAEpiMZZMshyDBzk1/Wi5%2bqVgN3%2bWS8UZoRnnZhnhk=

DataSheet http://www.irf.com/product-info/datasheets/data/irlr3410pbf.pdf
 
Last edited:

MartinM57

Moderator
Yes you can - IWP has shown you one way of doing it.

One subtlety you may have to deal with is having to think about:

- what you need/want to do when the button is initially pressed - if anything at all

- what you need/want to do when the button is released - as that is the only way of telling how long the button was actually pressed for

- maybe even what you need/want to do at various points during a very long press

...and how that affects the user's perception of the device - they often want things to happen when the button is pressed but this approach tends to focus on doing things when the button is released

Beware, it can quickly fry your brain and make your PICAXE code pretty complicated :)
 

inglewoodpete

Senior Member
I should add that practically all of my PICAXE software that uses keypad input uses the release of a key/button as the trigger to action something. The key press just starts some form of timer.
 

Goeytex

Senior Member
This may give you an idea on how to do it.

The program jumps to the longpress routine while the switch is still down.



Code:
#picaxe 18M2
#no_data

symbol Switch_Duration = b0

setint %00000010,%00000010

MAIN:
do             '// Waiting for switch interrupt
pause 10
loop

interrupt:
pause 20    '// Debounce
 
 do while pinc.1 = 1     '//  Timer
 
     pause 20
     inc switch_duration
     if switch_duration >  100 then longpress        '// ~ 2 seconds
         
 loop
 
  
 
  shortpress:
  '// do something here
  sertxd ("SHORT",cr,lf)
  switch_duration = 0      '// clear the timer 
  setint %00000010,%00000010
  return
  
  longpress:
 '// Do something here
 switch_duration = 0      '// clear the timer 
  sertxd ("LONG",cr,lf)
  
  do loop while pinc.1 = 1   ' // make sure sw is released before returning to main
  setint %00000010,%00000010
  return
 

Circuit

Senior Member
also on a unrelated topic what do ya'll think about this Mosfet? I should be able to run the gate off a pin right(1k resister in between and 100k gate to source)? and if i were to max out the 15amps,
The specification is a 17 amp Continuous Drain Current with VGS @ 10V - so I don't think that the drive voltage to the gate from a PICAXE will allow you to switch 15 amps. Have a look at Figure 2 in the sheet and you will get a better idea of what current the device can switch for a range of gate-source voltages.
 

Goeytex

Senior Member
The specification is a 17 amp Continuous Drain Current with VGS @ 10V - so I don't think that the drive voltage to the gate from a PICAXE will allow you to switch 15 amps. Have a look at Figure 2 in the sheet and you will get a better idea of what current the device can switch for a range of gate-source voltages.
I think you guys are misreading the datasheet. Figure 2 shows the maximum current over a range of VDS (Drain to source Voltage) , not VGS ( Gate to Source Voltage).

As long as the gate threshold voltage (plus about 1v) is reached, the FET will drive at the current determined by the load resistance, RDSON, and supply voltage ..... up the the max shown in figure 2. The difference between a VGS of 3.5 and a VGS of 10 is the time the FET spends in its linear zone. It will reach 17 AMPS in either case ( Assuming a high enough VDS) , it will just get there faster with a VGS of 10.

That being said, I do not particularly like this FET, especially for switching anything over a few hundred Hz. By modern standards it has a high RDSON of over 100 mOhms. And will get really hot if switching high currents at high speeds.

These FETs are heat-sinked via a copper pad on the PCB, usually with the tab (Drain) tied to a large power plane copper layer.
 
Last edited:

ac21

Member
I think you guys are misreading the datasheet. Figure 2 shows the maximum current over a range of VDS (Drain to source Voltage) , not VGS ( Gate to Source Voltage).
i was thinking the same

4v at the gate should give me close to 15amps due to it being logic level?
 
Last edited:

Goeytex

Senior Member
"Logic Level" is a misleading term. You MUST ALWAYS read the datasheet and get the MAX Gate Threshold Voltage. This is the voltage where the FET just begins to conduct. It will NOT fully conduct until the voltage at the gate reaches the Gate Threshold plus about 1 to 1.5 volts. This FET has a max threshold voltage of 2.0. It will not fully turn on until about 3 volts. So at 4V logic it will be fine as far as that goes.

However I would not use this FET for switching 15 amps. Why?, Because it will heat up and then need to be derrated to about 10amps. If it continues to operate at 15 amps while over the allowed junction temperature it will blow. This is all dependent upon the switching speed. But you have provided no details.
 

Circuit

Senior Member
I think you guys are misreading the datasheet. Figure 2 shows the maximum current over a range of VDS (Drain to source Voltage) , not VGS ( Gate to Source Voltage).

As long as the gate threshold voltage (plus about 1v) is reached, the FET will drive at the current determined by the load resistance, RDSON, and supply voltage ..... up the the max shown in figure 2. The difference between a VGS of 3.5 and a VGS of 10 is the time the FET spends in its linear zone. It will reach 17 AMPS in either case ( Assuming a high enough VDS) , it will just get there faster with a VGS of 10.

That being said, I do not particularly like this FET, especially for switching anything over a few hundred Hz. By modern standards it has a high RDSON of over 100 mOhms. And will get really hot if switching high currents at high speeds.
I am grateful for this further explanation (I am still trying to find my way around datasheets and to interpret them correctly), but I cannot quite understand your reading of Figure 2.

This is a graph that shows the Drain-to-Source current on the Y axis against the Drain-to-Source voltage on the X axis for a range of Vgs values.
I understand the nature of the threshold Vgs value but my understanding is that, from that point, the Drain-Source ON resistance decreases with an increasing Vgs up to a finite point, which on this graph appears to be at 10 volts. The Vgs line on the graph for 2.5 volts, for example, implies that the current cannot approach 2 amps, but you suggest that, with a Vgs for the device of 1.8 volts, maximum conductivity should be approached at this value and certainly exceeded by 3 volts. But the 3 volt Vgs line shows a plateau at 4 amps.

Please help me to understand where my interpretation of the graph is in error. I am puzzled and I would really like to fully understand logic-level MOSFETs.
 

lbenson

Senior Member
I'll add my thanks for your explanation, and ask what 3.3V-capable through-hole MOSFET(s) you would recommend instead?
 

Goeytex

Senior Member
Actually, Circuit was reading the IRLR 3410 datasheet correctly, It was just that I could not imagine a "logic level", FET would perform so poorly at common logic levels. Also The SPICE model supplied by IR by does not match the published data in Figure 2. With a VDS of 20 the , the model shows an ID of 18 amps, with 5v VGS, and 9.7 amps with 3.3v VGS. I would not recommend this FET unless used with a FET driver that can supply a min VGS of 10V. This FET is a dog for high current switching with a Logic level gate drive. Not only will it never reach max current at common logic level gate drives. It will have to dissipate tons of heat if operated from a Picaxe IO pin that is safely current limited. At 10KHz/ 50 percent duty,VDS of 20v, and a 1 ohm load, it will have to dissipate over50 watts of heat with a Picaxe driving it @ 3.3v.... and it will never reach 17 amps.


Compare the IRLR3410 with the STD30NF06L see OUTPUT Charistics Chart .

It will reach the 17 amps and will have to dissipate about 5 watts under the same conditions.

To recommend a FET, I would need to know the drive method , switching frequency,max duty cycle, load resistance, VDS, etc.
 
Last edited:

lbenson

Senior Member
STD30NF06LT4 mosfet: nice part, but not available in through-hole from digikey or mouser.

For a standard picaxable mosfet part, I would be looking at 3.3v drive through a 330R (say) from a picaxe pin, just on/off, no PWM, up to 10 amps.

I don't know that anyone yet has recommended high-speed PWM to a MOSFET from a picaxe without a driver chip.
 

Goeytex

Senior Member
The Through hole requirement is a deal killer. Tons of stuff in SMD.

Best I could locate in stock from Mouser or Digikey in through hole is the STP27N3LH5.
VGSth MIN = 1 VGSth MAX = 2.5. RDSON = 20m Ohms Probably OK at 3.3V drive. Cheap, get a couple and try them out.

Another one with promise is the IPP114N03L. In stock @ Digikey. VGSth MAX = 2.1
And another even better. STP60NF06L. VGSth = 1V. Good up to 40 amps with VGS @ 3.3V. In stock @ Mouser & Digikey
 
Last edited:

lbenson

Senior Member
Ordered some of the STP60NF06L Mosfets from Digikey. Also NTD5867NL-1G and IRLB8721PBF. So I'll see. Thanks for the suggestions.
 
Top