I haven’t been able to get it to fail again. The only time I saw it, it was on a light which had been booted and used for weeks, and I haven’t narrowed down a faster way to trigger the issue.
I’ve had the most recent version running all day in various modes to see if I can find the right conditions, but it refuses to fail. So… on the one hand, this is encouraging. But OTOH, I’d really like to fix it.
As for ideas, there are several… and some aren’t even related to this. But one in particular which I think might help is to change how it handles things when the current button sequence is longer than the maximum. Specifically, make the most-recent event replace whatever was at the end before, instead of just dropping events beyond the limit. This should slightly reduce code size, and it also means the sequence will end with a button-release event, assuming the user lets go of the button. And then the usual release timeout should always apply, and it should empty the queue sooner instead of waiting until standby is activated.
Also, I might drop the maximum length by one and make sure the end is always zero. This may help avoid falling off the end if there’s code anywhere which expects a zero instead of stopping at the maximum length.
And a bunch of other things I want to do to the event code, both to improve its function and reduce its size. There’s an awful lot of data in RAM which doesn’t need to be there, and I should really try to reduce the size of the tables involved somehow.
Hi BLF friends.
I had resolved my difficulty with crescendo compile.
I had changed my notebook and reinstalled AVRStudio 7, but during the installation I opted to not update the software.
I unistalled AVRStudio, and reinstalled it with the option to update the program during the installation procedure.
That solved the problem with the crescendo compile.
Thanks for the help TK, g_damian and zeroflow.
Now crescendo can be compiled complete, with all its functions.
Thanks TK! I have no idea how that extra 0 ended up in the code, I have not messed with this code in over a year and did not remember messing with that mode group now.
That was indeed the problem and it is working good now.
I tried to create a new anduril hwdef file for the mt09R but it will not compile. To start out with I just copied the D4 files and added the external voltage divider, it compiles fine if I leave it in the D4 hwdef file, so the code should be fine.
After looking at the errors I figured I also needed a matching cfg file so I copied the D4 cfg file as well but that did not help.
I then started digging deeper and found the abduril.c file had a bunch of FSM_*_ CFG driver defines, so I added one for the MT09R there, still didn't help.
I then found the hwdef defines in the TK-Attiny.h and added matching entries here as well.
Still getting the same error. It appears it is not seeing these new files.
Normally I would just change the D4 define files and use that but I know that annoys TK so trying to create a new define. ;)
This is the code as it sits now. I am sure it is a simple missing define or line someplace but I have dug as deep as I know how to figure it out. It just seems to not see the define files for some reason, I even copied the file names exactly to make sure the spelling was ok.
===== TA-MT09R-12v =====
avr-gcc -DFSM_TA-MT09R-12v_DRIVER -Wall -g -Os -mmcu=attiny85 -c -std=gnu99 -DATTINY=85 -I.. -I../.. -I../../.. -fshort-enums -o anduril.o -c anduril.c
<command-line>:0:7: warning: ISO C99 requires whitespace after the macro name
In file included from ../spaghetti-monster.h:25:0,
from anduril.c:193:
../../tk-attiny.h:112:2: error: #error Hey, you need to define an I/O pin layout.
#error Hey, you need to define an I/O pin layout.
^
In file included from ../spaghetti-monster.h:69:0,
from anduril.c:193:
../fsm-events.c: In function ‘nice_delay_ms’:
../fsm-events.c:136:21: error: ‘QUARTERSPEED_LEVEL’ undeclared (first use in this function)
if (level < QUARTERSPEED_LEVEL) {
^
../fsm-events.c:136:21: note: each undeclared identifier is reported only once for each function it appears in
In file included from ../spaghetti-monster.h:70:0,
from anduril.c:193:
../fsm-adc.c: In function ‘ADC_on’:
../fsm-adc.c:43:42: error: ‘ADC_PRSCL’ undeclared (first use in this function)
ADCSRA = (1 << ADEN) | (1 << ADSC) | ADC_PRSCL;
^
In file included from ../spaghetti-monster.h:72:0,
from anduril.c:193:
../fsm-pcint.c: In function ‘button_is_pressed’:
../fsm-pcint.c:33:51: error: ‘SWITCH_PIN’ undeclared (first use in this function)
readings = (readings << 1) | ((PINB & (1<<SWITCH_PIN)) == 0);
^
In file included from ../spaghetti-monster.h:74:0,
from anduril.c:193:
../fsm-ramping.c: In function ‘gradual_tick’:
../fsm-ramping.c:119:10: error: ‘PWM1_LVL’ undeclared (first use in this function)
if ((PWM1_LVL == pgm_read_byte(pwm1_levels + gt))
^
In file included from ../fsm-events.h:23:0,
from ../spaghetti-monster.h:30,
from anduril.c:193:
../fsm-ramping.c:119:36: error: ‘pwm1_levels’ undeclared (first use in this function)
if ((PWM1_LVL == pgm_read_byte(pwm1_levels + gt))
^
In file included from ../spaghetti-monster.h:74:0,
from anduril.c:193:
../fsm-ramping.c:91:13: warning: unused variable ‘target’ [-Wunused-variable]
uint8_t target;
^
In file included from ../spaghetti-monster.h:79:0,
from anduril.c:193:
../fsm-misc.c: In function ‘auto_clock_speed’:
../fsm-misc.c:26:17: error: ‘QUARTERSPEED_LEVEL’ undeclared (first use in this function)
if (level < QUARTERSPEED_LEVEL) {
^
../fsm-misc.c:32:22: error: ‘HALFSPEED_LEVEL’ undeclared (first use in this function)
else if (level < HALFSPEED_LEVEL) {
^
In file included from ../spaghetti-monster.h:36:0,
from anduril.c:193:
../fsm-misc.c: In function ‘blink_digit’:
../fsm-ramping.h:117:26: error: ‘pwm1_levels’ undeclared (first use in this function)
#define RAMP_SIZE sizeof(pwm1_levels)
^
../fsm-ramping.h:118:19: note: in expansion of macro ‘RAMP_SIZE’
#define MAX_LEVEL RAMP_SIZE
^
../fsm-misc.h:29:27: note: in expansion of macro ‘MAX_LEVEL’
#define BLINK_BRIGHTNESS (MAX_LEVEL/6)
^
../fsm-misc.c:51:19: note: in expansion of macro ‘BLINK_BRIGHTNESS’
set_level(BLINK_BRIGHTNESS);
^
In file included from ../spaghetti-monster.h:80:0,
from anduril.c:193:
../fsm-main.c: In function ‘main’:
../fsm-main.c:76:19: error: ‘SWITCH_PIN’ undeclared (first use in this function)
PORTB = (1 << SWITCH_PIN); // e-switch is the only input
^
anduril.c: At top level:
anduril.c:273:27: error: ‘MAX_1x7135’ undeclared here (not in a function)
uint8_t memorized_level = MAX_1x7135;
^
In file included from ../spaghetti-monster.h:36:0,
from anduril.c:193:
../fsm-ramping.h:117:26: error: ‘pwm1_levels’ undeclared here (not in a function)
#define RAMP_SIZE sizeof(pwm1_levels)
^
../fsm-ramping.h:118:19: note: in expansion of macro ‘RAMP_SIZE’
#define MAX_LEVEL RAMP_SIZE
^
anduril.c:259:30: note: in expansion of macro ‘MAX_LEVEL’
#define RAMP_SMOOTH_CEIL MAX_LEVEL - 30
^
anduril.c:277:37: note: in expansion of macro ‘RAMP_SMOOTH_CEIL’
volatile uint8_t ramp_smooth_ceil = RAMP_SMOOTH_CEIL;
^
mv: cannot stat 'anduril.hex': No such file or directory
Im still pretty new to this, but I found that the defines in the firmware point to the cfg files in the Anduril directory.
It pulls from the cfg- file ex FSM_EMISAR_D4S_219C_DRIVER = “cfg-emisar-d4s-219c.h”
Thanks TK, that was indeed the problem. Learn something new every day.
It did compile properly and appears to be working as well!
Now that I am starting to dig into the code I am really liking it.
I like that dual switch option in the code as well! I have wanted that in the past.
A few random questions as I try to figure out the code, sorry for the long list:
1: The indicator LED is not working, it is set to PB4 but it is not lighting up. Does it output ground or V+ by default? Can that be changed? Is there another setting that is needed to switch the auxLED from pb2 pin?
2: I see notes on a lot of the defines saying that that it will use this if not defined per-driver. Does this mean I can just copy/paste these defines into the driver config files and it will use those instead? I assume it should be in the cfg file?
3: Does Anduril use any form of low pass filter for the ADC readings? With the hot rods I work with I had issues in the past with the ADC readings spiking and causing strange behavior. DEL added a simple low pass filter to average the readings over a few seconds that helped this a lot.
4: Is it possible to instead of having the main LED’s blink when it passes a channel barrier, for it to instead blink the switch LED like narsil? It will blink out what channel it is using when you release the button.
5: Where can I set the default max ramp level? It would seem to be the RAMP_LENGTH but that is set to 150 now yet the ramp seems to stop around 50%?
6: how would I easily limit the turbo/max output? Can I just comment out the end of the FET ramp? Or does it have to match the 7135 channel length?
Thanks for all the hard work put into all the firmwares you have worked on TK and everyone else involved with the real coding. You have truly pushed flashlights forward by leaps and bounds with all this work! Thank you for also dumming it down enough that even people like me can work with it after having things explained.
Well, I flashed my Q8, my 219c D4S and a few convoys with no issues. I went to flash my XPL-HI D4S, it wrote fine, but verified a bad bit so I chose to reflash. Now I repeatedly get initialization failures when trying to program through AVRDUDESS.
Im set to Attiny 85, command as follows: -c usbasp -p t85 -B 0.5 -F -U flash:w:C:\Builds\anduril.EMISAR_D4S.hex -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m
Ive tried slower bitrates with no luck. When I use the -F force option I get random signature failures.
avrdude.exe: Device signature = 0x6c6675
avrdude.exe: Expected signature for ATtiny85 is 1E 93 0B
or avrdude.exe: Device signature = 0x626f6f
when I use the MCU detect option, I get many random signatures.
I think it may be a good idea to update the flashing scripts and recommended practices. Specifically, the following changes:
Split each flash*.sh script into two: One to flash the firmware, one to flash the fuses.
Change the recommended flashing procedures to firmware-only, no fuses.
Hopefully this can reduce the risk of accidentally locking MCUs. On a D4S, for example, it’s important to make sure the connectors have sufficient contact to transfer data reliably, and don’t move at all while flashing. Otherwise it could send corrupt data and set the wrong fuse values, bricking the MCU.
On the D4S in particular, I’m using solid-core wire which just barely fits. It’s placed so that there is some tension holding the wires against the edges of the vias. And I plug everything in, place it on a table, and don’t touch it at all while flashing. This keeps things from getting disconnected mid-flash.
Still though, having it flake out during the middle of sending a single byte for the fuse value… that’s hella bad luck.
1a. It’d be hard to say exactly without seeing the code. Maybe the option to enable aux LEDs isn’t defined?
1b. V+ by default.
2. Yes.
3. Yes.
4. By default, it switches the button LED from low to high when it passes the 1x7135 boundary. The LED state and brightness is directly tied to the ramp level, and it has no facility for blinking things out independent of the main LEDs. This is partly to keep code size down, but mostly because it’s a simple and straightforward way to make the button LEDs do something useful.
5. No, not RAMP_LENGTH. Look for the ramp ceiling values.
6. To reduce max power, change the PWM table values. Don’t make the PWM tables different lengths, because they all need to be the same.
I think thats exactly what happened. The first D4S I had to try 2-3 times but I took it very slow, flashing the fuses first then removing that section and flashing the FW.
Since I have to flash through Windows (the Linux subsystem cant see the USBASP) Im writing two separate .bats to flash the fuses first, then ONLY the firmware to mitigate this. No more GUI to mess things up. Either way, live and learn. Just a shame that it was my green XPL-HI version. Ill swap the 219c star out of the black one, and replace it with the HIs.
That PCB is REALLY jammed in there (or Im too gentle) though otherwise I would have went the replace MCU route. If anyone is interested in taking a crack at fixing/replacing this MCU, pm me and you might be able to get a 219c D4S for cheap.
So it should be as simple as this right? :
Attiny 85
FW- avrdude -c usbasp -p t85 -U flash:w:%1.hex:a
Fuses- avrdude -c usbasp -p t85 -u -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m
1A: Bingo, I did not realize that the D4 didn’t have a lighted switch so when I copied the code from that file it did not have the define. I meant to use the D4S file when I was researching but for some reason used the D4.
2: Do I need to use the indef/undef ect options when using the defines per driver? It seems that some of the per-driver defines use this and others do not. EDIT: I copied the ramp from narsil but it is 158 length instead of 150. When I change this I get this compile error even though I have the ifdef / undef lines in place:
5: Ok it is the ramp smooth ceiling. If I wanted 60% I assume I could do (MAX_LEVEL*3/5)? Is there a reason I could not simply do (MAX_LEVEL*0.6)?
6: Ok, so keep the ramps the same length. So could I just comment out the same length of both ramps and adjust the ramp length to match to reduce power? Or better yet if I simple reduce the ramp length define, will it ignore the ramp after the set number? That would be fantastic.
7: What do these defines do exactly?
HALFSPEED_LEVEL I saw something mentioned about slowing the MCU down to save power? I assume this is what these defines do?
QUARTERSPEED_LEVEL
Thanks again, think I am starting to get the hang of this now.
Quick question, I was having trouble getting my driver specific FUDGE_FACTOR defines to input correctly, Anduril build. I thought that the code would just work its way down, so if something is defined, I can redefine it later in the code with an undef/redef.
So what happened is that in the build, the FUDGE_FACTOR was getting defined in the hwcfg, but was staying at 7 through the build even after redef it later to 3. Im guessing that its because that value is further inputted into something in spaghetti-monsters.h includes\code, but I do not know. Looking for some advice.
That is similar to the issue I was having above when trying to change the ramp length. The undef did not seem to work. If I manually commented out the ramp length in the anduril.c file it compiled without errors.
My guess is that some calculations for battcheck_VpT or otherwise are created based on the value of FUDGE_FACTOR at the time of the calculation in the code, so redefining it later wont do anything because the value was already extracted from the variable.
Either way im looking into a better way of doing this so its more usable, but would like to know for future reference.