MiniDrv - simple firmware (source code)

DrJones - That is wonderful - Seriously, great to have you offer all this up to us.

Of course, it's still 17-31/32 more lines than I can understand.

@moderator007 in theory PMW 4 is 44mAh, so something less in practice.
I understand what you say about your flickering, I have the same thing on a light I made all the soldering myself (and I’m a bad solder…) and with a certain type of battery (old battery laptop pull manufactured in 2008) and only on high (I mean PMW 255). But as it appears for you at PMW 4, it’s not a drain issue.

@DrJones, maybe you should add you two new minimal firmware to your personnal page

I can't figure out what I'm doing wrong. I have tried this program on several different Nanjg 105c drivers. None work with it. I flashed many drivers with both my own and 3rd party firmware. Solution builds error free and flashes error free. PWM modes I'm using are 5,15,90,255. Here is the code I flashed (copied directly from Atmel Studio):

//MiniDrv -- minimalistic driver firmware (no blinkies) -- DrJones 2014
#define F_CPU 4800000 //use fuses low:0x75 high:0xff
#include <avr/io.h>
#include <util/delay.h>
//change modes here; just change/add/delete values
uint8_t modes[]={5,15,90,255}; //PWM values, 5..255
int main() {
DDRB=2; //define PB1 as output
TCCR0A=0b00100001; TCCR0B=0b00000001; //PWM setup, 9kHz
EEARL=4;EECR=1; uint8_t mode=EEDR; //read from EEPROM
if (mode>=sizeof(modes)) mode=0; //check if invalid
OCR0B=modes[mode]; //set PWM level
EEDR=mode+1; //next mode
if(EEDR>=sizeof(modes)) EEDR=0;
EECR=4;EECR=4+2; while(EECR&2); //write to EEPROM
_delay_ms(1000); //delay for memory (or nomemory) to kick in
EEDR=mode; //memory: use this mode again \ use one of these lines
//EEDR=0; //no memory: restart from 0 / use one of these lines
EECR=4;EECR=4+2; while(EECR&2); //write to EEPROM
while(1) {} //endless loop
}

Try to errase mcu first and then “burn” new code…

Thanks for the tip Sirius9. I do that every time. Standard procedure for me starting about 1/2 year ago.

And you are using this line to flash the drvr? because I don’t see anything wrong with your code…
avrdude -p t13 -c usbasp -u -Uflash:w:minidrv.hex:a -Ulfuse:w:0x75:m -Uhfuse:w:0xFF:m

Try this, if you want to rule out the build part of the equation (I just pasted your text into AS5) http://75.65.123.78/fw/minidrv.hex

Sirius9, I built a solution in AtmelStudio using the text from the OP. Here is the flash command I use:

avrdude -p t13 -c usbasp -e -u -Uflash:w:minidrv.hex:a -Ueeprom:w:minidrv.eep:a -Ulfuse:w:0x75:m -Uhfuse:w:0xff:m

Hmm, maybe that is my problem.

Comfy, thanks. I will try that tonight. Much appreciated.

Thanks guys.

you don’t need eeprom initialization (I would say), only hex. After erasing eeprom is blank and you don’t have special code that would initialize eeprom so .eep file does not contain useful data…
P.S. I always do a erasing as a separate (first) step.

Dear Dr. Jones,
The Attiny10 does not have EEPROM. Is it possible to read the Modes memory from the 1K flash?
Whether I need to set the F_CPU to 4MHz or 8MHz and make use of the prescaler to set the PWM frequency?
Your valuable comments are highly appreciated.

Microa: It's possible to read from the flash memory, but not to write to it, so the light cannot remember what state it is in whenever the button is pressed.

BTW, how do you flash these?

1K flash is the EEPROM Microa…it is a MCU…more or less a 20mhz computer with a 1K “programmable harddrive”

The prescaler is the clock frequency divider that controls the bus speed of the programming

There's a difference between normal EEPROM and Flash-EEPROM, and those MCUs clearly differentiate between them in how they are accessed. The ATtiny10 doesn't have that EEPROM and can't write to the Flash-EEPROM (other than by external programming).

Many thanks for your reply. It seems that it is not possible to modify MiniDrv for tinny10. I have read a lot of comments on the web that the tiny10 is lack of support in C programming. Most of the programs are written in ASM. Recently, the situation is getting better. May be I will try to work for MiniMo which seems to be not required the EEPROM.

Dear Dr. Jones,
I have built the MiniDrv with memory and without memory by AVR Studio 4.18 and AVR Studio 5.1. I found that all of these hex file can fire up the LED but have problem to change mode. Finally, I flashed the MCU back to luxdrv 0.22. Is there some tweak of the source code will be required?

I’m just starting with programming these drivers, I’ve got most of it figured out (I’m waiting on equipment still but started to play with it, I’m not new to programming, just new to this process, the chips I usually work with are 512k [for OBD-1 GM PCM’s] so I’ve not had to be concerned about space before so all this making stuff fit is whats new) but I’m a little confused about the mode-memory part.

Anyway about the line above, is 1sec the minimum time aloud or can it be set lower?

Thanks for all this, its the first one I’ve been able to edit and have the build actually succeed so this is great for us beginners, again thanks!

I have tried (2000), (3000) and (4000). At (4000), the situation is getting better. Can change mode precisely but it still stop at the lowest mode refuse to go up.
I set the PWM level at {5,85,170,255}

That is strange, I don't know what's wrong. Some ideas :

* Check the fuse bits.

* Try EEARL=12; instead of 4, maybe the EEPROM cell is bad.

* Try a different driver/MCU, maybe there are hardware issues.

* Restart from a fresh copy of MiniDrv, maybe you accidentally changed something.

Shall I also have to change EECR=4;EECR=4+2; to EECR=12;EECR=12+2 ?

Checked fuse OK. 0x75, 0xFF.
Tried EEARL=12; did not change the EECR. The symptoms persist.
The testing driver that I am using don’t have problem with Luxdrv 0.22 and BLF-VLD 0.4.