I'm willing to pay $200 (not commercial)

37 posts / 0 new
Last post

Pages

technosteve
Offline
Last seen: 4 days 16 hours ago
Joined: 09/25/2019 - 14:16
Posts: 25
Location: louisiana
I'm willing to pay $200 (not commercial)

I’ve been trying to get my flashlight firmware to work with my clicky flashlight, on a driver I designed myself. I’ve probably spend about 15 hours troubleshooting this, and my time is more valuable than that so I’m going to put out a bounty for someone to assist me with this.

I’m willing to share my schematic, and firmware, and if you can point me in the right direction to get this working, I will return the favor and paypal or venmo you $200. If it takes you 1 minute to get me up and running, I’ll still pay you. It’s legit, nothing fishy, I just want my flashlight to work the way I want it to.

No I’m not going to be selling this, I just want to make myself 10 flashlights that I can leave all around my house that will be super reliable, with hardware I can trust. No I don’t want to use someone else’s driver, but I’ll consider using someone else’s firmware.

Let me know if you are interested and I’ll share the details.

treellama
Offline
Last seen: 4 hours 11 min ago
Joined: 12/08/2018 - 21:20
Posts: 92
Location: Pittsburgh

I’m willing to have a look at it just out of curiosity. No money necessary.

technosteve
Offline
Last seen: 4 days 16 hours ago
Joined: 09/25/2019 - 14:16
Posts: 25
Location: louisiana

https://ibb.co/fSjRqWy

There’s a link to the schematic. I’ve heard that Bistro will work with this type of driver. It’s being powered by 2× 18650 cells in series, so 8.4V input.

The driver itself works fine, just need help with getting the MCU working with the modes. ATtiny25 or ATtiny85, or any other compatible ATtiny device.

Quadrupel
Quadrupel's picture
Offline
Last seen: 1 hour 44 min ago
Joined: 12/03/2017 - 10:40
Posts: 137
Location: LT

All i see is a 1.2v?? voltage regulator and outdated Attiny12.
Check this out, maybe youll find what you want:
http://budgetlightforum.com/node/67843

treellama
Offline
Last seen: 4 hours 11 min ago
Joined: 12/08/2018 - 21:20
Posts: 92
Location: Pittsburgh

So, when you say the driver itself works fine, you can drive PB0 low and get one level of output on the LEDs, and drive PB1 low and get another level of output? (This is a dual channel, right?)

technosteve
Offline
Last seen: 4 days 16 hours ago
Joined: 09/25/2019 - 14:16
Posts: 25
Location: louisiana

Input is 8.4V, the regulator I’m using is 3.3V. The MCU, I have both Attiny25 and Attiny85 on hand, pinout is the same.

I only need one PWM channel, so I can use either PB0 or PB1.

Mike C
Mike C's picture
Offline
Last seen: 1 hour 18 min ago
Joined: 01/22/2014 - 08:03
Posts: 2401
Location: Sweden

The schematic you posted in post #3 does not give any indication on how you actually plan on switching modes. Are you planning on using a clicky/off switch or a momentary/E-switch? If clicky/offswitch, what method? I don’t see any off-time capacitor.

treellama
Offline
Last seen: 4 hours 11 min ago
Joined: 12/08/2018 - 21:20
Posts: 92
Location: Pittsburgh

It also doesn’t show where the PWM outputs go. A FET? Banks of linear drivers?

technosteve
Offline
Last seen: 4 days 16 hours ago
Joined: 09/25/2019 - 14:16
Posts: 25
Location: louisiana

It goes to a buck driver. The driver works and is a separate circuit so I didn’t include it in the schematics. Assume the PWM output goes to a functioning driver.

technosteve
Offline
Last seen: 4 days 16 hours ago
Joined: 09/25/2019 - 14:16
Posts: 25
Location: louisiana

The switch is a clicky/on/off type where a half-press simply opens the circuit. True no off time capacitor exists because I’m unsure how to integrate one and make the calculations for the firmware. This is why I’m asking for help Wink

treellama
Offline
Last seen: 4 hours 11 min ago
Joined: 12/08/2018 - 21:20
Posts: 92
Location: Pittsburgh

So what do you have for firmware right now? Start with something simple that turns the output pin on and off every 200 ms, then add PWM and get it to drive the output at quarter / half duty cycle alternating. Can you get that far?

Mike C
Mike C's picture
Offline
Last seen: 1 hour 18 min ago
Joined: 01/22/2014 - 08:03
Posts: 2401
Location: Sweden

technosteve wrote:
The switch is a clicky/on/off type where a half-press simply opens the circuit. True no off time capacitor exists because I’m unsure how to integrate one and make the calculations for the firmware. This is why I’m asking for help Wink

Well, you wrote you where troubleshooting an already designed driver, trying to get the firmware to work. As you designed the driver, how did you design the driver to work in terms of mode changing?
technosteve
Offline
Last seen: 4 days 16 hours ago
Joined: 09/25/2019 - 14:16
Posts: 25
Location: louisiana

#treellama
Yes, I can get an appropriate PWM setting. Just can’t figure out how to get the modes to change.

Quote:
#include

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

//**here you set brightness of modes
int mode1 = 255;
int mode2 = 8;

const int buttonPin = 1; //setting button pin
const int ledPin = 0; // setting LED pin
int buttonPushCounter1 = 1; // counts the button pushes
int buttonState1 = 1; // tracks the button state
int lastButtonState1 = 0; // last state of the button
int buttonState = 0; // Button status
int lastButtonState = LOW; //Button set to LOW

long lastDebounceTime = 0; // Debounce status
long debounceDelay = 50; // Debounce timer

void setup() { pinMode(ledPin, OUTPUT); // Sets LED as output pinMode(buttonPin, INPUT); // Sets button as input

sbi(GIMSK,PCIE); // Turn on Pin Change interrupt sbi(PCMSK,PCINT1); // Which pins are affected by the interrupt }

//mode one: LED is set to 100% brightness by default
int modeone() { analogWrite(ledPin,mode1);
}

//mode two: LED is set to your preference of brightness (my default is about 30% = 76)
int modetwo() { analogWrite(ledPin,mode2);
}

//mode three: strobe light, I set it to be the most disorienting in darkness but feel free to change on and off times (in [ms])
int modethree() { digitalWrite(ledPin,HIGH); delay(15); digitalWrite(ledPin,LOW); delay(100);
}

//Sleep mode
int modefour() { analogWrite(ledPin,8); delay(20); analogWrite(ledPin,0); delay(20); analogWrite(ledPin,8); delay(20); analogWrite(ledPin,0); delay(20); analogWrite(ledPin,8); delay(20); analogWrite(ledPin,0); buttonPushCounter1 = 1; system_sleep();

}

void loop() { // All the debound button press stuff int reading = digitalRead(buttonPin); buttonState1 = digitalRead(buttonPin);

if (reading != lastButtonState) { lastDebounceTime = millis(); } if ((millis() – lastDebounceTime) > debounceDelay) { if (reading != buttonState) { buttonState = reading; if (buttonState1 != lastButtonState1) { if (buttonState1 == HIGH) { buttonPushCounter1++; if (buttonPushCounter1 == 5) { buttonPushCounter1 = 1;} } else { } } lastButtonState1 = buttonState1; } } lastButtonState = reading;

//switching modes:

if (buttonPushCounter1 1) { modeone(); } if (buttonPushCounter1 2) { modetwo(); } if (buttonPushCounter1 3) { modethree(); } if (buttonPushCounter1 4) { modefour(); }

}
//loop end

void system_sleep() { cbi(ADCSRA,ADEN); // Switch Analog to Digital converter OFF set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Set sleep mode sleep_mode(); // System sleeps here sbi(ADCSRA,ADEN); // Switch Analog to Digital converter ON
}

ISR {
}

technosteve
Offline
Last seen: 4 days 16 hours ago
Joined: 09/25/2019 - 14:16
Posts: 25
Location: louisiana

#Mike C
The driver is the part that regulates power to the LED. The microcontroller and it’s firmware sends the signal to control the driver. The driver is designed. I need assistance with the microcontroller and it’s firmware.

If I put in a signal to the driver, the driver does what it’s told. I’m not sure how to get the clicky button to tell the microcontroller how to change modes.

I’ve read that I need to use capacitors to allow the micro to stay on briefly between clicks/half presses, but haven’t found technical information on how to implement this. Perhaps if someone had both a schematic and firmware of a clicky (on/off switch) flashlight I would figure it out from there and that’s all it would take so I’d send that person the promised money.

tterev3
Offline
Last seen: 3 days 19 hours ago
Joined: 03/28/2014 - 11:22
Posts: 268
Location: NC, USA

technosteve wrote:
I've read that I need to use capacitors to allow the micro to stay on briefly between clicks/half presses, but haven't found technical information on how to implement this.
Usually if the microcontroller has a normal decoupling capacitor on its supply you can use the RAM retention trick like this: Declare two variables that the compiler won't automatically initialize to zero upon bootup:

unsigned int key attribute ((section (“.noinit”)));

unsigned char mode attribute ((section (“.noinit”))); 

 

And then at the beginning of your loop, so that it executes once each time the processor boots up:

if(key==12345){ //check if RAM is still valid from last time

   mode++; //yes, advance to next mode

   if(mode>max_mode) {mode=0;}

}

else{ //long power loss. default to first mode

   mode=default_mode;

   key=12345; //initialize key for next power loss

} 

technosteve
Offline
Last seen: 4 days 16 hours ago
Joined: 09/25/2019 - 14:16
Posts: 25
Location: louisiana

Thanks for your helpful response tterev3

I am currently using a 47uF decoupling capacitor, is that adequate our should I double, quadruple, etc the value?

For the first two lines, do I insert that before void setup? Or within void setup? I’ve tried several places and can’t get it to compile. (Or am I supposed to fill in a variable?)

Thanks!

tterev3
Offline
Last seen: 3 days 19 hours ago
Joined: 03/28/2014 - 11:22
Posts: 268
Location: NC, USA

You will have to test the capacitance in your system and see, there are a lot of variables with the other electronics loading down the rail. The first two are variable declarations, they should be put outside of any functions to make them global (assuming you have both a setup() and main() that will need to access them). Sorry, I think the forum formatting ruined the syntax. It should be

unsigned int key __attribute__ ((section (".noinit")));

unsigned char mode __attribute__ ((section (".noinit")));

technosteve
Offline
Last seen: 4 days 16 hours ago
Joined: 09/25/2019 - 14:16
Posts: 25
Location: louisiana

Thanks for that, that updated syntax compiled correctly.

Is there a target capacitance that this requires? Or a certain mcu ontime after the button opens the circuit?

Thanks!

tterev3
Offline
Last seen: 3 days 19 hours ago
Joined: 03/28/2014 - 11:22
Posts: 268
Location: NC, USA
technosteve wrote:
Is there a target capacitance that this requires? Or a certain mcu ontime after the button opens the circuit?

The trick is that there is a lower voltage limit below which the processor won’t operate, and a lower voltage limit below which RAM won’t be maintained, but they are not the same voltage. You can look it up for your specific part, but generally somewhere around 2.5V it will stop running, but it will maintain RAM values until about 1.5V. So when you open up the switch and it loses power, the voltage will start to fall. It will fall very fast at first while the LEDs etc. can still operate and draw current, but once you cross the threshold where the LEDs and processor shut off, voltage starts to fall much more slowly since nothing is drawing significant current. The time it takes for voltage to fall from this first threshold to the second is how long you have to reconnect power with the switch (or the length of your tap on a reverse-clicky). In my designs I like to target about 500ms for this time period. If you have stuff like resistor dividers, they will drain the power faster and you may need to increase capacitance to extend the time. On some designs there is almost no power drain below 2.5V and you would need to add resistance to intentionally drain the capacitor (and/or reduce the capacitance) so that the part can fully reset in a reasonable amount of time.

technosteve
Offline
Last seen: 4 days 16 hours ago
Joined: 09/25/2019 - 14:16
Posts: 25
Location: louisiana

Where in my code specifies the length of the tap on the clicky switch? Feel free to PM me, because if we get this working soon I’ll square up with the house.

tterev3
Offline
Last seen: 3 days 19 hours ago
Joined: 03/28/2014 - 11:22
Posts: 268
Location: NC, USA

technosteve wrote:
Where in my code specifies the length of the tap on the clicky switch?

Nothing in code specifies it, you just may need to adjust your hardware to make it an amount of time that works for you. Essentially you need to set how long the variable key “lives” for before it gets scrambled. If the microcontroller wakes up and sees that key still has the specific value it was assigned last time, then it knows the power loss was very short (because it was a tap on the switch) and therefore the value of mode is still valid (still holds what was used last time) and that the user would like to advance to the next mode. No timing needs to be specified for any of it in the code, it just needs to figure out every time it boots up if it’s a “warm boot” from a quick tap, or a “cold boot” from actually being off and unused for a while.
tterev3
Offline
Last seen: 3 days 19 hours ago
Joined: 03/28/2014 - 11:22
Posts: 268
Location: NC, USA

Here is a complete working example that uses this method. It’s for a different architecture but I tried to write it to be very human-readable so you can get a better understanding of the process:
http://budgetlightforum.com/node/30556?page=1

technosteve
Offline
Last seen: 4 days 16 hours ago
Joined: 09/25/2019 - 14:16
Posts: 25
Location: louisiana

Would it be too much to ask for you to put this together in my code so I can have something to test my hardware with? This is a bit over my head. That said it would take me days and days of testing this firmware to get something that probably won’t work well, whereas you can likely do it in minutes.

tterev3
Offline
Last seen: 3 days 19 hours ago
Joined: 03/28/2014 - 11:22
Posts: 268
Location: NC, USA

can you post your code that you have now with the PWM output working?

technosteve
Offline
Last seen: 4 days 16 hours ago
Joined: 09/25/2019 - 14:16
Posts: 25
Location: louisiana

Heres a link, it wouldn’t post correctly in the forum https://www.dropbox.com/s/kavb64mtqlh7jgq/flashlight%20attiny85.txt?dl=0

Mike C
Mike C's picture
Offline
Last seen: 1 hour 18 min ago
Joined: 01/22/2014 - 08:03
Posts: 2401
Location: Sweden

technosteve wrote:
The driver is the part that regulates power to the LED. The microcontroller and it’s firmware sends the signal to control the driver.

Ok, now I got ya. Here we call “driver” the entire schematics with microcontroller and everything, not just what you call led “driver”.

Without a specific cap for offtime, the method tterev3 mentions is your best bet. Timing can vary a little, but RAM in older generation ATtiny’s (13a/25/85) usually decay within a second or so. The newer series 1 don’t decay for ages even with 1uF input cap. My “no_init” RAM lasts over 10 minutes, I havn’t bothered testing further.

Lexel
Lexel's picture
Offline
Last seen: 8 hours 47 min ago
Joined: 11/01/2016 - 08:00
Posts: 5582
Location: Germany
tterev3 wrote:

technosteve wrote:
I’ve read that I need to use capacitors to allow the micro to stay on briefly between clicks/half presses, but haven’t found technical information on how to implement this.
Usually if the microcontroller has a normal decoupling capacitor on its supply you can use the RAM retention trick like this: Declare two variables that the compiler won’t automatically initialize to zero upon bootup:

unsigned int key attribute ((section (“.noinit”)));


unsigned char mode attribute ((section (“.noinit”))); 


 


And then at the beginning of your loop, so that it executes once each time the processor boots up:


if(key==12345){ //check if RAM is still valid from last time


   mode++; //yes, advance to next mode


   if(mode>max_mode) {mode=0;}


}


else{ //long power loss. default to first mode


   mode=default_mode;


   key=12345; //initialize key for next power loss


} 

you can also use parts of Bistro HD OTSM code without an OTC
It has the MCU powered during off time in a low drain state from a 47uF capacitor

I can help you with hardware all the way from design, to prototyping and final production in small quantities
I am pretty familiar to use existing BLF firmware but I can’t program much mainly config the settings code

.

if you once tried Bistro HD OTSM you may consider rather modify it that writing something on your own

technosteve
Offline
Last seen: 4 days 16 hours ago
Joined: 09/25/2019 - 14:16
Posts: 25
Location: louisiana

Can you provide an example of a more modern processor Mike C?

tterev3
Offline
Last seen: 3 days 19 hours ago
Joined: 03/28/2014 - 11:22
Posts: 268
Location: NC, USA

Try this. Not sure where your source came from - appears to have some Arduino-based I/O functions? Are you doing this in Atmel Studio with the compiler or in Arduino?

 

#include <avr/sleep.h>

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

//**here you set brightness of modes
int mode1 = 255;
int mode2 = 8;


const int ledPin = 0; // setting LED pin

unsigned int key __attribute__ ((section (".noinit")));

unsigned int mode __attribute__ ((section (".noinit")));

void setup() {
if(key==12345){ //check if RAM is still valid from last time
    mode++; //yes, advance to next mode
    if(mode>2) {mode=0;}
}
else{ //long power loss. default to first mode
    mode=0; //default mode after long power off
    key=12345; //initialize key for next power loss
}

pinMode(ledPin, OUTPUT); // Sets LED as output

sbi(GIMSK,PCIE); // Turn on Pin Change interrupt
sbi(PCMSK,PCINT1); // Which pins are affected by the interrupt
}

//mode one: LED is set to 100% brightness by default
int modeone() {
    analogWrite(ledPin,mode1);
}

//mode two: LED is set to your preference of brightness (my default is about 30% = 76)
int modetwo() {
    analogWrite(ledPin,mode2);
}

//mode three: strobe light, I set it to be the most disorienting in darkness but feel free to change on and off times (in [ms])
int modethree() {
    digitalWrite(ledPin,HIGH);
    delay(15);
    digitalWrite(ledPin,LOW);
    delay(100);
}


void loop() {

    switch(mode){
        default:
        case 0:
            modeone();
            break;
        case 1:
            modetwo();
            break;
        case 2:
            modethree();
            break;
    }
}
//loop end


void system_sleep() {
    cbi(ADCSRA,ADEN); // Switch Analog to Digital converter OFF
    set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Set sleep mode
    sleep_mode(); // System sleeps here
    sbi(ADCSRA,ADEN); // Switch Analog to Digital converter ON
}

ISR(PCINT0_vect) {
}

 

mgracia85
mgracia85's picture
Offline
Last seen: 1 hour 51 min ago
Joined: 12/01/2017 - 18:35
Posts: 241
Location: East Texas

Newbie here

What coding language is this?

I love my wife’s toy poodle

technosteve
Offline
Last seen: 4 days 16 hours ago
Joined: 09/25/2019 - 14:16
Posts: 25
Location: louisiana

Yes I am using Arduino IDE.

Pages