ATtiny1616 Best Sleep Using AC or Pin Level Detect

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've a circuit which inputs a slowly changing analog sine wave to a pin, where the AC (comparator) level compares it.

 

I'd like ideally to stick the chip into powerdown mode based on this pin being zero for a timeout, but reading into the datasheet the AC won't function. There's a low-level pin interrupt which may work but it'll be low level when I enter power-down - will it need to cycle high before hitting low again to fire the interrupt or immediately fire?

 

Alternatively I think the next best thing is to use Idle mode but switch the MAIN_CLK to use the 32KHz internal, which will allow the 20MHz internal to shutdown and the AC to continue working. The 32KHz is always running as it's fed into the RTC PTC. Although all other peripherals are disabled (CTRLA) I've read that feeding any CLK_PER into them does actually waste a bit of power.

 

How's my thinking?

 

Last Edited: Tue. Jun 21, 2022 - 10:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Think about how you could use pin change for this.  I.e. tell the level hen you go to sleep, and when you awaken.  Pin change good enough?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

snoopy33 wrote:
I've read that feeding any CLK_PER into them does actually waste a bit of power.
Very low (CMOS power dissipation is proportional to frequency)

 

edit :

Peripherals Power Consumption | tinyAVR® 1-series

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Tue. Jun 21, 2022 - 11:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

snoopy33 wrote:

slowly changing analog sine wave to a pin, where the AC (comparator) level compares it.

 

I'd like ideally to stick the chip into powerdown mode based on this pin being zero for a timeout

Strictly speaking a sine-wave is only zero for an infinitesimally small time.

A diagram/sketch of the waveform and trigger levels may help us understand.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Power breaks today are nothing spectacular: you will miss two or more sinusoides, that is all. Each sinusoide does have zero transition in 10ms time (when 50Hz), thus it is easy to catch a nasty event, do 10ms Pin change Interrupt to clear WDR, and use 16ms WDT.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The sine is a half rectified 0-200Hz signal, 0 to 80V. I believe it's too slow to trigger edge detect.
 

For the CMP I was also intending to use a resistor divider and a DAC with 0.55v REF rather than a single very high value resistor to limit current through the pins protection diode. For the CMP this offers much higher hysteretic change which a single resistor does not. However, the DAC doesn't run in power-down either.
 

I have the RTC PTC going at 2Hz to clear WDT, true I could speed that up and check the port status in code but the higher wakeups might be counterproductive to a deep sleep.
 

It comes down to, if the pin level is zero and I enable the pin LEVEL_LOW interrupt will it fire or will it wait until the level first goes high then returns to zero? If it does this then it'll be the best solution.

Last Edited: Wed. Jun 22, 2022 - 08:41 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For the CMP I was also intending to use a resistor divider and a DAC with 0.55v REF rather than a single very high value resistor 

If you are doing all this stuff to "save power", why not keep the AVR running?  How much will you net save & how much do you have?  

You could use a diode/R/C and after enough cycles build up enough voltage to trigger something.  That would also filter noise on the 80V line, if that is a concern.

Are you just wanting to turn on once the sinewave becomes present for a while?

Are you tuning on once a second, once a week? 60 times a second?

What about your power supplies?

 powerdown mode based on this pin being zero for a timeout

  timeout? Do you mean after the signal is gone for xxx cycles, kill the AVR? 

 

I believe it's too slow to trigger edge detect.

Maybe/maybe not...be sure to have some hysteresis so you don't get a bunch of chatter...even then it is a tug of war, since a signal can move slower & slower & eventually even hysteresis can lose the battle (but that is generally a fairly extreme case).

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm probably over-optimising, but why not be the best. wink

The power supply is a large super-capacitor (so it has quite a lot of leakage about 0.2mA) feeding into a boost converter which powers the AVR.

In idle mode I'm measuring the aforementioned half wave cycle using a CMPn and TCBn in frequency measurement mode. I'm planning to run the AVR at 250KHz if it's fast enough to get all the code ran within the RTC PIT's 2Hz cycle rate.

Once the half-wave cycle hasn't been detected for a while (4 minutes) most peripherals shut-down. At this point it would be ideal to enter power-down mode.

I don't think trigger edge will work, there's no hysteresis with a single resistor. Using the CMP permits using a voltage divider, the DAC and setting hysteresis. It's why I went with this for normal use to deal with noise.

For wake-up I don't care about noise of course, but changing to a single divider then forces this disadvantage during normal mode.

There's also one more issue with the single resistor approach, there's no discharge route and it may float above 0v a bit, I've seen this in a previous life with PIC's.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why not just poll every few ms?...you will see lots of "hi"s ..if you don't see 100 (or whatever number) of hi's in 40 seconds, 4 minutes, whatever, then shut down.  So you really aren't looking for an edge, just that the signal has disappeared.  The bigger the number, the more certain it is. Of course, if you need to wake up from the signal reappearing, that is a different story.

 

Also, beware of high ohms, & leaky Schottky diodes (especially if temperature extremes involved).

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here's where I'm at.

I'll use standby = idle all the time. This keeps the CMP and DAC running. 

In "Quasi standby" I'll switch CLK_PER to 32KHz, which given nothing else is using OSC20M directly will save the 125uA.

The RTC PTC fires at 2Hz. It checks the CMP INT flag (Int isn't enabled, I assume flag still gets set). If detected it switches CLK_PER to OSC20M. Now TCBx will start calculating the correct frequency. I have another software timeout shown in the code below that forces the quasi standby again.

I've made an assumption the CMP INT flag is being set when INT isn't enabled. This is how I've seen it on PIC16's before.

 

 static void quasiPowerDown (void) {

    HW_CMP_INT_RESET(MOTION_CMP);
     _PROTECTED_WRITE(CLKCTRL.MCLKCTRLA,CLKCTRL.MCLKCTRLA | CLKCTRL_CLKSEL_OSCULP32K_gc);
}
 
 
 while (1) {
        quasiPowerDown();
        ticks = 0;

        // the only wakeup will be from the rtc timer int, no need to check flag
        while(1) {
            sleep_cpu();
            wdt_reset();
            // any motion detected?
            if (HW_CMP_INT_STATUS(MOTION_CMP)) {
                // fast cpu
                 _PROTECTED_WRITE(CLKCTRL.MCLKCTRLA,CLKCTRL.MCLKCTRLA & ~(CLKCTRL_CLKSEL_OSCULP32K_gc));
                MOTION_Task();
                if (motion.moving) {
                    break;
                } else if (motion.hz) {
                    ticks = 0;
                } else {
                    ticks++;
                    if (ticks > MOTION_DETECTED_TICKS) { // must be > not = otherwise conflict with motion.moving
                        ticks = 0;
                        quasiPowerDown();
                    }
                }
            }
        }
        
    // normal bootup here, held in another while loop until quasi powerdown is required again
        
 }

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

snoopy33 wrote:
However, the DAC doesn't run in power-down either.
An alternative is a PORT to create a R-2R DAC; another alternative may be an AVR Dx ZCD in standby at 12 microamp typical.

External "BOD" may be a fit.

 

Sleep Mode Operation | AC | AVR® DB Family

Sleep Mode Operation | ZCD | AVR® DB Family

AN1051 AVR180: External Brown-Out Protection | Application Note | Microchip Technology

 


AN2508 AVR182: Zero Cross Detector | Application Note | Microchip Technology

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

snoopy33 wrote:

I believe it's too slow to trigger edge detect.

???  Tell more about that.  When you are using AC, aren't you using "edge detect"?  Are you referring to my suggestion about using pin change?  Why wouldn't it work, after you have conditioned your 80V signal and isolated it for safety of man and machine?

 

So, while designing that circuitry, add your "trip" trigger suitable for an AVR input.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.