Adventures in TinyAVR 1-Series

276 posts / 0 new
Last post
icpart
Offline
Last seen: 14 hours 21 min ago
Joined: 04/15/2019 - 01:13
Posts: 327
Location: Bulgaria

thefreeman wrote:

Sorry it’s me again, never mind my previous post, that was just a bad solder joint on my test board Facepalm , compiling and flashing works fine. I did further testing on my driver and the problem comes from the boost enable pin, it’s floating at ~0.8V whether it’s off or on, I also assigned it to others pins (PB1, PB4, normally it’s PB3, for testing I enabled pull-up on PB3, which for some strange reason is at 2.2V instead of 2.8V) same result, then I assigned it to PA5 and it works : 0V when off, 2.8V when on. How does that make sense ?

 


Maybe bad tracing on PCB. Is the enable pin have direct connection to MCU or there is some pullup resistors?
Quadrupel
Quadrupel's picture
Offline
Last seen: 1 day 22 hours ago
Joined: 12/03/2017 - 10:40
Posts: 729
Location: Lithuania

Only one difference i see is that PA5 is port A ;))

thefreeman
thefreeman's picture
Online
Last seen: 4 sec ago
Joined: 01/06/2020 - 09:56
Posts: 871
Location: France

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.

gchart
gchart's picture
Offline
Last seen: 11 hours 59 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

Huh, that’s really quite strange.

thefreeman
thefreeman's picture
Online
Last seen: 4 sec ago
Joined: 01/06/2020 - 09:56
Posts: 871
Location: France

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.

gchart
gchart's picture
Offline
Last seen: 11 hours 59 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

thefreeman wrote:
PC3 led enable… No led enable

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?

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

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
thefreeman
thefreeman's picture
Online
Last seen: 4 sec ago
Joined: 01/06/2020 - 09:56
Posts: 871
Location: France

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.

gchart
gchart's picture
Offline
Last seen: 11 hours 59 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

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).

thefreeman
thefreeman's picture
Online
Last seen: 4 sec ago
Joined: 01/06/2020 - 09:56
Posts: 871
Location: France

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.

thefreeman
thefreeman's picture
Online
Last seen: 4 sec ago
Joined: 01/06/2020 - 09:56
Posts: 871
Location: France

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).

gchart
gchart's picture
Offline
Last seen: 11 hours 59 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

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

thefreeman
thefreeman's picture
Online
Last seen: 4 sec ago
Joined: 01/06/2020 - 09:56
Posts: 871
Location: France

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

Thank you Thumbs Up Thumbs Up

gchart
gchart's picture
Offline
Last seen: 11 hours 59 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

Great!! You’re welcome

thefreeman
thefreeman's picture
Online
Last seen: 4 sec ago
Joined: 01/06/2020 - 09:56
Posts: 871
Location: France

ToyKeeper wrote:

For 5/10 MHz, I just measured the PWM speed and got 19.22 kHz… which suggests it’s either fast PWM at 5 MHz or phase-correct at 10 MHz. Looking at the code, it appears to be 5 MHz with fast PWM. I haven’t measured that before on this MCU, but older models had issues with fast PWM at low levels and at full output, since each pulse would turn on and off at least for one cycle regardless of the target value… so 0/255 wasn’t fully off and 255/255 wasn’t fully on. So it may be worth some investigation to see if that’s still the case, and maybe switch to phase-correct 10MHz. But that’s just a minor potential optimization for later.

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.

gchart
gchart's picture
Offline
Last seen: 11 hours 59 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

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

thefreeman
thefreeman's picture
Online
Last seen: 4 sec ago
Joined: 01/06/2020 - 09:56
Posts: 871
Location: France

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.

thefreeman
thefreeman's picture
Online
Last seen: 4 sec ago
Joined: 01/06/2020 - 09:56
Posts: 871
Location: France

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.

Dlux
Offline
Last seen: 15 hours 20 min ago
Joined: 05/27/2019 - 18:43
Posts: 66

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.

gchart
gchart's picture
Offline
Last seen: 11 hours 59 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

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.

thefreeman
thefreeman's picture
Online
Last seen: 4 sec ago
Joined: 01/06/2020 - 09:56
Posts: 871
Location: France
thefreeman wrote:
Hmm, and here I was wondering if it mattered if the V+ for flashing was connected before or after the LDO, if like, the MCU was powered from a lower voltage (ldo voltage) than the UDPI signal it would cause issues (maybe a stupid question…).

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.

gchart wrote:
Is that the case for both while the MCU is awake and sleeping?

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

gchart
gchart's picture
Offline
Last seen: 11 hours 59 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

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.

https://github.com/ElTangas/jtag2updi

ElTangas wrote:

Currently, I have not tested this software with a level shifter, however, since the UPDI pin is high voltage tolerant, it's ok to have V_prog > V_target, but not the reverse. Warning: only the UPDI pins of devices that support high voltage programming should be assumed to be high voltage tolerant. This is not the case for the MegaAVR 0-series or AVR-DA series! However, the current injection spec for I/O pins on these parts is far more generous that it is for older AVR devices it is not clear if the UPDI pin is included in this.

Notice, however, that the logic levels need to be compatible for successful programming: V_target cannot be lower than about 60% of V_prog (60% will likelly work, 70% is guaranteed to work). Therefore, it will not be possible to program a 2.5V target with a 5.0V programmer, because communication errors will surely occur (but no electrical damage), but if V_target is 3.3V (66% of 5.0V) chances are good.

 

                                            V_prog                 V_target
                                              +-+                     +-+
                                               |                       |
 +----------+          +---------------------+ |                       | +--------------------+
 | PC       |          | Programmer          +-+                       +-+  Target            |
 | avrdude  |          |                     |      +----------+         |                    |
 |       TX +----------+ RX              PD6 +------+   4k7    +---------+ UPDI               |
 |          |          |                     |      +----------+         |                    |
 |       RX +----------+ TX                  |                           |                    |
 |          |          |                     |                           |                    |
 |          |          |                     |                           |                    |
 |          |          |                     +--+                     +--+                    |
 +----------+          +---------------------+  |                     |  +--------------------+
             JTAGICE MkII                      +-+     UPDI          +-+
             Protocol                          GND     Protocol      GND


thefreeman
thefreeman's picture
Online
Last seen: 4 sec ago
Joined: 01/06/2020 - 09:56
Posts: 871
Location: France

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.

thefreeman
thefreeman's picture
Online
Last seen: 4 sec ago
Joined: 01/06/2020 - 09:56
Posts: 871
Location: France

I tested with a bench PSU, it flashes without errors down to VCC = 1.9V, at 1.8V it reads the device but fails at erasing.

gchart
gchart's picture
Offline
Last seen: 11 hours 59 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

I just pushed a few changes to my Anduril2 branch:

  • Switched to 10 MHz clock and Phase-Correct (dual slope) PWM instead of Fast (single slope) PWM at 5 MHz. This results in the same effective PWM speed: 19.6 kHz in the upper ranges, down to 4.9 kHz in the lowest modes (due to the dynamic underclocking mechanism).
  • Added some documentation to the PWM setup code including a some instructions and a link to the datasheet
  • Instead of Factory Reset forcing a thermal offset to assume an ambient temperature of 21°C, a Factory Reset for the 1-Series will clear any user-set thermal offset since the internal sensor is factory calibrated.

thefreeman
thefreeman's picture
Online
Last seen: 4 sec ago
Joined: 01/06/2020 - 09:56
Posts: 871
Location: France

Nice!

  • phase correct allows for full on and full off PWM, are there other advantages ? For drivers where we use the filtered PWM signal it’s not really an issue to have 1/resolution-1 as the min/max, and running the MCU slower saves power so if there are no other advantages then fast PWM is preferable.
  • Thumbs Up
  • Thumbs Up

edit :

Not relevant for us then.

gchart
gchart's picture
Offline
Last seen: 11 hours 59 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

thefreeman wrote:
phase correct allows for full on and full off PWM, are there other advantages ? For drivers where we use the filtered PWM signal it’s not really an issue to have 1/resolution-1 as the min/max, and running the MCU slower saves power so if there are no other advantages then fast PWM is preferable.

I’m not aware of other benefits, it’s mostly to just get the Full-On and Full-Off signals.

For the drivers with a filtered PWM signal, you can still use Single Slope (Fast) when setting up the PWM in hwdef. And in the config file, just set the QUATERSPEED_LEVEL and HALFSPEED_LEVEL really high so that the MCU is running underclocked most all of the time. At least that’s the easiest thing I can think of at the moment.

SammysHP
SammysHP's picture
Offline
Last seen: 6 hours 39 min ago
Joined: 06/25/2019 - 14:35
Posts: 981
Location: Germany

Haven’t checked the datasheet, but what’s the required voltage and power consumption for the higher clock? Could it be an issue?

gchart
gchart's picture
Offline
Last seen: 11 hours 59 min ago
Joined: 03/19/2016 - 11:57
Posts: 3158
Location: Central IL

That’s possible. I don’t have a bench power supply and scope to really say for sure. The datasheet says 10 MHz is good down to 2.7 volts.

SammysHP
SammysHP's picture
Offline
Last seen: 6 hours 39 min ago
Joined: 06/25/2019 - 14:35
Posts: 981
Location: Germany

Look at section 37. Power consumption is more or less linear, but even at 10 MHz only 4 mA, so not worth to think about it. Smile

thefreeman
thefreeman's picture
Online
Last seen: 4 sec ago
Joined: 01/06/2020 - 09:56
Posts: 871
Location: France

gchart wrote:

I’m not aware of other benefits, it’s mostly to just get the Full-On and Full-Off signals.

For the drivers with a filtered PWM signal, you can still use Single Slope (Fast) when setting up the PWM in hwdef. And in the config file, just set the QUATERSPEED_LEVEL and HALFSPEED_LEVEL really high so that the MCU is running underclocked most all of the time. At least that’s the easiest thing I can think of at the moment.

Thanks, I’ll do that.

Another question :
Is it possible to change the internal reference voltage in the hwdef file ? Using 2.5V instead 1.1V allows to use a divider with the same values, it’s a small detail but reducing the amount of different resistor values is always a good thing.

Pages