Esempio n. 1
0
	unsigned int Complete(void)
	{
		unsigned int result = AdcCountsToBatteryVoltage(AdcConversion<input, channel>::ReadADC());
		BATTERY_SENSE_DISABLE();
		if (QueryCalibrationValid())
			result += GetBatteryCalibrationValue();
		Average.AddSample(result);
		return result;
	}
Esempio n. 2
0
static void EnterShippingMode(void)
{
  /* Turn off the watchdog timer */
  WDTCTL = WDTPW + WDTHOLD;
#ifdef DIGITAL
  ClearLcd();
#endif
  ConfigResetPin(RST_PIN_ENABLED);
  
  __delay_cycles(100000);
  
  __disable_interrupt();
  __no_operation();
  
  DisableRtosTick();
  
  /* 
   * the radio draws more current in reset than it does after 
   * the patch is loaded
   */
  
  DISABLE_DISPLAY_POWER();
  DISABLE_LCD_ENABLE();
  BATTERY_CHARGE_DISABLE();
  LIGHT_SENSOR_SHUTDOWN();
  BATTERY_SENSE_DISABLE();
  HARDWARE_CFG_SENSE_DISABLE();
  APPLE_POWER_DISABLE();
  ACCELEROMETER_INT_DISABLE();
  DISABLE_BUTTONS();
  
#ifdef DIGITAL
  /* SHIPPING */
  ENABLE_SHIPPING_WAKEUP();
#endif
  
  SELECT_ACLK(SELA__REFOCLK);                
  SELECT_FLLREF(SELREF__REFOCLK); 
  UCSCTL8 &= ~SMCLKREQEN;
  UCSCTL6 |= SMCLKOFF;
  /* disable aclk */
  P11SEL &= ~BIT0;
  XT1_Stop();
  
  /* turn off the regulator */
  PMMCTL0_H = PMMPW_H;
  PMMCTL0_L = PMMREGOFF;
  __low_power_mode_4();
  __no_operation();
  __no_operation();
  
  /* should not get here without a power event */
  SoftwareReset();
}
Esempio n. 3
0
/* 80 us
 * 
 * conversion time = 13 * ADC12DIV *  1/FreqAdcClock
 * 13 * 8 * 1/5e6 = 20.8 us
 */
void BatterySenseCycle(void)
{ 
  static unsigned char Index = 0;

  xSemaphoreTake(AdcMutex, portMAX_DELAY);
  
  BATTERY_SENSE_ENABLE();
  ENABLE_REFERENCE();

  /* low_bat_en assertion to bat_sense valid is ~100 ns */
  /* Start battery sense conversion */
  AdcCheck();
  CLEAR_START_ADDR();
  ADC12CTL1 |= ADC12CSTARTADD_1;
  ENABLE_ADC();

  WaitForAdcBusy();

  /* Convert the ADC count for the battery input into a voltage 
   * ADC12MEM1: Counts Battery Voltage in ADC counts
   * Result: Battery voltage in millivolts */
  unsigned int Value = (unsigned int)(CONVERSION_FACTOR_BATTERY * (double)ADC12MEM1);

  if (ValidCalibration()) Value += GetBatteryCalibrationValue();

  /* smoothing algorithm: cut extreme values (gap > 20) */
  unsigned char Prev = (Index == 0) ? MAX_SAMPLES - 1: Index - 1;
  if (Sample[BATTERY][Prev])
  {
    int Gap = Value - Sample[BATTERY][Prev];
    if (Charging())
    {
      if (Gap > GAP_BIG) Gap = GAP_BIG;
      else if (Gap < GAP_SMALL_NEGATIVE) Gap = GAP_SMALL_NEGATIVE;
    }
    else
    {
      if (Gap > GAP_SMALL) Gap = GAP_SMALL;
      else if (Gap < GAP_BIG_NEGATIVE) Gap = GAP_BIG_NEGATIVE;
    }
    
    Sample[BATTERY][Index] = Sample[BATTERY][Prev] + Gap;
  }
  else Sample[BATTERY][Index] = Value;

  if (++Index >= MAX_SAMPLES) Index = 0;
  
  BATTERY_SENSE_DISABLE();
  EndAdcCycle(); //xSemaphoreGive()
}
Esempio n. 4
0
static void EnterShippingMode(void)
{
  /* Turn off the watchdog timer */
  WDTCTL = WDTPW | WDTHOLD;
  
  EnableRstPin();
  
  __delay_cycles(100000);
  
  __disable_interrupt();
  __no_operation();
  
  /* 
   * the radio draws more current in reset than it does after 
   * the patch is loaded
   */
  
  DISABLE_DISPLAY_POWER();
  DISABLE_LCD_ENABLE();
  BATTERY_CHARGE_DISABLE();
  LIGHT_SENSOR_SHUTDOWN();
  BATTERY_SENSE_DISABLE();
  HARDWARE_CFG_SENSE_DISABLE();
  APPLE_POWER_DISABLE();
  ACCELEROMETER_INT_DISABLE();
  DISABLE_BUTTONS();

  SELECT_ACLK(SELA__REFOCLK);                
  SELECT_FLLREF(SELREF__REFOCLK); 
  UCSCTL8 &= ~SMCLKREQEN;
  UCSCTL6 |= SMCLKOFF;
  /* disable aclk */
  P11SEL &= ~BIT0;
  XT1_Stop();
  
  /* turn off the regulator */
  unsigned char temp = PMMCTL0_L;
  PMMCTL0_H = PMMPW_H;
  PMMCTL0_L = PMMREGOFF | temp;
  LPM4;
  __no_operation();
  __no_operation();
  
  /* should not get here without a power event */
  SoftwareReset();
}