How To Build a Flashlight With Perfect Modes (picture heavy)

863 posts / 0 new
Last post
Proto
Offline
Last seen: 9 years 1 month ago
Joined: 09/23/2011 - 20:47
Posts: 10
Location: Michigan

Hi first post, 

 

 I have been following this thread with great interest (thank you Tido and everyone for the resource) and have purchased an avrispmkII and 3M soic clip. I am trying to reprogram a 2.8amp (8x 7135) driver that I purchased from Shiningbeam. I've hit a snag. Below is a screenshot of the error message I'm receiving. At first I thought the connection was bad but the green light comes on after I run the command, apparently indicating that the chip/target is receiving power. I've checked pinout three times, and I seem to have continuity in all pins. Any ideas from anyone? Is this the type of message I would get if the reprogramming fuse is set to prevent re-writing? Anything else I could check? 

 

 -Jon

Macintosh-3:~ JCI$ avrdude -P usb -p t13 -c avrispmkII -n

 

avrdude: stk500v2_command(): command failed

avrdude: stk500v2_command(): unknown status 0xc9

avrdude: stk500v2_program_enable(): cannot get connection status

avrdude: initialization failed, rc=-1

         Double check connections and try again, or use -F to override

         this check.

 

 

avrdude done.  Thank you.

E1320
E1320's picture
Offline
Last seen: 9 months 4 days ago
Joined: 03/30/2011 - 05:26
Posts: 3376
Location: New Hampshire

Looks like your connection isn't good, but I gave up a while ago I hit a dead end with my programming at this point. I actually de soldered a tiny13 chip to play around with so I can get the connections on easier. Sorry I couldn't be more help.

I am already visualizing the duct tape over your mouth.

E1320
E1320's picture
Offline
Last seen: 9 months 4 days ago
Joined: 03/30/2011 - 05:26
Posts: 3376
Location: New Hampshire

Use your multimeter and go from the clip to the programmer and make sure there is continuity again. It is written kind of weird I had to do mine twice because i read it wrong the first time before i got the right connections.

 

 

 

http://flashlight-wiki.com/AVR_Drivers

I am already visualizing the duct tape over your mouth.

Proto
Offline
Last seen: 9 years 1 month ago
Joined: 09/23/2011 - 20:47
Posts: 10
Location: Michigan

Thanks for the suggestion, I double checked the continuity with DMM and even soldered the leads directly to the pins on the chip, and the continuity was good between avrisp board pins and the chip pins. I don't know what else to do. I have another question: if you test the voltage between the vcc and gnd pins on the programmer (avrispmkII), should there be a constant voltage of 5V? Mine is showing basically no voltage between vcc and gnd on the programmer. I know I'm using a power usb.  

E1320
E1320's picture
Offline
Last seen: 9 months 4 days ago
Joined: 03/30/2011 - 05:26
Posts: 3376
Location: New Hampshire

Proto wrote:

Thanks for the suggestion, I double checked the continuity with DMM and even soldered the leads directly to the pins on the chip, and the continuity was good between avrisp board pins and the chip pins. I don't know what else to do. I have another question: if you test the voltage between the vcc and gnd pins on the programmer (avrispmkII), should there be a constant voltage of 5V? Mine is showing basically no voltage between vcc and gnd on the programmer. I know I'm using a power usb.  

I just pinned mine out and except for the ground closest to the VCC pin the rest have 5 volts (VCC-Ground)

I am already visualizing the duct tape over your mouth.

Proto
Offline
Last seen: 9 years 1 month ago
Joined: 09/23/2011 - 20:47
Posts: 10
Location: Michigan

So I just finished reading a review of the avrisp mkII, and it happened to mention that this programmer only senses voltage, but does NOT supply power to the target. Oops. So, I connected an xml to the driver, and soldered up a simple switched circuit to power the driver with 1 18650 3.7V li-ion, and wouldn't you know it, now I get a response! Of course, being me, I don't get the correct response:

Macintosh-3:~ JCI$ avrdude -P usb -p t13 -c avrispmkII -B 1 -u -Uflash:r:flash-dump.hex:i -Ueeprom:r:eeprom-dump.hex:i -Ulfuse:r:lfuse-dump.hex:i -Uhfuse:r:hfuse-dump.hex:i

 

avrdude: AVR device initialized and ready to accept instructions

 

Reading | ################################################## | 100% 0.01s

 

avrdude: Device signature = 0x068001

avrdude: Expected signature for ATtiny13 is 1E 90 07

         Double check chip, or use -F to override this check.

 

avrdude done.  Thank you.

Does anyone know why my attiny13A chip would spit out the wrong device sig? Anything I can do about it?

One thing I do know is that I'm getting a USBtinyisp so I don't have to rig a separate power source, which is cumbersome and impractical to use.

So, some progress, but still not able to load Tido's code yet. 

 

 -Jon 

E1320
E1320's picture
Offline
Last seen: 9 months 4 days ago
Joined: 03/30/2011 - 05:26
Posts: 3376
Location: New Hampshire

that is were i have been for about 2 months now

I am already visualizing the duct tape over your mouth.

parkerdude
Offline
Last seen: 4 months 3 weeks ago
Joined: 06/20/2011 - 23:50
Posts: 228
Location: St. Louis, Missouri

Wow,

When I first saw this thread, I was excited. I was thinking that I could get a 4-Mode driver w/memory, High-100%, Medium-50%, Low-15%, Moon-light-2%.

This conversation has gone so far over my head, that I'm back to searching the internet for an alternative. I don't think that this level of modding is EVER going to be within my reach 8-( .

Just to throw in my 2¢, if anyone gets to where they are custom programming some of these drivers, I'd like to buy 3-5 of them. Nothing fancy, just 4 modes, no strobes, w/memory.

Let us non-programmer types know. I'm still going to keep watching, but I'm not understanding a lot of what I'm reading.

Thanks, and keep up the good work!

E1320
E1320's picture
Offline
Last seen: 9 months 4 days ago
Joined: 03/30/2011 - 05:26
Posts: 3376
Location: New Hampshire

parkerdude wrote:

Wow,

When I first saw this thread, I was excited. I was thinking that I could get a 4-Mode driver w/memory, High-100%, Medium-50%, Low-15%, Moon-light-2%.

This conversation has gone so far over my head, that I'm back to searching the internet for an alternative. I don't think that this level of modding is EVER going to be within my reach 8-( .

Just to throw in my 2¢, if anyone gets to where they are custom programming some of these drivers, I'd like to buy 3-5 of them. Nothing fancy, just 4 modes, no strobes, w/memory.

Let us non-programmer types know. I'm still going to keep watching, but I'm not understanding a lot of what I'm reading.

Thanks, and keep up the good work!

I here you man I have been fighting with this for a couple months at this point I have given up. Maybe I will try again soon.

I am already visualizing the duct tape over your mouth.

Budgeteer
Budgeteer's picture
Offline
Last seen: 8 years 1 month ago
Joined: 08/24/2010 - 02:19
Posts: 3087
Location: Slovenia (EU)

Let's make a pool to make someone savvy make a few custom flash ready images with desired modes for us to use. That's it.

Get the soic clip the usb programmer load that load of apps and flash rightaway. About 5 versions per drivery type (the most common would probably fit 90% of requests). Unless i'm missing something it would certainly be doable.

4 modes with low low, 3 modes with XY spacing, 4 mode H-M-L or L-M-H with beacon. etc...

kragmutt wrote:

They're gonna send you a green redcat with a black LED.

Proto
Offline
Last seen: 9 years 1 month ago
Joined: 09/23/2011 - 20:47
Posts: 10
Location: Michigan

So, I finally am able to flash Tido's code to my drivers! The solution for me was to buy a USBtiny programmer kit from Adafruit, which requires assembly but which also powers the target board. Once I connected my attiny13-controlled SB 2.8A driver to this programmer, I had no problem. Next up is tackling the code so that I understand it well enough to set custom levels for a 4-level fixed mode no-memory driver. I think I am starting to understand, although I agree with the others that having the simple, programmable, and fixedmodes code in separate files in C would greatly increase my understanding. If I ever get the fixedmodes code sorted by itself I will post it (with Tido's permission). 

I also have a question about pinswitch: does this feature allow you to program to fixed groups of modes (two sets of Low-med-high for example), where the mode sets can be selected by the state of the pinswitch pin? If so I am interested in learning how I might include another switch, such as tightening/loosening the bezel or tailcap, to change the pinswitch state and access the alternate mode set. Does the attiny13 have the memory for something like this, or am I misunderstanding the pinswitch feature?

Dan
Offline
Last seen: 7 years 6 months ago
Joined: 07/19/2011 - 04:53
Posts: 32
Location: United Kingdom

This might be of interest - this link http://hlt.media.mit.edu/?p=1229 gives instructions on how to program an ATtiny using an Arduino

Tally-ho
Tally-ho's picture
Offline
Last seen: 2 months 6 days ago
Joined: 07/23/2011 - 04:15
Posts: 1394
Location: France

For more information about AVR and ATTiny there is also AVR Freaks...a noob's nightmare ^^ 

Proto
Offline
Last seen: 9 years 1 month ago
Joined: 09/23/2011 - 20:47
Posts: 10
Location: Michigan

I've successfully reprogrammed several drivers now, using a USBtinyISP programmer that supplies voltage to the target through USB power. I'm now working on modifying the code to so that I can have 4 fixed modes, similar to the changes sixty545 outlined for another member.

My problem is similar to others who have tried to build the code in AVRStudio: the error message "undefined reference to 'start_wdt' " comes up continually. I've solved the util.delay issue by defining the speed of the CPU, however I don't know where to start with this last error. I'm positive I have not changed anything in the code that would cause this, as I tried building the code without any modifications and this error still appears. It also occurs with an older version (0.3) of the code I downloaded. Does anyone know why 'start_wdt' is not defined in this code, and how I can fix this so it will build in AVRStudio5? 

-Jon

DrJones
DrJones's picture
Offline
Last seen: 5 years 6 months ago
Joined: 01/05/2011 - 13:30
Posts: 1044
Location: Frankfurt, Germany

I finally took the time and made my own driver program (from scratch). It mimics sixty454's UI: 11 modes currently, but once a mode is locked (>2s on), it will restart with the 1st mode as next mode. I have my most used modes at the beginning, no need to cycle through the rarely used modes all the time.

It's my 1st version and leaves room for improvement, as it doesn't have many features: Just various levels of brightness, strobe, beacon. No batt level measurement yet, no off-time-measuring ("pinswitch"), not programmable. And it doesn't have BLF-VLD's flexibility.

The other meaning of "leaves room for improvement" is that there is quite some free space: It uses 480 byte currently. The source code is shorter and maybe a bit easier to see through. Further it uses much less EEPROM writes and a wider wear leveling over 32 bytes. Some kind of ramping could be done.

Next thing I'll probably implement is a 5 minute timer; I have a need for that. My watch can do that of course, but a flashlight doing that is somewhat special Smile Won't be very precise though I guess, due to ATtiny's frequency variations, but I think it'll suffice.

DrJones
DrJones's picture
Offline
Last seen: 5 years 6 months ago
Joined: 01/05/2011 - 13:30
Posts: 1044
Location: Frankfurt, Germany

Implemented the 5 minutes timer; every minute it blinks out the number of remaining minutes, after 5min it strobes for 10 seconds, then it blinks weakly and slowly (in case you missed the strobe). I like it. Smile  Costs 126 bytes though.

DrJones
DrJones's picture
Offline
Last seen: 5 years 6 months ago
Joined: 01/05/2011 - 13:30
Posts: 1044
Location: Frankfurt, Germany

With XM-L and  Nanjg 105C at 1.2MHz and Tido's driver I don't get any output on the lowest level (PWM 1) (I guess the 1.7µs pulse is just too short for the AMCs). 

Does anyone of you do? With what settings? 

Edit: Hm, I just browsed the thread, Tido seems to use 4.8MHz, I guess with a prescaler of 8 with phase-correct PWM that should give a minimal pulse of 3.3µs and a PWM frequency of ~1.2kHz.

Edit: Ah, I got it now... low fuse 0x69, that's 0.6MHz CPU freq, PWM prescaler of 1, PWM frequency 1.2kHz. Thanks Tido! 

Microa
Offline
Last seen: 1 hour 56 min ago
Joined: 06/29/2011 - 21:20
Posts: 251

Dear Tido,

I am thinking to replace the R2 with a NTC resistor to change the battery monitor to a temperature monitor. I would like to ask for your help to change the RAMPDOWN from every five seconds to let say 30 seconds or 60 seconds. If LOWBAT_RAMPDOWN is not defined, whether LOWBAT_MAX_LVL is also needed to be undifined. Many thanks.

Microa
Offline
Last seen: 1 hour 56 min ago
Joined: 06/29/2011 - 21:20
Posts: 251

I would like to revise my question as changing the rampdown timing can not solve the problem.

The schematic of my driver

The testing set up

The problem is when the temperature rises to the threshold and the light level starts to rampdown. The light will go out every 5 seconds and will not stop blinking even the temperature drops below the threshold. You have to reset the light manually. I would like to ask for your help to solve the problem. Thanks a lot.

 

 

 

 

DrJones
DrJones's picture
Offline
Last seen: 5 years 6 months ago
Joined: 01/05/2011 - 13:30
Posts: 1044
Location: Frankfurt, Germany

After playing with some lights using my driver for a while I'm quite happy with it and published the code here.

Mikk0
Offline
Last seen: 1 year 10 months ago
Joined: 01/09/2011 - 06:20
Posts: 179
Location: Estland

Sorry for not reading through whole thread, but is it possible to use two switches for this ATtiny chip? One for turning it on/off and second one to switch modes (as fenix tk35)?


DrJones
DrJones's picture
Offline
Last seen: 5 years 6 months ago
Joined: 01/05/2011 - 13:30
Posts: 1044
Location: Frankfurt, Germany

Sure. There are 5 usable pins for input or output, PWM control uses one of them. You could wire the mode switch to any other pin and write a firmware to react to that.

Microa
Offline
Last seen: 1 hour 56 min ago
Joined: 06/29/2011 - 21:20
Posts: 251

The driver of my previous post which I modified the battery monitor to a temperature monitor is configured as a 3 level driver, High 0x08, Med 0x07 and Low 0x05. The battery monitor is configured as below;

// Config for battery monitoring
#define MONITOR_BAT       // enable battery monitoring
#define LOWBAT_TRIG 130     // trigger level for low battery, see README
//#define LOWBAT_RAMPDOWN     // decrease output gradually when battery fails
#define LOWBAT_MIN_LVL 0x07 // minimal PWM level to use in low battery situation
#define LOWBAT_MAX_LVL 0x08 // maximum PWM level to start ramping down from
#define ADC_MUX 0x01        // ADC channel to use, see README
#define ADC_DIDR ADC1D      // digital input to disable, see README
#define ADC_PRSCL 0x06      // ADC prescaler of 64

The outcome is that the light level is switched to Low instead of staying at Med when the voltage of the voltage divider is smaller or equal to the threshold. Would like to ask someone to help me to fix the issue. Thanks.

 

DrJones
DrJones's picture
Offline
Last seen: 5 years 6 months ago
Joined: 01/05/2011 - 13:30
Posts: 1044
Location: Frankfurt, Germany

LOWBAT_MIN_LVL and LOWBAT_MAX_LVL are PWM levels, not mode numbers.  If LOWBAT_MAX_LVL is 8, then low-batt mode starts at 8/255=3% which is quite low already.

I'd try:

#define LOWBAT_RAMPDOWN     // decrease output gradually when battery fails        <--- on
#define LOWBAT_MAX_LVL 0x80 // maximum PWM level to start ramping down from   <--- start lowbatt mode at half brightness
#define LOWBAT_MIN_LVL 0x02 // minimal PWM level to use in low battery situation  <--- gradually ramping down to very low

Microa
Offline
Last seen: 1 hour 56 min ago
Joined: 06/29/2011 - 21:20
Posts: 251

Thanks again,

I see what you meant. I have confused with the mode number and the PWM level.

E1320
E1320's picture
Offline
Last seen: 9 months 4 days ago
Joined: 03/30/2011 - 05:26
Posts: 3376
Location: New Hampshire

I am finally able to flash my drivers. Many thanks to Tido for supplying the tools and info to make this possible and thanks to Jonnyc for walking me through the problem I have been stuck on for a couple months.

I am already visualizing the duct tape over your mouth.

Major
Major's picture
Offline
Last seen: 6 years 4 months ago
Joined: 11/10/2011 - 13:59
Posts: 232
Location: Peak district, UK

Just signed up to say thank you for a excellent thread. I've successfully flashed tido's files, working on compiling so i can modify and build files which will allow me to create the perfect (for me!) driver. It's not easy as computers and me dont really get along but it's interesting and great to learn about something I've been curious about for a while. . BTW the last time i did any programming was in the 1980's with a computer that had 1k of memory how crazy was that!

krisirk
Offline
Last seen: 5 years 4 months ago
Joined: 11/07/2011 - 19:53
Posts: 10
Location: North Dakota

Major wrote:
BTW the last time i did any programming was in the 1980's with a computer that had 1k of memory how crazy was that!

 

Now your flashlight (with an Attiny13) has 1K of flash memory!  Though, I bet it's a little smaller than the computers you were using then.

 

Kris

parkerdude
Offline
Last seen: 4 months 3 weeks ago
Joined: 06/20/2011 - 23:50
Posts: 228
Location: St. Louis, Missouri

Hi Major,

Welcome to BLF!

Your comments bring back memories, this thread makes me think about trying my hand at programming again. My first attempts were in BASIC on a TRS-80 Model 1, back around that time too. Geez, seems like a while back.

Glad to see so much interest, and so many "mature" users in our ranks. 8-)

later,




Major wrote:


Just signed up to say thank you for a excellent thread. I've successfully flashed tido's files, working on compiling so i can modify and build files which will allow me to create the perfect (for me!) driver. It's not easy as computers and me dont really get along but it's interesting and great to learn about something I've been curious about for a while. . BTW the last time i did any programming was in the 1980's with a computer that had 1k of memory how crazy was that!

xecconlight
xecconlight's picture
Offline
Last seen: 9 years 11 months ago
Joined: 11/16/2011 - 10:59
Posts: 15
Location: shenzhen

Tido wrote:

brted wrote:

Also I know you will be flashing them, but it would be good to know how the modes are spaced by default and whether they can be changed by soldering to the stars.

 Thanks for checking.

I just did a quick test and the stars work just like they do on the AK-47. You get exactly the same mode groups.

Xeccon light manufacture, LED Flashlights; HID flashlights, Rechargeable Batteries; Flashlight Accessories

Pages