Exemplo n.º 1
0
void analogSensorsInit(void)
{

	// pin configuration for AirSpeed Sensor
	PINSEL_CFG_Type airPin_intStr;
	// pin configuration for UltraSonic Distance Sensor
	PINSEL_CFG_Type usonicPin_intStr;

	//Setup Air Speed Sensor Pin
	airPin_intStr.Funcnum   = AIR_PIN_FUNC;
	airPin_intStr.OpenDrain = PINSEL_PINMODE_NORMAL;
	airPin_intStr.Pinmode   = PINSEL_PINMODE_PULLUP;
	airPin_intStr.Pinnum    = AIR_PIN;
	airPin_intStr.Portnum   = AIR_PORT;
	PINSEL_ConfigPin(&airPin_intStr);

	//UltraSonic Sensor Pin
	usonicPin_intStr.Funcnum   = USON_PIN_FUNC;
	usonicPin_intStr.OpenDrain = PINSEL_PINMODE_NORMAL;
	usonicPin_intStr.Pinmode   = PINSEL_PINMODE_PULLUP;
	usonicPin_intStr.Pinnum    = USON_PIN;
	usonicPin_intStr.Portnum   = USON_PORT;
	PINSEL_ConfigPin(&usonicPin_intStr);

	// set AD Conversion speed
	ADC_Init(LPC_ADC, 200000);
	// disable the interrupt
	ADC_IntConfig (LPC_ADC, ADC_ADGINTEN, SET);
	// enable the ADC channels
	ADC_ChannelCmd(LPC_ADC, AIR_CHAN, ENABLE);
	ADC_ChannelCmd(LPC_ADC, USON_CHAN, ENABLE);
}
Exemplo n.º 2
0
char sampleADC(void)
{
    char res = 0x0;

    CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
    ADC_DeInit(ADC1);

    ADC_VrefintCmd(ENABLE);
    delay_10us(3);

    ADC_Cmd(ADC1, ENABLE);
    ADC_Init(ADC1, ADC_ConversionMode_Single,
             ADC_Resolution_6Bit, ADC_Prescaler_1);

    ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_9Cycles);
    ADC_ChannelCmd(ADC1, ADC_Channel_0, ENABLE);
    delay_10us(3);

    ADC_SoftwareStartConv(ADC1);
    while( ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == 0);
    res = (char)ADC_GetConversionValue(ADC1);

    ADC_VrefintCmd(DISABLE);
    ADC_DeInit(ADC1);

    /* disable SchmittTrigger for ADC_Channel_24, to save power */
    //ADC_SchmittTriggerConfig(ADC1, ADC_Channel_24, DISABLE);

    CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, DISABLE);
    ADC_ChannelCmd(ADC1, ADC_Channel_0, DISABLE);

    return res;
}
Exemplo n.º 3
0
int Get_ADC_Val(char* pin) {
  int channel, intChannel;
  if(pin == "P15") {
    channel = ADC_CHANNEL_0;
    intChannel = ADC_ADINTEN0;
  }
  else if(pin == "P16") {
    channel = ADC_CHANNEL_1;
    intChannel = ADC_ADINTEN1;
  }
  else if(pin == "P17") {
    channel = ADC_CHANNEL_2;
    intChannel = ADC_ADINTEN2;
  }
  else if(pin == "P18") {
    channel = ADC_CHANNEL_3;
    intChannel = ADC_ADINTEN3;
  }
  ADC_IntConfig(LPC_ADC, intChannel, DISABLE);
  ADC_ChannelCmd(LPC_ADC, channel, ENABLE);
  ADC_StartCmd(LPC_ADC, ADC_START_NOW);
  
  while(!(ADC_ChannelGetStatus(LPC_ADC, channel, ADC_DATA_DONE)));
  uint32_t adcVal= ADC_ChannelGetData(LPC_ADC, channel);

  ADC_ChannelCmd(LPC_ADC, channel, DISABLE);
  return (int) adcVal;
}
Exemplo n.º 4
0
uint16_t AnalogIn::readBits()
{
	ADC_ChannelCmd(LPC_ADC, channel, ENABLE);
	ADC_StartCmd(LPC_ADC, ADC_START_NOW);
	while(!(ADC_ChannelGetStatus(LPC_ADC, channel, ADC_DATA_DONE)));
	uint16_t bits = ADC_ChannelGetData(LPC_ADC, channel);
	ADC_ChannelCmd(LPC_ADC, channel, DISABLE);
	return bits;
}
Exemplo n.º 5
0
/**
  * @brief  Read ADC1
	* @caller several functions
  * @param None
  * @retval ADC value
  */ 
u16 ADC_Supply(void)
{
	uint8_t i;
	uint16_t res;

/* Enable ADC clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);

/* de-initialize ADC */
  ADC_DeInit(ADC1);

/*ADC configuration
  ADC configured as follow:
  - Channel VREF
  - Mode = Single ConversionMode(ContinuousConvMode disabled)
  - Resolution = 12Bit
  - Prescaler = /1
  - sampling time 9 */
  
  ADC_VrefintCmd(ENABLE);
  delay_10us(3);
  
  
  ADC_Cmd(ADC1, ENABLE);	 
  ADC_Init(ADC1, ADC_ConversionMode_Single,
  ADC_Resolution_12Bit, ADC_Prescaler_1);
  
  ADC_SamplingTimeConfig(ADC1, ADC_Group_FastChannels, ADC_SamplingTime_9Cycles);
  ADC_ChannelCmd(ADC1, ADC_Channel_Vrefint, ENABLE);
  delay_10us(3);

/* initialize result */
  res = 0;
  for(i=8; i>0; i--)
  {
/* start ADC convertion by software */
    ADC_SoftwareStartConv(ADC1);
/* wait until end-of-covertion */
    while( ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == 0 );
/* read ADC convertion result */
    res += ADC_GetConversionValue(ADC1);
  }
	
/* de-initialize ADC */
  ADC_VrefintCmd(DISABLE);

  ADC_DeInit(ADC1);
 
 /* disable SchmittTrigger for ADC_Channel_24, to save power */
  ADC_SchmittTriggerConfig(ADC1, ADC_Channel_24, DISABLE);
	
  CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, DISABLE);
  ADC_ChannelCmd(ADC1, ADC_Channel_Vrefint, DISABLE);
	
  return (res>>3);
}
Exemplo n.º 6
0
// Handle ADC interrupts
// NOTE: This could probably be less complicated...
void ADC_IRQHandler(void)
{
  elua_adc_dev_state *d = adc_get_dev_state( 0 );
  elua_adc_ch_state *s = d->ch_state[ d->seq_ctr ];
//int i;
  
  // Disable sampling & current sequence channel
  ADC_StartCmd( LPC_ADC, 0 );
  ADC_ChannelCmd( LPC_ADC, s->id, DISABLE );
  ADC_IntConfig( LPC_ADC, s->id, DISABLE );

  if ( ADC_ChannelGetStatus( LPC_ADC, s->id, ADC_DATA_DONE ) )
  { 
    d->sample_buf[ d->seq_ctr ] = ( u16 )ADC_ChannelGetData( LPC_ADC, s->id );
    s->value_fresh = 1;
            
    if ( s->logsmoothlen > 0 && s->smooth_ready == 0)
      adc_smooth_data( s->id );
#if defined( BUF_ENABLE_ADC )
    else if ( s->reqsamples > 1 )
    {
      buf_write( BUF_ID_ADC, s->id, ( t_buf_data* )s->value_ptr );
      s->value_fresh = 0;
    }
#endif
        
    if ( adc_samples_available( s->id ) >= s->reqsamples && s->freerunning == 0 )
      platform_adc_stop( s->id );      
  }
    
  // Set up for next channel acquisition if we're still running
  if( d->running == 1 )
  {
    // Prep next channel in sequence, if applicable
    if( d->seq_ctr < ( d->seq_len - 1 ) )
      d->seq_ctr++;
    else if( d->seq_ctr == ( d->seq_len - 1 ) )
    { 
      adc_update_dev_sequence( 0 );
      d->seq_ctr = 0; // reset sequence counter if on last sequence entry
    }
          
    ADC_ChannelCmd( LPC_ADC, d->ch_state[ d->seq_ctr ]->id, ENABLE );
    ADC_IntConfig( LPC_ADC, d->ch_state[ d->seq_ctr ]->id, ENABLE );
         
    if( d->clocked == 1  && d->seq_ctr == 0 ) // always use clock for first in clocked sequence
      ADC_StartCmd( LPC_ADC, adc_trig[ d->timer_id ] );

    // Start next conversion if unclocked or if clocked and sequence index > 0
    if( ( d->clocked == 1 && d->seq_ctr > 0 ) || d->clocked == 0 )
      ADC_StartCmd( LPC_ADC, ADC_START_NOW );
  }
}
Exemplo n.º 7
0
Arquivo: misc.cpp Projeto: Neon22/pixy
uint32_t adc_get(uint32_t channel)
{
	uint32_t res;

	ADC_ChannelCmd(LPC_ADC0, channel, ENABLE);
	delayus(500);
	ADC_StartCmd(LPC_ADC0, ADC_START_NOW);
	while (!(ADC_ChannelGetStatus(LPC_ADC0, channel, ADC_DATA_DONE)));
	res = ADC_ChannelGetData(LPC_ADC0, channel);
	ADC_ChannelCmd(LPC_ADC0, channel, DISABLE);

	return res;
}
Exemplo n.º 8
0
/**
  * @brief  Configure ADC peripheral 
  * @param  None
  * @retval None
  */
static void ADC_Config(void)
{
  /* Initialize and configure ADC1 */
  ADC_Init(ADC1, ADC_ConversionMode_Single, ADC_Resolution_12Bit, ADC_Prescaler_2);
  ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);
  ADC_SamplingTimeConfig(ADC1, ADC_Group_FastChannels, ADC_SamplingTime_384Cycles);

  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);

  /* Enable ADC1 Channels 3 */
  ADC_ChannelCmd(ADC1, ADC_Channel_3, ENABLE); /* connected to Potentiometer RV */
  /* Enable ADC1 Channels 24 */
  ADC_ChannelCmd(ADC1, ADC_Channel_24, ENABLE); /* connected to BNC */
}
Exemplo n.º 9
0
void ADC_Config(void)
{
	CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
	CLK_PeripheralClockConfig(CLK_Peripheral_DMA1, ENABLE);
	
	ADC_Init(ADC1, ADC_ConversionMode_Continuous, ADC_Resolution_12Bit, ADC_Prescaler_2);
	ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);
	ADC_Cmd(ADC1, ENABLE);
	
	ADC_ChannelCmd(ADC1, ADC_Channel_24, ENABLE); //设置ADC通道
	
	SYSCFG_REMAPDMAChannelConfig(REMAP_DMA1Channel_ADC1ToChannel0);
	
	DMA_Init(DMA1_Channel0, 
		BUFFER_ADDRESS,
		ADC1_DR_ADDRESS,
		BUFFER_SIZE,
		DMA_DIR_PeripheralToMemory,
		DMA_Mode_Circular,
		DMA_MemoryIncMode_Inc,
		DMA_Priority_High,
		DMA_MemoryDataSize_HalfWord);
	
	DMA_Cmd(DMA1_Channel0, ENABLE);
	DMA_ITConfig(DMA1_Channel0, DMA_ITx_TC, ENABLE);
	DMA_GlobalCmd(ENABLE);
}        
Exemplo n.º 10
0
int platform_adc_start_sequence()
{ 
  elua_adc_dev_state *d = adc_get_dev_state( 0 );
  
  if( d->running != 1 )
  {
    adc_update_dev_sequence( 0 );
    
    // Start sampling on first channel
    d->seq_ctr = 0;
    ADC_ChannelCmd( LPC_ADC, d->ch_state[ d->seq_ctr ]->id, ENABLE );
    ADC_IntConfig( LPC_ADC, d->ch_state[ d->seq_ctr ]->id, ENABLE );

    d->running = 1;
    NVIC_EnableIRQ( ADC_IRQn );
    
    if( d->clocked == 1 )
    {
      ADC_StartCmd( LPC_ADC, adc_trig[ d->timer_id ] );
      TIM_ResetCounter( tmr[ d->timer_id ] );
      TIM_Cmd( tmr[ d->timer_id ], ENABLE );
    }
    else
      ADC_StartCmd( LPC_ADC, ADC_START_NOW );
  }
  
  return PLATFORM_OK;
}
Exemplo n.º 11
0
/**
  * @brief ADC_Icc(ADC_24 of ADC_0~27) initialization
	* @caller main and ADC_Icc_Test
  * @param None
  * @retval None
  */ 
void ADC_Icc_Init(void)
{

/* Enable ADC clock */
  CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);

/* de-initialize ADC */
  ADC_DeInit(ADC1);
	
/*  ADC configured as follow:
  - NbrOfChannel = 1 - ADC_Channel_24
  - Mode = Single ConversionMode(ContinuousConvMode disabled)
  - Resolution = 12Bit
  - Prescaler = /1
  - sampling time 159 */
	
/* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);
  ADC_Init(ADC1, ADC_ConversionMode_Single,ADC_Resolution_12Bit, ADC_Prescaler_1);

  ADC_SamplingTimeConfig(ADC1, ADC_Group_FastChannels, ADC_SamplingTime_9Cycles);
  ADC_ChannelCmd(ADC1, ADC_Channel_24, ENABLE);

/* disable SchmittTrigger for ADC_Channel_24, to save power */
  ADC_SchmittTriggerConfig(ADC1, ADC_Channel_24, DISABLE);

/* a short time of delay is required after enable ADC */
  delay_10us(3);
	
}
Exemplo n.º 12
0
/**
  * @brief  Configure ADC and Analog watchdog
  * @param  None
  * @retval None
  */
static void ADC_Config(void)
{
    /* Enable ADC1 clock */
    CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);

    /* Initialise and configure ADC1 */
    ADC_Init(ADC1, ADC_ConversionMode_Continuous, ADC_Resolution_12Bit, ADC_Prescaler_2);
    ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);

    /* Enable ADC1 */
    ADC_Cmd(ADC1, ENABLE);

    /* Enable ADC1 Channel 3 */
    ADC_ChannelCmd(ADC1, ADC_Channel_3, ENABLE);

    /* Calculate Threshold data value*/
    HighThresholdData = (uint16_t)(((uint32_t)HIGH_THRESHOLD_VOLTAGE * 1000) / (uint32_t)ADC_RATIO) ;
    LowThresholdData  = (uint16_t)(((uint32_t)LOW_THRESHOLD_VOLTAGE * 1000) / (uint32_t)ADC_RATIO) ;

    /* Configure Analog Watchdog selected channel and Thresholds */
    ADC_AnalogWatchdogConfig(ADC1, ADC_AnalogWatchdogSelection_Channel3,
                             HighThresholdData,
                             LowThresholdData);

    /* Enable Analog watchdog ADC1 Interrupt */
    ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);

    /* Enable Interrupts */
    enableInterrupts();

    /* Start ADC1 Conversion using Software trigger*/
    ADC_SoftwareStartConv(ADC1);
}
Exemplo n.º 13
0
/*********************************************************************//**
 * @brief       c_entry: Main ADC program body
 * @param[in]   None
 * @return      None
 **********************************************************************/
void c_entry(void)
{
    volatile uint32_t adc_value, tmp;
    uint8_t  quit;

    /* Initialize debug via UART0
     * – 115200bps
     * – 8 data bit
     * – No parity
     * – 1 stop bit
     * – No flow control
     */
    debug_frmwrk_init();

    // print welcome screen
    print_menu();

    /* Initialize ADC ----------------------------------------------------*/
    /*
     * Init ADC pin that currently is being used on the board
     */
    PINSEL_ConfigPin (BRD_ADC_PREPARED_CH_PORT, BRD_ADC_PREPARED_CH_PIN, BRD_ADC_PREPARED_CH_FUNC_NO);
    PINSEL_SetAnalogPinMode(BRD_ADC_PREPARED_CH_PORT,BRD_ADC_PREPARED_CH_PIN,ENABLE);

    /* Configuration for ADC :
     *  ADC conversion rate = 400Khz
     */
    ADC_Init(LPC_ADC, 400000);

    ADC_IntConfig(LPC_ADC, BRD_ADC_PREPARED_INTR, DISABLE);
    ADC_ChannelCmd(LPC_ADC, BRD_ADC_PREPARED_CHANNEL, ENABLE);

    while(1)
    {
        // Start conversion
        ADC_StartCmd(LPC_ADC, ADC_START_NOW);

        //Wait conversion complete
        while (!(ADC_ChannelGetStatus(LPC_ADC, BRD_ADC_PREPARED_CHANNEL, ADC_DATA_DONE)));

        adc_value = ADC_ChannelGetData(LPC_ADC, BRD_ADC_PREPARED_CHANNEL);

        //Display the result of conversion on the UART

        _DBG("ADC value on channel "); _DBD(BRD_ADC_PREPARED_CHANNEL);

        _DBG(" is: "); _DBD32(adc_value); _DBG_("");

        //delay
        for(tmp = 0; tmp < 1000000; tmp++);
        if(_DG_NONBLOCK(&quit) &&
            (quit == 'Q' || quit == 'q'))
            break;
    }
    _DBG_("Demo termination!!!");

    ADC_DeInit(LPC_ADC);

}
Exemplo n.º 14
0
/*
 * Configure the pins according to their intended default function
 */
int _roboveroConfig(uint8_t * args)
{
    int i;
    UART_CFG_Type UARTConfigStruct;
    PWM_TIMERCFG_Type PWMCfgDat;

    configAllPins();

    /*
     * Enable 7 analog inputs
     */
    ADC_Init(LPC_ADC, 200000);
    for (i = 0; i < 4; i++)
    		ADC_ChannelCmd(LPC_ADC, i, ENABLE); 
    for (i = 5; i < 8; i++)
        ADC_ChannelCmd(LPC_ADC, i, ENABLE);
    /*
     * Configure I2C0 for IMU communications
     */
    I2C_Init(LPC_I2C0, 100000);
    I2C_Cmd(LPC_I2C0, ENABLE);

    /*
     * Initialize CAN bus
     */
    CAN_Init(LPC_CAN1, 100000);

    /*
     * Initialize UART1 
     */
    UART_ConfigStructInit(&UARTConfigStruct);
    UARTConfigStruct.Baud_rate = 115200;
    UART_Init((LPC_UART_TypeDef*)LPC_UART1, &UARTConfigStruct);
    UART_TxCmd((LPC_UART_TypeDef*)LPC_UART1, ENABLE);

    /*
     * Initialize PWM
     *
     * Peripheral clock is 30MHz. Prescale by 30 cycles for 1us resolution.
     */    
    PWMCfgDat.PrescaleOption = PWM_TIMER_PRESCALE_TICKVAL;
    PWMCfgDat.PrescaleValue = 30;
    PWM_Init(LPC_PWM1, PWM_MODE_TIMER, &PWMCfgDat);

    return 0;
}
Exemplo n.º 15
0
// FIXME: de qAnalogInit is not really necessary, but without it consecutive readings are faulty (the second one is corrupted)
//        Maybe a BURST mode is preferible in this case but only 2 analogs are beign used right now.
uint16_t qAnalog_Read(qAnalogInput * q){

	uint16_t ret;
	qAnalog_Init();
	ADC_ChannelCmd(LPC_ADC,q->adcChannel,ENABLE);

	ADC_StartCmd(LPC_ADC,ADC_START_NOW);

	//Wait conversion complete
	while (!(ADC_ChannelGetStatus(LPC_ADC,q->adcChannel,ADC_DATA_DONE)));
	ret = ADC_ChannelGetData(LPC_ADC,q->adcChannel);

	ADC_ChannelCmd(LPC_ADC,q->adcChannel,DISABLE);

	return ret;

}
Exemplo n.º 16
0
void EINT3_IRQHandler(void)
{
	  if (GPIO_GetIntStatus(1, 10, 1))
	  {
		  GPIO_ClearInt(2,(1<<10));
		  toggle=~toggle;
#ifdef MCB_LPC_1768_ADC_BURST_MULTI
		  if(toggle)
		  {
			  ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_3,ENABLE);
			  FIO_ByteSetValue(1, 3, POLL_LED);
		  }
		  else
		  {
			  ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_3,DISABLE);
			  FIO_ByteClearValue(1, 3, POLL_LED);
		  }
#endif
	  }
}
Exemplo n.º 17
0
/******************************************************************************
 *
 * Description:
 *   Initialize the trim potentiometer, i.e. ADC connected to TrimPot on
 *   Base Board.
 *
 *****************************************************************************/
void trimpot_init(void)
{
  // pinsel for AD0.2 on p0.25
	PINSEL_ConfigPin (0, 25, 1);
  PINSEL_SetAnalogPinMode (0, 25, 1);

  ADC_Init(LPC_ADC, 400000);

	ADC_IntConfig(LPC_ADC, ADC_ADINTEN2, DISABLE);
	ADC_ChannelCmd(LPC_ADC, ADC_CH_TRIMPOT, ENABLE);
}
Exemplo n.º 18
0
/**
  * @brief  Configure ADC peripheral
  * @param  None
  * @retval None
  */
static void ADC_Config(void)
{
  /* Initialise and configure ADC1 */
  ADC_Init(ADC1, ADC_ConversionMode_Continuous, ADC_Resolution_12Bit, ADC_Prescaler_2);
  ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);

  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);

  /* Enable ADC1 Channels 3 */
  ADC_ChannelCmd(ADC1, ADC_Channel_3, ENABLE); /* connected to potentiometer */
}
Exemplo n.º 19
0
void ADC_InitChannel(int i){
  PINSEL_CFG_Type pinCfg;
    pinCfg.Funcnum = 1;
    pinCfg.OpenDrain = 0;
    pinCfg.Pinmode = 0;
    pinCfg.Portnum = 0;
    pinCfg.Pinnum = 23 + i;
    PINSEL_ConfigPin(&pinCfg);
  ADC_Init(LPC_ADC, 200000);
    ADC_IntConfig(LPC_ADC, i, DISABLE);
    ADC_ChannelCmd(LPC_ADC, i, ENABLE);
}
Exemplo n.º 20
0
void init_adc(void) {
    PINSEL_CFG_Type PinCfg; 

    PinCfg.Funcnum = 1;
    PinCfg.OpenDrain = 0;
    PinCfg.Pinmode = PINSEL_PINMODE_PULLUP;
    PinCfg.Pinnum = 24;
    PinCfg.Portnum = 0;
    PINSEL_ConfigPin(&PinCfg);

    ADC_Init(LPC_ADC, 10000);
    ADC_IntConfig(LPC_ADC, ADC_ADINTEN0, DISABLE);
    ADC_ChannelCmd(LPC_ADC, ADC_CHANNEL_1, ENABLE);
}
Exemplo n.º 21
0
/*
 -Pre-Reqs: None
 -Desc: Initalise ADC at pin 30, mbed pin 19
 -Input: None
 -Output: None
 -*/
void setupADC(){
    //Setup for channel 0
    PINSEL_CFG_Type ADCPinCfg;
    ADCPinCfg.Funcnum = 3;
    ADCPinCfg.OpenDrain = 0;
    ADCPinCfg.Pinmode = 0;
    ADCPinCfg.Pinnum = 30;
    ADCPinCfg.Portnum = 1;
    PINSEL_ConfigPin(&ADCPinCfg);

    ADC_Init(LPC_ADC,100);
    ADC_ChannelCmd(LPC_ADC,4,ENABLE);
	ADC_StartCmd(LPC_ADC,ADC_START_NOW);
}
/*********************************************************************//**
 * @brief		Print menu
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void EINT0_IRQHandler(void)
{
	EXTI_ClearEXTIFlag(EXTI_EINT0);

	toggle = ((toggle == TRUE) ? FALSE:TRUE);

#ifdef LPC177x_8x_ADC_BURST_MULTI
	if(toggle)
	{
		ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_n,ENABLE);

		//Turn on LED -> indicate that extended channel was enable
		GPIO_ClearValue(LED_PORT, LED_PIN);
	}
	else
	{
		ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_n,DISABLE);

		// Turn off LED ->indicate that extended channel was disable
		GPIO_SetValue(LED_PORT, LED_PIN);
	}
#endif
}
Exemplo n.º 23
0
/**
 * @brief Main Program body
 */
int c_entry(void)
{
	PINSEL_CFG_Type PinCfg;
	uint32_t adc_value;

	/*
	 * Initialize debug via UART
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/*
	 * Init ADC pin connect
	 * AD0.2 on P0.25
	 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 25;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);

	/* Configuration for ADC :
	 * 	Frequency at 1Mhz
	 *  ADC channel 2, no Interrupt
	 */
	ADC_Init(LPC_ADC, 1000000);
	ADC_IntConfig(LPC_ADC,ADC_ADINTEN2,DISABLE);
	ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_2,ENABLE);

	while(1)
	{
		// Start conversion
		ADC_StartCmd(LPC_ADC,ADC_START_NOW);
		//Wait conversion complete
		while (!(ADC_ChannelGetStatus(LPC_ADC,ADC_CHANNEL_2,ADC_DATA_DONE)));
		adc_value = ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_2);
		//Display the result of conversion on the UART0
		_DBG("ADC value on channel 2: ");
		_DBD32(adc_value);
		_DBG_("");
		//delay 1s
		Timer_Wait(1000);
	}
	ADC_DeInit(LPC_ADC);
	return 1;
}
Exemplo n.º 24
0
/**
  * @brief  Configure ADC peripheral 
  * @param  None
  * @retval None
  */
static void ADC_Config(void)
{
  /* Initialise and configure ADC1 */
  ADC_Init(ADC1, ADC_ConversionMode_Continuous, ADC_Resolution_12Bit, ADC_Prescaler_1);

  /* Configure ADC1 to measure the analog voltage available on slow channels */
  /* Slow channel group configuration: Channel 22 (PD0) */
  ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_192Cycles);

  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);

  /* Enable ADC1 Channel 22: PD0 */
  ADC_ChannelCmd(ADC1, ADC_Channel_22, ENABLE);
}
Exemplo n.º 25
0
/**
  * @brief  Configure ADC peripheral
  * @param  None
  * @retval None
  */
static void ADC_Config(void)
{
    /* Initialise and configure ADC1 */
    ADC_Init(ADC1, ADC_ConversionMode_Continuous, ADC_Resolution_12Bit, ADC_Prescaler_2);
    ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);

    /* Enable ADC1 */
    ADC_Cmd(ADC1, ENABLE);

    /* Enable ADC1 Channel 3 */
    ADC_ChannelCmd(ADC1, ADC_Channel_5, ENABLE);

    /* Enable End of conversion ADC1 Interrupt */
    //ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
}
Exemplo n.º 26
0
void ADC_init()
{
	PINSEL_CFG_Type PinCfg;
 
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Funcnum = 3;
	PinCfg.Portnum = 1;
	PinCfg.Pinnum = 30;
	PINSEL_ConfigPin(&PinCfg);
	
	ADC_Init(LPC_ADC, 20000);
	ADC_ChannelCmd(LPC_ADC, 4, ENABLE);
	
	ADC_ChannelGetData(LPC_ADC, 4);
}
Exemplo n.º 27
0
static void platform_setup_adcs()
{
  unsigned id;
  
  for( id = 0; id < NUM_ADC; id ++ )
    adc_init_ch_state( id );
  
  NVIC_SetPriority(ADC_IRQn, ((0x01<<3)|0x01));

  ADC_Init(LPC_ADC, 13000000);
  
  // Default enables CH0, disable channel
  ADC_ChannelCmd( LPC_ADC, 0, DISABLE );
  
  // Default enables ADC interrupt only on global, switch to per-channel
  ADC_IntConfig( LPC_ADC, ADC_ADGINTEN, DISABLE );
    
  platform_adc_set_clock( 0, 0 );
}
Exemplo n.º 28
0
int _analogReadAll(uint8_t * args)
{
	uint8_t start_mode = 1; //Start now
	uint8_t adc_data_done = 1; //Data_done
	int pin[]={0,2,3};
	int n,nb_pin=3;
	unsigned int adc_values[3];


	for(n=0;n<nb_pin;n++)
	{
		ADC_Init(LPC_ADC, 200000);
		ADC_ChannelCmd(LPC_ADC, pin[n], ENABLE);
		ADC_StartCmd(LPC_ADC, start_mode);
		while( ! ADC_ChannelGetStatus(LPC_ADC, pin[n], adc_data_done))
			{;}
		adc_values[n]= ADC_ChannelGetData(LPC_ADC, pin[n]);
	}
	sprintf( (char*) str, "%x %x %x\r\n", adc_values[0], adc_values[1], adc_values[2]);
	writeUSBOutString(str);

	return 0;
}
Exemplo n.º 29
0
uint16_t getADC(int channel)
{
	uint16_t adc_value;
	uint16_t adc_value1;
	uint16_t adc_value2;

	// Start conversion
	ADC_StartCmd(LPC_ADC,ADC_START_NOW);
	//Wait conversion complete
	ADC_IntConfig(LPC_ADC,ADC_ADINTEN2,RESET);
	ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_2,ENABLE);
	while (!(ADC_ChannelGetStatus(LPC_ADC,ADC_CHANNEL_2,ADC_DATA_DONE)));
	adc_value = ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_2);
	ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_2,DISABLE);

	ADC_IntConfig(LPC_ADC,ADC_ADINTEN1,RESET);
	ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_1,ENABLE);
	while (!(ADC_ChannelGetStatus(LPC_ADC,ADC_CHANNEL_1,ADC_DATA_DONE)));
	adc_value1 = ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_1);
	ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_1,DISABLE);

	ADC_IntConfig(LPC_ADC,ADC_ADINTEN0,RESET);
	ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_0,ENABLE);
	while (!(ADC_ChannelGetStatus(LPC_ADC,ADC_CHANNEL_0,ADC_DATA_DONE)));
	adc_value2 = ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_0);
	ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_0,DISABLE);

	if (channel == 0)
	{
		return adc_value;
	}
	if (channel == 1)
	{
		return adc_value1;
	}
	if (channel == 2)
	{
		return adc_value2;
	}
	else
	{
		return 0;
	}
}
/*********************************************************************//**
 * @brief		c_entry: Main program body
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void c_entry (void)
{
	EXTI_InitTypeDef EXTICfg;
	
	GPIO_Init();

	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	PINSEL_ConfigPin(2, 10,1);

	ADC_Init(LPC_ADC, 100);
	ADC_IntConfig(LPC_ADC, BRD_ADC_PREPARED_INTR, ENABLE);
	ADC_ChannelCmd(LPC_ADC, BRD_ADC_PREPARED_CHANNEL, ENABLE);

	GPIO_SetDir(BRD_LED_1_CONNECTED_PORT, BRD_LED_1_CONNECTED_MASK, GPIO_DIRECTION_OUTPUT);
	GPIO_SetDir(BRD_LED_2_CONNECTED_PORT, BRD_LED_2_CONNECTED_MASK, GPIO_DIRECTION_OUTPUT);

	/* Initialize External 0 interrupt */
	EXTI_Init();

	EXTICfg.EXTI_Line = EXTI_EINT0;
	/* edge sensitive */
	EXTICfg.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE;
	EXTICfg.EXTI_polarity = EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE;

	EXTI_Config(&EXTICfg);

#if (INT_MODE == 0) //same group, different sub-levels (Tail-chaining example)
	//sets group priorities: 8 - subpriorities: 3
	NVIC_SetPriorityGrouping(4);

	//000:10 (bit 7:3)  assign eint0 to group 0, sub-priority 2 within group 0
	NVIC_SetPriority(EINT0_IRQn, 2);

	NVIC_SetPriority(ADC_IRQn, 0x01);
#else //different group - (Late-arriving example)  ==================================================
	//sets group priorities: 8 - subpriorities: 3
	NVIC_SetPriorityGrouping(4);

	//000:00 (bit 7:3) assign eint0 to group 0, sub-priority 0 within group 0
	NVIC_SetPriority(EINT0_IRQn, 0);

	NVIC_SetPriority(ADC_IRQn, 0x04);
#endif

	NVIC_EnableIRQ(EINT0_IRQn);

	/* Enable ADC in NVIC */
	NVIC_EnableIRQ(ADC_IRQn);

	while(1)
	{
		// Start conversion
		ADC_StartCmd(LPC_ADC, ADC_START_NOW);

		/* Enable ADC in NVIC */
		NVIC_EnableIRQ(ADC_IRQn);
	}
}