Hmmm, actually I probaby would pay $60 for a flashlight with this kind of mod. Would be an amazing flashlight with dedicated XP-E's in red, blue, green, and UV, then have 3 XM-L2 U2 1D, that would be amazing! Ya, for $60 I would definitely get it!
Yes, the 12F1822 is the perfect choice for writing in C on a tiny 8-pin part. I haven’t used them much in my mods simply because my work throws away lower-level parts (12F617) by the boatload, so I use those since I hate to see them go to landfill. If you pursue a project with the 12F1822 we would be able to port pieces of my MELD code right over to it (if that’s the kind of functionality you’re looking for)
Thank you again tterev3. I purchased the flasher you recommended above. So I will be flashing and that MCU you discussed is very affordable. I think I will first attempt to adapt my favorite Attiny13a FW to the 12F1822 first. I have to study to the 12F1822 datasheet more so that I can figure out what adjustments I would need to make to the code.
MELD looks like an incredible program. It just has so much more functionality that I feel I should tackle at this time. I really like your concept of having all those colors and UV in one light. I have separate, green, red and UV lights. It would be really cool to have all that available in one light. It's just too much for me at the moment. I need baby steps.
Thanks again for your very gracious sharing of your knowledge and efforts.
Here's an example program I put together for the 1822. It's a very simple flashlight with 3 brightnesses and a randomized strobe that changes modes on power cycle. This should help you get started with the 1822:
//v0 4/21/2014 by Everett
//initial version
//simple flashlight controller. mode change on power cycle
if(TMR0IF){ //fires at 1kHz
TMR0IF=0;
if(strobe_timer){strobe_timer--;} //count down milliseconds
}
}
void main(void)
{
configure(); //set up hardware peripherals
delayms(15); //short delay to avoid power glitches incrementing mode
if(key==12345){ //RAM retention trick to detect quick power cycles
mode++; //go to next mode
if(mode>max_mode){mode=0;}
}
else{ //long power loss. default to first mode
mode=default_mode;
key=12345;
}
switch(mode){ //initialize current mode
default:
case max:
CCPR1L=255;
break;
case med:
CCPR1L=25;
break;
case low:
CCPR1L=1;
break;
case strobe:
strobe_timer=0;
on_off=0;
CCPR1L=0;
break;
}
GIE=1; //turn on interrupts
while(1){
if(mode==strobe){ //no other modes need active tasks while running
if(strobe_timer==0){ //timer ran out
on_off=~on_off; //flip it
if(on_off){
CCPR1L=255;
strobe_timer=on_time; //set on time
}
else{
CCPR1L=0;
strobe_position++;
strobe_timer=stun_rate_lookup(strobe_position); //set off time
} //set output
}
}
}
Thank you. Very good idea to start with code that works since someone new to PIC programing/flashing (like me) will probably be dealing with other first time issues. One less potential complication. Looks like the code is for a normal clickie type switch (on/off, half click to interrupt power). Is that correct?
Received my programmer today. Excited to start going down this path, but I will have to be patient as I have quite a few demands for my time right now, plus the Scratch Build Contest.
Thanks for the write up. In my brief experimentation with PIC, I found MPLAB-8 much clearer than MPLAB-X, and that was coming into it with ZERO experience. I might have to start using my PICKit 3 again...
Great info …on your third day. I’m going to go in to the corner and shudder remembering the one time I had to not just have a basic understanding of assembler on the mainframe but actually got stuck having to get in the code.
I'm doing a bit of reading and I'm really interested in using that little 6-pin PIC10F322. I've been looking at making a really small 3 mode flashlight driver for years, but don't want to use QFN parts. The PIC10F322 is actually small enough for my project! Obviously it can do PWM out, and I'm assuming it can accept a voltage divider input for battery monitoring (on it's single input-only pin). However, can I by any chance use the internal voltage reference to estimate the supply voltage (less parts required)?
Another question. I note in the OP that ttreve3 lists assembly beside the PIC10F322. Does this mean it will only work with assembly code, or does it simply mean there probably won't be enough room to use C on it? I was going to take the code supplied in post #18, remove the strobe and see if I could get that working on the PIC10F322.
This may give you an idea about who you're dealing with here, but I don't know what that means in regards to my application lol. So is this a waste of time? It's ttreve3's code with the strobe removed (I think...I would be grateful if someone would check it over). Will I be able to compile that in MPLAB 8 and flash it using my PICkit 3?
Edit: note I have not taken the time as yet to check things like registers line up etc. And seen as there is no eeprom the last section is likely a waste of time.
Correct on the _eeprom_data code, it is irrelevant, so just get rid of it. I don’t play with C, so can’t say what compiler problems you may encounter, if any, with MPLAB 8. The htc.h include file will give an indication on what compiler is being used, and compatibility.