Close

verify your results

A project log for USB cable tester

I want something usb stick thingy-ish to check a usb cable

davedarkodavedarko 09/09/2015 at 07:380 Comments

So the code from last time didn't work at all, when I woke up the blue LEDs where totally dim. I've check the datasheet for the attiny45 and noticed once again - what works on an arduino must not work on a board using non-atmega328s. I hooked up my new UNI-T UT61E and measured 200uA - not the 0.1uA I've expected to see. With the help of the gist from JChristensen I verified (read copied) my code for the power down and measured a success - yes it's measurable - 0.1uA !

/* 
Things to safe power, according to datasheet:
 - turn off adc (not needed for LEDs)
 - turn off brown out detection (BOD)
 - turn off analog comparator
 - turn off internal voltage reference 
 - turn off watchdog timer
 - disable port pins per register
 
With the help of JChristensen/AVR Sleep
https://gist.github.com/JChristensen/5616922

*/

#include <avr/sleep.h>
#define BODS 7                     //BOD Sleep bit in MCUCR
#define BODSE 2                    //BOD Sleep enable bit in MCUCR

int leds[] = {4,0,1,2};
void setup() 
{
  for (int i=0; i<4; i++)
  {
    pinMode(leds[i], OUTPUT);
    digitalWrite(leds[i], HIGH);
    delay(200);
    digitalWrite(leds[i], LOW);
    delay(200);
  }
  die_until_reset();
}

void loop() { }

void die_until_reset()
{
  byte  mcucr1, mcucr2;

  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  MCUCR &= ~(_BV(ISC01) | _BV(ISC00));      //INT0 on low level
  ADCSRA &= ~_BV(ADEN);                     //disable ADC
  cli();                                    //stop interrupts to ensure the BOD timed sequence executes as required
  mcucr1 = MCUCR | _BV(BODS) | _BV(BODSE);  //turn off the brown-out detector
  mcucr2 = mcucr1 & ~_BV(BODSE);            //if the MCU does not have BOD disable capability,
  MCUCR = mcucr1;                           //  this code has no effect
  MCUCR = mcucr2;
  sleep_cpu();
}

Discussions