Adventures in TinyAVR 1-Series

Oh actually, maybe the ramp could just be like this, with only one PWM (example with ramp lenght of 10)

PWM1_LEVELS 2, 500, 1023, 2, 20, 50, 100, 200, 500, 1023

With the mosfet for the high current range enabled from level 4 to 10.

I hate to break it to you, but it looks like Anduril will need some (hopefully minor?) updates/customizations to make TCD work. If you check out page 250 of the datasheet you’ll see how the TCD works with CMPxSET and CMPxCLR. It’s opposite of how we normally think of PWM. If you set CMPxSET to 0, the LED would be fully on. If you set it to 255 (8-bit) or 1023 (10-bit), then the LED will be fully off. You’ll notice that in my test code, I subtracted the desired PWM value from the period to get the inverse.

Also… you need to tell the TCD to synchronize any time you make a CMPxSET (or CMPxCLR) update. That’s the “TCD0.CTRLE |= TCD_SYNCEOC_bm;” line in my test code.

Pretty much anywhere PWMx_LVL is used, it’ll require a small update. After grepping around, it looks like most of the changes are going to be in fsm-ramping.c. There are also a couple lines in fsm-main.c and spaghetti-monster.h. None of the changes should be too terrible. If you want, I could make the changes if you’d like to test them.

Page 250 you mean ?
Honestly I’m not understanding much of what I read, so yeah, any help would be greatly appreciated
I knew I should have used PA4 or PA5 since they can be used with TCA, but tracing was easier with the opposite pins…

Edit : maybe, if you’re interested in this boost driver, I could send you one.

Yeah, I meant 250… oops.

Now that I think about it, the easiest thing to do might be to mimic some of what the Noctigon K9.3 is doing. It has an override for the set_level function defined specifically for it, all controlled in cfg files. Note how the top of the cfg-noctigon-k9.3.h file says:

// this model requires some special code
#define OVERRIDES_FILE cfg-noctigon-k9.3.c
#define OVERRIDE_SET_LEVEL
#define OVERRIDE_GRADUAL_TICK
inline void set_level_override(uint8_t level);

and then there’s a specific “c” file to contain those override functions. We’ll probably want to do the same thing. Then you can set things like “when level == 0 set the PWMx_LVL = PERIOD” and “PWMxLVL = PERIOD - PWM_GET(x,y)” as well as being able to say when to turn on and off those specific current set resistor channels.

Hmm yes maybe, though as long as I don’t know much about programming I think I won’t be able to do much here, I did try to learn in the past but got discouraged pretty quickly, I picked up again a book on C a couple of days ago but honestly I’d rather focus on the hardware if possible, as I have other driver projects, which I think people will find interesting too.
I messaged Toykeeper about this but she won’t be able to help at the moment.

Regarding TCD, I can make a new hardware revision, using PA4 (WO4) or PA5 (WO5), this way it’ll work with TCA and keeping the option for TCD in the future. Or maybe I could wire to both PBO (WO0) or PC3(alternate WO3) and PC0 (WOC), that would mean less change to the layout for this driver.

For the high dynamic range though, it’s kind of one of the main feature, but the driver can still works without it.

So for now I put an airwire to PB0 to test the basic functionalities, I ran into errors when building Anduril though, but maybe I missed some steps. Using Microship studio 7 (it seems that atmel studio is integrated into microchip studio now, or something like that) I :

  • created a GCC C executable project
  • copied all the files from toykeeper, spaghetti-monster and anduril in the project folder next to main.c, deleted that one.
  • right clicked on ’project name’ add existing file, and added all files so they appear in the solution wiener.
  • built ’project name’

I get a few error: unknown type name ’…’ with beacon-mode.h with battcheck-mode.h
And error: CONFIGFILE: No such file or directory in anduril.c
And 2 warnings.

Do you know what could be the cause ?

There was a working Atmel Studio project some time ago, but it was not maintained.
I suggest that you install bash or another Linux shell on your windows and use the regular build method.

While I’ve used Atmel Studio (on Windows) for firmware before, I’ve never used it for Anduril. You might try following this guide.

Also, don’t forget that you’ll want to use the version of Anduril found at my branch because it’s likely the only one out there that has AVR 1-Series support.

I can try helping with the hwdef and cfg files, but it’s gonna take me a bit.

Yep that’s the guide I saw, but I followed Agro’s advice :wink: , I installed an Ubuntu VM, followed Toykeeper’s instructions , and compiled her branch to check that the basic stuff works fine, all very straightforward.

Then for your branch (yes it’s the one I was using :wink: ) I got the extracted DFP, put its path in your build script, changed 412 to 1616 in it and put the build script in the anduril folder.
Is there something more to do ? (like specify somewhere to use your build script )

I used the make command and it compiled all files without issue, mine too.

Then in atmel/microchip studio I used device programing, put the hex file in memories/flash and then hit program.

The driver turns on and off on the lowest output and that’s all, no ramping, so I must have an issue somewhere in my hwdef or cfg files, or maybe elsewhere.

Ok, you’ve got it compiling and flashed, that’s great progress!

Do you still have it wired up to use TCD? No air-wires or other things for testing? Could you upload your hwdef and config files, perhaps to PasteBin so-as not to overwhelm this thread?

Hwdef
Cfg

I should have put less stuff in it for basic testing though.

Edit : airwire from PB0 to PC0 (and PC1 since they’re connected on pcb), I tried with and without pull-up on PC0 and PC1 in the bottom of hwdef, but maybe I should cut the traces ? It worked fine with your test_tcd code even though pc0 and pc1 were connected together.

A few thoughts:

  • In hwdef for the Aux, you don’t need the separate AUXLED_x_PORT definitions, just the single AUXLED_RGB_PORT that you already have. AUXLED_RGB_DDR and AUXLED_RGB_PUE can be removed
  • In cfg I’m not sure about starting the ramp at 0, usually you’d want it at 1 or higher.
  • If you’re going to try with the airwire from PB0, I definitely wouldn’t set the pullups on PC0 and PC1. By pulling those pins high, that could/will interfere with your PWM signal.
  • Don’t forget to set PA6 as output. You might try setting it high to see if you can get the higher current range to activate, though I’m not sure that would actually tell you anything. Just a thought.

Thanks for having taken a look

  • OK, but if one is on another ”port” (e.g red on PAx and R, G on PBx) then I would need to put separate AUXLED_x_PORT definitions ?
  • yep, not sure why I did that
  • makes sense
  • PB0 too, I forgot :person_facepalming:

But, it’s not working anymore (no initial flash), I’ll resume tomorrow with a fresh mind, it’s getting late.

I’m a bit confused with the instructions for Linux on the first page, after putting the DFP path into your build script, what do I do with it ? Does it just need to be in the anduril folder? with or without it in it using the command ”make” compile everything without errors, isn’t this strange ?

All you should need to do is update the DFP line in the build script with your directory for those files. It’s strange that it would build successfully without them. If you run the following commands, what versions does it say you have?

apt-cache policy avr-libc
apt-cache policy gcc-avr

I’m on avr-libc version 2.0.0 and gcc-avr version 5.4.0. I’ve heard there are other (development) versions available that might have the device packs baked-in.

avr-libc:
Installed: 1:2.0.0+Atmel3.6.1-2
Candidate: 1:2.0.0+Atmel3.6.1-2
Version table:
*** 1:2.0.0+Atmel3.6.1-2 500

gcc-avr:
Installed: 1:5.4.0+Atmel3.6.1-2build1
Candidate: 1:5.4.0+Atmel3.6.1-2build1
Version table:
*** 1:5.4.0+Atmel3.6.1-2build1 500

I made a test board with one 7135 and the same pinout as your BLF_Q8_T1616 so I don’t have to touch anything, it doesn’t work, so there is something wrong either with the building or flashing.

Could you send me an hex file for the BLF_Q8_T1616 ?

edit : never mind that was a bad solder joint, building and flashing is ok.

There should be one here that you can try out: Index of /blf/firmware/hex_files

If I remember correctly, it’s using this layout: What did you mod today? - #9719 by gchart

Thank you, I’ll test that tomorrow.

Hi, I’m merging the code into my anduril2 branch. Overall it looks really good, clean and clear, but I have some questions…

In MODELS it adds a few entries, and I’m wondering which ones use factory hardware and which ones require custom driver hardware:

0622    sofirn-sp10s
0631    blf-q8-t1616
0632    sofirn-sp36-t1616
0633    blf-lantern-t1616 
1618    gchart-fet1-t16

If any of the “06” (Sofirn) builds require custom hardware, I’ll re-number them under the “16” brand.

In fsm-adc.c, why does the temperature shift right 8 and then left 6, instead of just shifting right 2 bits? It seems like this throws out some potential extra precision. Also, it uses 32-bit math to avoid 2 bits of potential overflow, but then sheds 6 bits, so I’m wondering if that might be avoidable. Not sure how many clock cycles it takes for the 32-bit operation on this MCU, but I’m trying to keep interrupt handler timing as short as possible.

In tk-attiny.h, it sets the base clock speed to 5 MHz, but could have also used 10 MHz. I can see reasons for either one to be used, but I’m wondering how the PWM speed and power usage look in both configurations. Have you measured this?

The SP10S build has pretty unusual ramp values and looks like the low channel is very low. Would it benefit from some extra sub-ramping on the low channel during the bottom portion of the high channel’s ramp? Not sure if that could provide extra resolution or not, especially with dual voltage.

Sorry about how messy it is to add a new MCU. I’ve been thinking about ways to make this process easier and cleaner, but I’m not sure what the best approach is or when it’ll happen.

Hey TK, good to see you around!

  • The 06xx builds for t1616: Sofirn approached me about working with them to convert these models to use the t1616. So these are pre-production builds, but could hopefully one day (soon?) be actual Sofirn lights. Feel free to number them however you see fit!
  • The “shift right 8 bits” was part of code I copied right from Atmel (attiny1616 manual page 435). Then I saw you left aligned things. I didn’t combine the two, but it looks like that could be done. In general though, that chunk of code was just a copy & paste from Atmel. I didn’t bother trying to optimize it for our use case.
  • The power usage between 5 MHz and 10 MHz is minimal unless we’re trying to really stretch runtime on low modes. You can see some test results here
  • I agree, the SP10S ramp is a bit unusual. And yes, that’s because the low channel is very low. But the lowest setting of the big channel is appreciably higher. I think the high channel is a straight 3.13V feed while the low side adds a 4.7 kOhm resistor. I’m not that great with customizing the ramps, and flashing new builds meant tearing the light apart again, so I rolled with a “yeah, that’ll work” ramp. I’d be up for trying something new though!