Adventures in TinyAVR 1-Series

Just as I wrote, I have V+ from the Xplained Nano connected to the battery spring by a crocodile clip. The Xplained Nano powers the MCU. You did write you made the change to make layout easier, I just added this because layout is even easier with two pads instead of three, it works fine for me.

:+1: sorry, I was skimming as I’m working at the moment. I should know better than to try multi-tasking…

Digikey

Is this the right component?

Well I’ll be! They got a batch in earlier than expected. I’m halfway tempted to try and cancel my Mouser order and place one at Digikey.

Aaaaannndd they’re gone

Yeah lol, a few moments after I ordered, I also wanted a buck IC, some 9000 in stock in the morning, then zero in the afternoon when I placed my order, plenty of other ICs have poor availability too.

They’re also gone from Farnell.

I had 2 in my cart along with a few odds and ends and saw this this morning when I finally was ready to checkout.

Gchart, do you have an example hwdef file with TCD ?

Sorry, I haven’t used TCD with Anduril yet. But I do have a fairly bare bones TCD 10-bit PWM test code here:

http://www.ghart.com/blf/firmware/Tests/pwm_tcd_led.c

It’s been a while since I’ve played with the TCD, I should do that again. Let me know if you run into issues and I might be able to provide some pointers or run some tests on the Xplained Mini dev board.

Oh… for now I’ve just been copy pasting code from other files so that’s a bit problematic :blush:

I tested with test code, it worked.

This is where I'm at for my boost driver.

hwdef file : (removed since it was a bit long)

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?