Author Topic: ATTiny48 Inconsistent Startup Behavior  (Read 1868 times)

0 Members and 1 Guest are viewing this topic.

Offline meshtronTopic starter

  • Regular Contributor
  • *
  • Posts: 190
  • Country: us
ATTiny48 Inconsistent Startup Behavior
« on: November 11, 2023, 07:20:46 pm »
I'm working on a bare metal project with an ATTiny48 MCU (28 TQFN) and having some strange behavior on startup.  It's a product I will be (eventually) selling so would rather not post full schematics and code even though I understand that would be helpful - so please bear with me.

The device is a 12VDC PWM load driver.  It's pretty straightforward with the ATTiny48 MCU, a DRV8145 high-side, half-bridge driver (which just gets me built-in load monitoring, reverse polarity protection, and nice fault monitoring).  Onboard there are some dip switches to set options and a pot for user adjustment of some settings.  Generally speaking, everything works exactly like it should.  An important note is that my device is high-side switching and the input power comes from a switched 12VDC source which then powers the logic circuit through a LM7805.  The board is grounded to the same 12V source (battery) but the big load is only switching on the high-side.

Internally I'm using Timer0 to tick via interrupt ~once per millisecond, the 10-bit ADC on several pins, and the PWM in output compare mode - all working fine as near as I can tell.

The issue I'm having appears to affect all modes, but is most visible (and easiest to explain) in one mode.  The intended workflow is this:

- Switch on, 12VDC power comes in
- System starts, does the following in setup():
  - Read DIP switches
  - Do one ADC read to get pot volts
  - Calculate a duty cycle and frequency from that
  - Output a PWM signal on PINB1 (OC1A) to the DRV8145

And, that works just right.  Switch on, the load (either an LED light or a motor, but in testing it's a high-current LED) basically instantly comes on at the proper, dimmed setting.  BUT...

If I switch power off, let it sit for (say) 3 seconds, and switch it back on, I get different behavior at startup.  I'm still trying to figure out exactly what's happening, but for something like 800ms, the output of the PWM changes multiple times.  Starts at correct duty cycle (based on pot), but then changes quickly two or three times all the way up to straight DC, then finally drops again back to expected setting.

(Maybe?) Coincidentally during this same time, I've read the voltage on a cap that tells me whether or not the system was recently shut down.  And, once I read it, I switch to recharge it.  That 150uF cap is on the +5V side and is connected to the MCU pin through a 220-ohm resistor.

If I switch power off and let it sit for something like 4+ seconds, it starts up perfectly as before.

I have two theories:
 a) Maybe one of the onboard caps (there are 2x 220uF bulk caps between Vin and GND and the afore-mentioned 150uF cap connected to the MCU) is keeping some part of the MCU alive/set for multiple seconds after power off (this seems unlikely)
 b) Maybe when I charge the 150uF cap by setting the MCU pin high (incidentally it's PinC4), maybe I'm getting some voltage drop/weirdness elsewhere?

So - any thoughts?  Where might you start on something like this?  I don't think it's a code problem since it works exactly right so long as it's off long enough between startups.  But, maybe my code should be checking some condition I haven't considered to behave differently.

Appreciate any input - I'm kind of pulling my hair out at this point!  I think my next step is to try to capture the weird behavior on the scope for various points like my +5V rail voltage at the MCU.
« Last Edit: November 11, 2023, 08:37:45 pm by meshtron »
 

Online wraper

  • Supporter
  • ****
  • Posts: 19537
  • Country: lv
Re: ATTiny48 Inconsistent Startup Behavior
« Reply #1 on: November 11, 2023, 07:30:23 pm »
Do you use Brown-out detection? So MCU gets actually properly reset when power is still present but not enough for correct operation. Then no mention about how you initialize peripherals at startup which is among the first things you should think about.
 
The following users thanked this post: meshtron

Offline jfiresto

  • Super Contributor
  • ***
  • Posts: 1055
  • Country: de
Re: ATTiny48 Inconsistent Startup Behavior
« Reply #2 on: November 11, 2023, 07:33:17 pm »
That was what I was typing as well (or something in that direction). See "Brown-Out Detection" (section 8.2.3) about resetting the MCU during low VCC.
-John
 
The following users thanked this post: meshtron

Offline floobydust

  • Super Contributor
  • ***
  • Posts: 9126
  • Country: ca
Re: ATTiny48 Inconsistent Startup Behavior
« Reply #3 on: November 11, 2023, 07:38:30 pm »
I would guess the MCU is not doing a proper POR because the 150uF cap is powering it through your short cold starts. That can also cause EEPROM corruption re: 5.3.5
You can try add a 1k resistor across the 5V rail to ensure it goes to 0V. What's on the external RESET pin? OSC startup time setting?
Look at your fuse settings for brownout detect as well.
 
The following users thanked this post: meshtron

Offline meshtronTopic starter

  • Regular Contributor
  • *
  • Posts: 190
  • Country: us
Re: ATTiny48 Inconsistent Startup Behavior
« Reply #4 on: November 11, 2023, 08:22:46 pm »
Answers to a few questions:
- Brownout is set at 2.7V
- OSC startup is at default which is Internal 8MHz oscillator, 6 CK/14 CK + 65ms
- Peripherals (really just the DRV8145) gets initialized properly even when it's misbehaving - otherwise there would be no output at all on Vout
- RESET pin (PinC6) is only connected to programming header, no other connections

The 150uF cap keeping the MCU semi-awake seems like the likely culprit.  I actually did a bit more work on figuring out timing too, the "cutoff" for behaving correctly seems to be more like 3-4 seconds.

I will try some different brownout settings and see if that changes things and/or helps - but first I'll read up on that stuff in the datasheet.  Thanks all!

EDIT: Missed question about OSC startup
EDIT2: Missed question about RESET
« Last Edit: November 11, 2023, 09:44:04 pm by meshtron »
 

Offline meshtronTopic starter

  • Regular Contributor
  • *
  • Posts: 190
  • Country: us
Re: ATTiny48 Inconsistent Startup Behavior
« Reply #5 on: November 11, 2023, 09:46:18 pm »
Hmmmm....

Also, the issue is significantly worse if I simply unplug my programmer (ATMEL ICE) from the programming header.  Seems like with that, even waiting 30+ seconds I get a "noisy" startup.

Maybe my +5V is coming online slower than I think AND the 150uF cap is causing issues.
 

Offline PlainName

  • Super Contributor
  • ***
  • Posts: 9015
  • Country: 00
Re: ATTiny48 Inconsistent Startup Behavior
« Reply #6 on: November 11, 2023, 10:03:15 pm »
You have a long enough fault period to try things like shorting the cap and seeing if that reduces the window significantly. That should tell you if the cap is keeping the chip awake, or if the voltage drop is too slow.
 
The following users thanked this post: meshtron

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2178
  • Country: fi
  • Embedded SW/HW.
Re: ATTiny48 Inconsistent Startup Behavior
« Reply #7 on: November 11, 2023, 10:24:41 pm »
Have you read this document already?

AN2519 - AVR Microcontroller Hardware Design Considerations

https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ApplicationNotes/ApplicationNotes/AN2519-AVR-Microcontroller-Hardware-Design-Considerations-00002519B.pdf

Check section about the reset circuitry and power supply.
 
The following users thanked this post: meshtron


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->