Adventures in TinyAVR 1-Series

I replaced the 416 with a 1616 on the xplained board, breadboarded the SP10S layout, with the LED enable assigned to PA1 (original) no problem, assigned to PB1 or PB2, doesn’t work, assigned to PC1, works.

LED enable just doesn’t work on B pins.

Huh, that’s really quite strange.

Some other tests

PB0 PWM
PA5 led enable
PB2 R
PB1 G
PB4 B

No PWM

PB0 PWM1
PA5 led enable

OK

PB0 PWM
PA5 led enable
PC0 R
PC1 G
PC2 B

OK

PB0 PWM
PC3 led enable
PC0 R
PC1 G
PC2 B

No led enable

I wanted to also test PWM on PA3 (WO3) but I don’t know what to put in hwdef for that.

That’s really weird. You might have to check in over at avrfreaks to see if they have any ideas about the PortC behavior. You’re just using it as a basic IO pin and setting it high and low, right? Do you have a pull-down resistor on your LED enable channel? If so, what value? Maybe PortC output is very weak or something?

You’ll need to enable Split mode. I haven’t tried that yet myself, but I see the very knowledgable El Tangas has examples here

The output pins are connected to LEDs with current limiting resistors to test the pins behavior.

Moving the RGB LEDs to port A :

PB0 PWM
PC3 led enable
PA1 R
PA2 G
PA3 B

OK

It looks to me that different stuff can’t be on the same port.

Ohhh, I think you’re onto something! Worth noting, each “pin group” has a maximum combined source/sink current. According to Table 36-10, that appears to be 100 mA. That sounds like plenty, but very well could be what you’re running into. I’m pretty sure for these chips, “pin group” is synonymous with “port” (eg, Port A, Port B, and Port C).

Hmm, I put 100Ω on the RGB leds and PWM LED, 10K on the LED enable LED, I’ll try with more resistance on the two former, but it mirrors the issues on my driver, on which the load is on the uA order.

Testing with 10K resistors on the status leds, same result.
Moving led enable to PA5

PB0 PWM
PA5 led enable
PA1 R
PA2 G
PA3 B

No led enable.

Circuit on the breadboard :

I also checked with a voltmeter instead of status leds (i.e. the pins are only connected to the voltmeter), same result, I just used leds because it’s quicker for checking the pins status.

hwdef

So at this point I’m eliminating any issues with the circuit, it must be in the code.

In the present state if I want to use the attiny1616 with my driver I must wire the PWM, led enable and RBG on different ports, which is possible of course, just not as convenient as using any pins. But if there is functionality added for the current sense resistor selection, then that’ll possibly means it’ll have to be on another (nonexistant) port. (Toykeeper said she has an unfinished branch that might have functionality for this).

Ohhh, I think I finally noticed it. At least I hope so. When you set the DIR for those RGB, each write is wiping out the entire VPORTA.DIR contents.

Replace this:

    VPORTA.DIR = PIN5_bm;  //enable
    VPORTB.DIR = PIN0_bm;   // PWM
    VPORTA.DIR = PIN1_bm; //R
    VPORTA.DIR = PIN2_bm; //G
    VPORTA.DIR = PIN3_bm; //B

With this:

    VPORTA.DIR = PIN5_bm | PIN3_bm | PIN2_bm | PIN1_bm;  //enable, R, G, B
    VPORTB.DIR = PIN0_bm;   // PWM

Or perhaps (note the added pipes):

    VPORTA.DIR |= PIN5_bm;  //enable
    VPORTB.DIR |= PIN0_bm;   // PWM
    VPORTA.DIR |= PIN1_bm; //R
    VPORTA.DIR |= PIN2_bm; //G
    VPORTA.DIR |= PIN3_bm; //B

BTW, SpenceKonde has a nice write up on AVR’s bit manipulation with the PORT & VPORT registers here

Yes it works, of course I should have properly copied the syntax from your hwdef files… sorry for having the stupid.

Thank you :+1: :+1:

Great!! You’re welcome

At 1023/1023 it’s not fully on, it’s off the same amount of time it’s on at 1/1023, 200ns so 1 cycle.

Is that with TCA? Does it act the same way in 8-bit? And does 0/1023 go fully off?

Yes and yes.

Edit : for the 3rd question I’m guessing no, anduril apparently turns the flashligh off (led enable goes off) when putting 0 as the floor so it’s not obvious, but shortly before that the level just stops at 1/1023 for like half a second, instead of smoothly going to 0.

Looking with the scope, it seems that having the PWM pin (e.g. PB0) connected to a floating pin (e.g. PC0), doesn’t affect the waveform. The difference in current draw with the floating pin is about 50~100uA. I might do that, that way the hardware would be compatible with both TCA and TCD.

Interesting thefreeman, I thought that a floating pin would consume a significant amount of power.
Thanks all of you for sharing your progress, it is being a really entertaining reading for me.

Great to know! That would certainly be handy for a development/testing build so that you can play around with trying to get TCD working. The 50-100 uA isn’t a whole lot, but more than I would want in a production light. Is that the case for both while the MCU is awake and sleeping? I’ve always heard that a pin shouldn’t be left floating in order to minimize current draw, but I’ve been curious about just how big of an impact it makes.

So after of before the LDO it works, also when powered by another source e.g. the battery. Mike already mentionned it but with the LDO I wanted to test to be sure.

Uh, I’m not sure, I’ll have to re test.

Good to know! I haven't experimented much with it, but ElTangas says that as long as the VCC at the MCU is ~60%+ of the programmer's voltage, it should work just fine.

60% of 5V so 3V? LDO is 2.8V on my driver, so maybe it wont be entirely reliable, hmm, the programmer’s voltage can’t be lowered ?

Edit : I guess it’s directly the USB voltage so it can’t be lowered.