示例#1
0
void UpdateAnalogs(void)
{
	ADC_StartConversion(AT91C_BASE_ADC1);
	while((ADC_GetStatus(AT91C_BASE_ADC1) & 0x80) != 0x80) nop();
	//g_AnalogReading[0] = ADC_GetConvertedData(AT91C_BASE_ADC1,0);
	g_AnalogReading[1] = ADC_GetConvertedData(AT91C_BASE_ADC1,1);
	g_AnalogReading[2] = ADC_GetConvertedData(AT91C_BASE_ADC1,2);
	g_AnalogReading[3] = ADC_GetConvertedData(AT91C_BASE_ADC1,3);
	g_AnalogReading[4] = ADC_GetConvertedData(AT91C_BASE_ADC1,4);
	g_AnalogReading[5] = ADC_GetConvertedData(AT91C_BASE_ADC1,5);
	g_AnalogReading[6] = ADC_GetConvertedData(AT91C_BASE_ADC1,6);
	g_AnalogReading[7] = ADC_GetConvertedData(AT91C_BASE_ADC1,7);
	
	
	switch(g_BatteryCounter) {
		case 0:
			g_AnalogReading[0] = ADC_GetConvertedData(AT91C_BASE_ADC1, 0);
			SelectBattV();
			break;
		case 1:
		  CalculateBatteryPower(ADC_GetConvertedData(AT91C_BASE_ADC1, 0));
			SelectAng0();
			break;
		case BATTV_PERIOD:
			g_BatteryCounter = -1;
		default:
			g_AnalogReading[0] = ADC_GetConvertedData(AT91C_BASE_ADC1, 0);
	}
	g_BatteryCounter++;
}
void ADC_IrqHandler(void)
{
    Adc *pAdc = ADC;
    int32_t  dwLowPotThreshold, dwHighPotThreshold;
    volatile uint32_t dummy = 0;

    /* Read the status to ack the IT */
    dummy = ADC_GetStatus(ADC);

    /* Get the potentiometer initial value */
    gdwPotentiometerValue = ADC_GetConvertedData(pAdc, ADC_CHANNEL_5);

    /* Read LCDR to clear DRDY bit */
    dummy = ADC_GetLastConvertedData(pAdc);

    /* Set Window threshold according to the initial values */
    dwLowPotThreshold  = gdwPotentiometerValue - (NB_INTERVALS * (0x1000 / 256));
    if (dwLowPotThreshold < 0)
        dwLowPotThreshold = 0;
    dwHighPotThreshold = gdwPotentiometerValue + (NB_INTERVALS * (0x1000 / 256));
    if (dwHighPotThreshold >= 0x1000)
        dwHighPotThreshold = 0x1000 - 1;

    /* Normalize the value 0 -> 255 */
    gdwPotentiometerValue = (gdwPotentiometerValue * 256) / 0xFFF;

    /* Post Message */
    WGT_SendMessageISR( WGT_MSG_KEY_PRESSED, WGT_KEY_VR1, 255 - gdwPotentiometerValue ) ;

    /* Setup Threshold*/
    ADC_SetComparisonWindow(pAdc,((dwHighPotThreshold<<16)|dwLowPotThreshold));

}
示例#3
0
static void ISR_ADC(void) {
    int status = ADC_GetStatus(AT91C_BASE_ADC);

    char_display_number(33);

    if (ADC_IsChannelInterruptStatusSet(status, POT_CHANNEL)) {

        //gets the new value from ADC
        pot_current_value = ADC_GetConvertedData(AT91C_BASE_ADC, POT_CHANNEL);

        char_display_number((pot_current_value - 25) / 10);
        //char_display_number(44);

        //starts the converter running again
        ADC_StartConversion(AT91C_BASE_ADC);
    }
}
/**
  * @brief  Checks whether the specified ADC1 Status flag is set or not.
  * @param  Flag: specifies the flag to check.
  *         This parameter can be one of the following values:
  *           @arg ADC1_FLAG_OVERWRITE:         the previous ADC1 measured value was overwritten;
  *           @arg ADC1_FLAG_OUT_OF_RANGE:      the ADC1 measured value is out of range;
  *           @arg ADC1_FLAG_END_OF_CONVERSION: the ADC1 conversion finished;
  * @retval Current Status flag state (SET or RESET).
  */
FlagStatus ADC_GetFlagStatus(uint32_t Flag)
{
  FlagStatus bitstatus;

  /* Check the parameters */
  assert_param(IS_ADC_STATUS_FLAG(Flag));

  if ((ADC_GetStatus() & Flag) == 0)
  {
    bitstatus = RESET;
  }
  else
  {
    bitstatus = SET;
  }

  return bitstatus;
}
/**
  * @brief  Checks whether the ADC1 interrupt has occurred or not.
  * @param  ADC_IT: specifies the ADC interrupt source to check.
  *         This parameter can be one of the following values:
  *           @arg ADC1_IT_OUT_OF_RANGE:        the ADC1 measured value is out of range;
  *           @arg ADC1_IT_END_OF_CONVERSION:   the ADC1 conversion finished;
  * @retval The new state of the ADC_IT (SET or RESET).
  */
ITStatus ADC_GetITStatus(uint32_t ADC_IT)
{
  ITStatus bitstatus;
  uint32_t tmpreg;

  /* Check the parameters */
  assert_param(IS_ADC_CONFIG_IT(ADC_IT));

  tmpreg = ADC_GetStatus();
  tmpreg &= (tmpreg >> 2) & ADC_IT;

  if (tmpreg == 0)
  {
    bitstatus = RESET;
  }
  else
  {
    bitstatus = SET;
  }

  return bitstatus;
}
示例#6
0
//-----------------------------------------------------------------------------
/// Test if ADC Status is Set
/// \param pAdc Pointer to an AT91S_ADC instance.
/// \param flag flag to be tested
/// \return 1 if the staus is set; 0 otherwise
//-----------------------------------------------------------------------------
unsigned int ADC_IsStatusSet(AT91S_ADC *pAdc, unsigned int flag)
{
    return (ADC_GetStatus(pAdc) & flag);
}
static uint32_t _WFE_Potentiometer_Initialize( void )
{
    Adc *pAdc = ADC;
    int32_t  dwLowPotThreshold, dwHighPotThreshold;

    /* STEP1: Realize a first measure to get potentiometer's initial position */
    /* Initialize ADC*/
    ADC_Initialize( pAdc,ID_ADC, ADC_MR_TRGEN_DIS,/*HARDWARE trigger*/
            0,ADC_MR_SLEEP_NORMAL,ADC_MR_LOWRES_12_BIT,
            BOARD_MCK,BOARD_ADC_FREQ,10,20);

    /*Enable  channel 5 (potentiometer) */
    ADC_EnableChannel(pAdc, ADC_CHANNEL_5);

    /* Start convrsion */
    ADC_StartConversion(pAdc);

    /* Wait for the end of conversion */
    while ( !(ADC_GetStatus(pAdc) & ADC_ISR_EOC5) ) {}

    /* Get the potentiometer initial value */
    gdwPotentiometerValue = ADC_GetConvertedData(pAdc, ADC_CHANNEL_5);

    /* Set Window threshold according to the initial values */
    dwLowPotThreshold  = gdwPotentiometerValue - (NB_INTERVALS * (0x1000 / 256));
    if (dwLowPotThreshold < 0)
        dwLowPotThreshold = 0;
    dwHighPotThreshold = gdwPotentiometerValue + (NB_INTERVALS * (0x1000 / 256));
    if (dwHighPotThreshold >= 0x1000)
        dwHighPotThreshold = 0x1000 - 1;

    /* Normalize the value 0 -> 255 */
    gdwPotentiometerValue = (gdwPotentiometerValue * 256) / 0xFFF;

    /* STEP2: Re configure ADC to use windowing */
    /* Initialize ADC*/
    ADC_Initialize( pAdc,ID_ADC, ADC_MR_TRGEN_EN,/*HARDWARE trigger*/
            ADC_MR_TRGSEL_ADC_TRIG0,ADC_MR_SLEEP_NORMAL,ADC_MR_LOWRES_12_BIT,
            BOARD_MCK,BOARD_ADC_FREQ,10,20);

    /*Enable  channel 5 (potentiometer) */
    ADC_EnableChannel(pAdc, ADC_CHANNEL_5);

    /* Configure TC*/
    ConfigureTc0();

    /*Channel 5 has to be compared*/
    ADC_SetCompareChannel(pAdc, ADC_CHANNEL_5);
    /*Compare mode, in the window*/
    ADC_SetCompareMode(pAdc, ADC_EMR_CMPMODE_OUT);

    /* Setup Threshold*/
    ADC_SetComparisonWindow(pAdc,((dwHighPotThreshold<<16)|dwLowPotThreshold));

    /* enable adc interrupt*/
    NVIC_EnableIRQ(ADC_IRQn);

    /* Enable Compare Interrupt*/
    ADC_EnableIt(pAdc, ADC_IDR_COMPE);

    /* Start TC0 and hardware trigger*/
    TC_Start(TC0,0);

    return SAMGUI_E_OK ;
}