Esempio n. 1
0
	static void Setup(void)
	{
		HARDWARE_CFG_SENSE_INIT();
		AdcConversion<input, channel>::Config();
	}
Esempio n. 2
0
/*! Initialize the Analog-to-Digital Conversion peripheral.  Set the outputs from
 * the micro to the correct state.  The ADC is used to read the 
 * hardware configuration registers, the battery voltage, and the value from the
 * light sensor.
*/
void InitAdc(void)
{
  /* 
   * the internal voltage reference is not used ( AVcc is used )
   * reference is controlled by ADC12MCTLx register
   * 2.5 volt reference cannot be used because it requires external AVcc of 2.8
   * disable temperature sensor 
   */
  REFCTL0 = REFMSTR | REFTCOFF; 

  LIGHT_SENSE_INIT();
  BATTERY_SENSE_INIT();
  HARDWARE_CFG_SENSE_INIT();
 
  /* allow conditional request for modosc */
  UCSCTL8 |= MODOSCREQEN;
  
  /* select ADC12SC bit as sample and hold source (00) 
   * and use pulse mode
   * use modosc / 8 because frequency must be 0.45 MHz to 2.7 MHz (0.625 MHz)
   */
  ADC12CTL1 = ADC12CSTARTADD_0 + ADC12SHP + ADC12SSEL_0 + ADC12DIV_7; 

  /* 12 bit resolution, only use reference when doing a conversion */
  ADC12CTL2 = ADC12TCOFF + ADC12RES_2 + ADC12REFBURST;

  /* setup input channels */
  ADC12MCTL0 = HARDWARE_CFG_INPUT_CHANNEL + ADC12EOS;
  ADC12MCTL1 = BATTERY_SENSE_INPUT_CHANNEL + ADC12EOS;
  ADC12MCTL2 = LIGHT_SENSE_INPUT_CHANNEL + ADC12EOS;

  /* init to 0 */
  memset(Sample, 0, MAX_SAMPLES << 2);
  
  /* control access to adc peripheral */
  AdcMutex = xSemaphoreCreateMutex();
  xSemaphoreGive(AdcMutex);
  
  WarningLevel = DEFAULT_WARNING_LEVEL;
  RadioOffLevel = DEFAULT_RADIO_OFF_LEVEL;
  /*
   * A voltage divider on the board is populated differently
   * for each revision of the board.
   *
   * determine configuration at start-up
  */
  HARDWARE_CFG_SENSE_ENABLE();
  ENABLE_REFERENCE();

  /* Start Hardware Configuration Cycle */
  AdcCheck();

  /* setup the ADC channel */
  CLEAR_START_ADDR();
  ADC12CTL1 |= ADC12CSTARTADD_0;

  /* enable the ADC to start sampling and perform a conversion */
  ENABLE_ADC();
  WaitForAdcBusy();
  
  /* Finish HardwareConfiguration Cycle */
  /* Convert ADC counts to a voltage (truncates)
   * ADC12MEM0: Voltage in ADC counts
   * result: Voltage in millivolts * 10
   */
  unsigned int HwCfgVolt = (unsigned int)(CONVERSION_FACTOR * (double)ADC12MEM0);
  HARDWARE_CFG_SENSE_DISABLE();
  DISABLE_ADC();
  DISABLE_REFERENCE();
  
  BoardType = HW_CONFIG_NUM - 1;
  for (; BoardType; --BoardType) if (HwCfgVolt > HwConfig[BoardType]) break;

  ConfigureDefaultIO();
}