コード例 #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++;
}
コード例 #2
0
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
ファイル: potentiometer.c プロジェクト: morriemajor/mariokart
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);
    }
}
コード例 #4
0
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 ;
}