static uint16_t readADC(uint8_t id) { uint16_t dataADC; uint16_t first; Chip_ADC_EnableChannel(LPC_ADC, id, ENABLE); Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING); /* Waiting for A/D conversion complete */ while (Chip_ADC_ReadStatus(LPC_ADC, id, ADC_DR_DONE_STAT) != SET) {} /* Read ADC value */ Chip_ADC_ReadValue(LPC_ADC, id, &first); Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING); /* Waiting for A/D conversion complete */ while (Chip_ADC_ReadStatus(LPC_ADC, id, ADC_DR_DONE_STAT) != SET) {} /* Read ADC value */ Chip_ADC_ReadValue(LPC_ADC, id, &dataADC); int32_t diff = first - dataADC; if(diff < 0 ) diff = -diff; while(diff > 200) { first = dataADC; Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING); /* Waiting for A/D conversion complete */ while (Chip_ADC_ReadStatus(LPC_ADC, id, ADC_DR_DONE_STAT) != SET) {} /* Read ADC value */ Chip_ADC_ReadValue(LPC_ADC, id, &dataADC); diff = first - dataADC; if(diff < 0 ) diff = -diff; } Chip_ADC_EnableChannel(LPC_ADC, id, DISABLE); return dataADC; }
void adc_read(uint8_t channel, uint16_t *data) { Chip_ADC_EnableChannel(LPC_ADC, (ADC_CHANNEL_T)channel, ENABLE); /* Start A/D conversion */ Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING); /* Waiting for A/D conversion complete */ while (Chip_ADC_ReadStatus(LPC_ADC, (ADC_CHANNEL_T)channel, ADC_DR_DONE_STAT) != SET); /* Read ADC value */ Chip_ADC_ReadValue(LPC_ADC, channel, data); Chip_ADC_EnableChannel(LPC_ADC, (ADC_CHANNEL_T)channel, DISABLE); }
uint16_t Board_TPS_2_ADC_Read(uint16_t *adc_data) { /* Enable this channel and disable all others (because burst mode not enabled) */ Chip_ADC_EnableChannel(LPC_ADC, ADC_CH0, DISABLE); Chip_ADC_EnableChannel(LPC_ADC, ADC_CH1, ENABLE); /* Start A/D conversion */ Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING); /* Waiting for A/D conversion complete */ while (!Chip_ADC_ReadStatus(LPC_ADC, ADC_CH1, ADC_DR_DONE_STAT)) {} /* Read ADC value */ Chip_ADC_ReadValue(LPC_ADC, ADC_CH1, adc_data); }
/* * @brief Get the value of one ADC channel. Mode: BLOCKING * @param AI0 ... AIn * @return analog value */ uint16_t analogRead( uint8_t analogInput ){ uint8_t lpcAdcChannel = 49 - analogInput; uint16_t analogValue = 0; Chip_ADC_EnableChannel(LPC_ADC0, lpcAdcChannel, ENABLE); Chip_ADC_SetStartMode(LPC_ADC0, ADC_START_NOW, ADC_TRIGGERMODE_RISING); while( (Chip_ADC_ReadStatus(LPC_ADC0, lpcAdcChannel, ADC_DR_DONE_STAT) != SET) ); Chip_ADC_ReadValue( LPC_ADC0, lpcAdcChannel, &analogValue ); Chip_ADC_EnableChannel( LPC_ADC0, lpcAdcChannel, DISABLE ); return analogValue; }
int main(void) { //preparing the chip & board SystemCoreClockUpdate(); Board_Init(); PWM_Init(); PWM_SetCycle(400,1000); //the actual code Chip_ADC_Init(_LPC_ADC_ID, &ADCSetup); Chip_ADC_EnableChannel(_LPC_ADC_ID, _ADC_CHANNLE, ENABLE); Chip_ADC_SetBurstCmd(_LPC_ADC_ID, ENABLE); //int i; SysTick_Config(SystemCoreClock / TICKRATE_HZ1); while(1) { __WFI(); /* if(rotation_counter==MEMORY_CAPACITY){ //not rotation_cycle? for(i=0;i<MEMORY_CAPACITY;i++){ DEBUGOUT("%d \n",rotation_debug_holder[i]);//,rotation_debug_holder2[i]); } rotation_counter++; } */ } return 0 ; }
/** * @brief main routine for ADC example * @return Function should not exit */ int main(void) { uint16_t dataADC; int j; SystemCoreClockUpdate(); Board_Init(); Init_ADC_PinMux(); DEBUGSTR("ADC Demo\r\n"); /* ADC Init */ Chip_ADC_Init(LPC_ADC, &ADCSetup); Chip_ADC_EnableChannel(LPC_ADC, ADC_CH0, ENABLE); while (1) { /* Start A/D conversion */ Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING); /* Waiting for A/D conversion complete */ while (Chip_ADC_ReadStatus(LPC_ADC, ADC_CH0, ADC_DR_DONE_STAT) != SET) {} /* Read ADC value */ Chip_ADC_ReadValue(LPC_ADC, ADC_CH0, &dataADC); /* Print ADC value */ DEBUGOUT("ADC value is 0x%x\r\n", dataADC); /* Delay */ j = 500000; while (j--) {} } /* Should not run to here */ return 0; }
void InicializarADC() { Chip_SCU_ADC_Channel_Config(ADC0,CANAL1); //adc_18xx_43xx.h”: Chip_ADC_Init(LPC_ADC0, &configclock ); Chip_ADC_EnableChannel(LPC_ADC0, ADC_CH1, ENABLE); Chip_ADC_SetStartMode(LPC_ADC0, ADC_START_NOW, ADC_TRIGGERMODE_RISING); //Chip_ADC_ReadStatus(LPC_ADC_T *pADC, uint8_t channel, uint32_t StatusType); }
void InicializarADC(void) { /* perform the needed initialization here */ ADC_CLOCK_SETUP_T ADCSetup; Chip_SCU_ADC_Channel_Config(0,ADC_CH1); Chip_ADC_Init(LPC_ADC0, &ADCSetup ); Chip_ADC_EnableChannel(LPC_ADC0, ADC_CH1,ENABLE); };
void InitADC() { Chip_SCU_ADC_Channel_Config(ADC_ID,ADC_CH1); Chip_ADC_Init(LPC_ADC0, & ADCSetup);/* aca debo pasarle un puntero a LPC_DAC_T que es un tipo de dato definido con typedef*/ Chip_ADC_EnableChannel(LPC_ADC0,ADC_CH1,ENABLE);/*ADC_CH1 Y ENABLE son parte de un enum y corresponden a numeros que definen el canal que estoy usando "el 1" y habilitando ese canal*/ Chip_ADC_SetSampleRate(LPC_ADC0, &ADCSetup,ADC_MAX_SAMPLE_RATE); }
/* P0.23 -> AD0 */ void adcInit(void) { ADC_CLOCK_SETUP_T adc; Chip_ADC_Init(LPC_ADC, &adc); Chip_ADC_SetSampleRate(LPC_ADC, &adc, 22000); Chip_ADC_EnableChannel(LPC_ADC, ADC_CH0, ENABLE); Chip_ADC_Int_SetChannelCmd(LPC_ADC, ADC_CH0, ENABLE); Chip_ADC_SetBurstCmd(LPC_ADC, ENABLE); NVIC_EnableIRQ(ADC_IRQn); }
void initAdc (const adc_t adcNumber) { ADCSetup.adcRate = ADC_MAX_SAMPLE_RATE; ADCSetup.bitsAccuracy = ADC_10BITS; ADCSetup.burstMode = false; if ((adcNumber > 0) && (adcNumber < (sizeof (adc) / sizeof (adc_t)))) { /*ADC Init */ Chip_SCU_ADC_Channel_Config(ADC_ID, adc[adcNumber]); // Channel on ADC0 Chip_ADC_Init(_LPC_ADC_ID, &ADCSetup); Chip_ADC_EnableChannel(_LPC_ADC_ID, adc[adcNumber], ENABLE); } }
void Board_ADC_EnableChannel(uint8_t channelNumber) { uint32_t index = 0; // always using ADC0 switch(channelNumber) { case 1: Chip_ADC_EnableChannel(adcsData[index].adc, ADC_CH1, ENABLE); Chip_ADC_EnableChannel(adcsData[index].adc, ADC_CH2, DISABLE); Chip_ADC_EnableChannel(adcsData[index].adc, ADC_CH3, DISABLE); break; case 2: Chip_ADC_EnableChannel(adcsData[index].adc, ADC_CH1, DISABLE); Chip_ADC_EnableChannel(adcsData[index].adc, ADC_CH2, ENABLE); Chip_ADC_EnableChannel(adcsData[index].adc, ADC_CH3, DISABLE); break; case 3: Chip_ADC_EnableChannel(adcsData[index].adc, ADC_CH1, DISABLE); Chip_ADC_EnableChannel(adcsData[index].adc, ADC_CH2, DISABLE); Chip_ADC_EnableChannel(adcsData[index].adc, ADC_CH3, ENABLE); break; } }
/** \brief ADC Initialization method */ uint8_t init_ADC_EDUCIAA(void) { /** \details * This function initialize the ADC peripheral in the EDU-CIAA board, * with the correct parameters with LPCOpen library. It uses CH1 * * \param none * * \return uint8_t: TBD (to support errors in the init function) * */ static ADC_CLOCK_SETUP_T configADC; configADC.adcRate=1000; /** max 409 KHz*/ configADC.burstMode=DISABLE; configADC.bitsAccuracy=ADC_10BITS; Chip_ADC_Init(LPC_ADC0,&configADC); Chip_ADC_EnableChannel(LPC_ADC0,ADC_CH1,ENABLE); Chip_ADC_SetSampleRate(LPC_ADC0, &configADC,ADC_MAX_SAMPLE_RATE); return TRUE; }
void ADC_Init() { Chip_SCU_ADC_Channel_Config(0,ADC_CH1); Chip_ADC_Init(LPC_ADC0, &adcsetup); Chip_ADC_EnableChannel(LPC_ADC0, ADC_CH1, ENABLE); }
/* * @brief: enable/disable the ADC and DAC peripheral * @param: ENEABLE_AI, DISABLE_AI, ENEABLE_AO, DISABLE_AO * @return: none */ void analogConfig( uint8_t config ){ switch(config){ case ENABLE_ANALOG_INPUTS: { /* Config ADC0 sample mode */ /* ADC_CLOCK_SETUP_T ADCSetup = { 400000, // ADC rate 10, // ADC bit accuracy 0 // ADC Burt Mode (true or false) }; */ ADC_CLOCK_SETUP_T ADCSetup; /* Initialized to default values: * - Sample rate:ADC_MAX_SAMPLE_RATE=400KHz * - resolution: ADC_10BITS * - burst mode: DISABLE */ Chip_ADC_Init( LPC_ADC0, &ADCSetup ); /* Disable burst mode */ Chip_ADC_SetBurstCmd( LPC_ADC0, DISABLE ); /* Set sample rate to 200KHz */ Chip_ADC_SetSampleRate( LPC_ADC0, &ADCSetup, ADC_MAX_SAMPLE_RATE/2 ); /* Disable all channels */ Chip_ADC_EnableChannel( LPC_ADC0,ADC_CH1, DISABLE ); Chip_ADC_Int_SetChannelCmd( LPC_ADC0, ADC_CH1, DISABLE ); Chip_ADC_EnableChannel( LPC_ADC0, ADC_CH2, DISABLE ); Chip_ADC_Int_SetChannelCmd( LPC_ADC0, ADC_CH2, DISABLE ); Chip_ADC_EnableChannel( LPC_ADC0, ADC_CH3, DISABLE ); Chip_ADC_Int_SetChannelCmd( LPC_ADC0, ADC_CH3, DISABLE ); Chip_ADC_EnableChannel( LPC_ADC0, ADC_CH4, DISABLE ); Chip_ADC_Int_SetChannelCmd( LPC_ADC0, ADC_CH4, DISABLE ); } break; case DISABLE_ANALOG_INPUTS: /* Disable ADC peripheral */ Chip_ADC_DeInit( LPC_ADC0 ); break; case ENABLE_ANALOG_OUTPUTS: /* Initialize the DAC peripheral */ Chip_DAC_Init(LPC_DAC); /* Enables the DMA operation and controls DMA timer */ Chip_DAC_ConfigDAConverterControl(LPC_DAC, DAC_DMA_ENA); /* DCAR DMA access */ /* Update value to DAC buffer*/ Chip_DAC_UpdateValue(LPC_DAC, 0); break; case DISABLE_ANALOG_OUTPUTS: /* Disable DAC peripheral */ Chip_DAC_DeInit( LPC_DAC ); break; } }
/** * @brief Main routine for W5500 EVB firmware * @return Function should not exit. */ int main(void) { #if defined (__USE_LPCOPEN) #if !defined(NO_BOARD_LIB) // Read clock settings and update SystemCoreClock variable SystemCoreClockUpdate(); // Set up and initialize all required blocks and // functions related to the board hardware Board_Init(); #endif #endif uint16_t dataADC; int16_t calc_temp; /* Flag for running user's code */ bool run_user_applications = true; /* Enable and setup SysTick Timer at a periodic rate */ SysTick_Config(SystemCoreClock / TICKRATE_HZ1); /* ADC Init */ Init_ADC_PinMux(); Chip_ADC_Init(LPC_ADC, &ADCSetup); Chip_ADC_EnableChannel(LPC_ADC, TEMP_SENSOR_CH, ENABLE); #ifdef _MAIN_DEBUG_ printf("\r\n=======================================\r\n"); printf(" WIZnet W5500 EVB\r\n"); printf(" On-board Temperature sensor demo example v%d.%.2d\r\n", VER_H, VER_L); printf("=======================================\r\n"); printf(">> This example using ADC, SysTick\r\n"); printf("=======================================\r\n"); #endif /* Main loop ***************************************/ while(1) { // TODO: insert user's code here if(run_user_applications) { if(ADC_read_enable) { ADC_read_enable = false; /* Start A/D conversion */ Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING); /* Waiting for A/D conversion complete */ while (Chip_ADC_ReadStatus(LPC_ADC, TEMP_SENSOR_CH, ADC_DR_DONE_STAT) != SET) {} /* Read ADC value */ Chip_ADC_ReadValue(LPC_ADC, TEMP_SENSOR_CH, &dataADC); /* Calculate ADC value to Celsius temperature */ calc_temp = (((dataADC * SUPPLY_VOLTAGE) / 1023) - 500) / 10; /* Print ADC value */ printf("ADC value is 0x%x, ", dataADC); /* Print Celsius temperature */ printf("Celsius temperature : %d C\r\n", calc_temp); } } // End of user's code } // End of Main loop return 0; }
/** * @brief main routine for blinky example * @return Function should not exit. */ int main(void) { USBD_API_INIT_PARAM_T usb_param; USB_CORE_DESCS_T desc; ErrorCode_t ret = LPC_OK; uint32_t prompt = 0; SystemCoreClockUpdate(); /* Initialize board and chip */ Board_Init(); Board_ADC_Init(); /* Initialize PWM Units */ handle0 = Chip_PWM_Init(0, 18, 100); handle1 = Chip_PWM_Init(0, 13, 100); /* enable clocks and pinmux */ Chip_USB_Init(); /* initialize USBD ROM API pointer. */ g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->usbdApiBase; /* initialize call back structures */ memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T)); usb_param.usb_reg_base = LPC_USB0_BASE; /* WORKAROUND for artf44835 ROM driver BUG: Code clearing STALL bits in endpoint reset routine corrupts memory area next to the endpoint control data. For example When EP0, EP1_IN, EP1_OUT, EP2_IN are used we need to specify 3 here. But as a workaround for this issue specify 4. So that extra EPs control structure acts as padding buffer to avoid data corruption. Corruption of padding memory doesn’t affect the stack/program behaviour. */ usb_param.max_num_ep = 3 + 1; usb_param.mem_base = USB_STACK_MEM_BASE; usb_param.mem_size = USB_STACK_MEM_SIZE; /* Set the USB descriptors */ desc.device_desc = (uint8_t *) &USB_DeviceDescriptor[0]; desc.string_desc = (uint8_t *) &USB_StringDescriptor[0]; /* Note, to pass USBCV test full-speed only devices should have both descriptor arrays point to same location and device_qualifier set to 0. */ desc.high_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0]; desc.full_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0]; desc.device_qualifier = 0; /* USB Initialization */ ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param); if (ret == LPC_OK) { /* WORKAROUND for artf32219 ROM driver BUG: The mem_base parameter part of USB_param structure returned by Init() routine is not accurate causing memory allocation issues for further components. */ usb_param.mem_base = USB_STACK_MEM_BASE + (USB_STACK_MEM_SIZE - usb_param.mem_size); /* Initialize ADC */ Chip_ADC_Init(_LPC_ADC_ID, &ADCSetup); Chip_ADC_EnableChannel(_LPC_ADC_ID, ADC_CH0, ENABLE); Chip_ADC_Int_SetChannelCmd(_LPC_ADC_ID, ADC_CH0, ENABLE); NVIC_SetPriority(_LPC_ADC_IRQ, 1); NVIC_EnableIRQ(_LPC_ADC_IRQ); /* Init VCOM interface */ ret = vcom_init(g_hUsb, &desc, &usb_param); if (ret == LPC_OK) { /* enable USB interrupts */ NVIC_SetPriority(USB0_IRQn, 1); NVIC_EnableIRQ(USB0_IRQn); /* now connect */ USBD_API->hw->Connect(g_hUsb, 1); } } DEBUGSTR("USB CDC class based virtual Comm port example!\r\n"); /* Start BURST Mode (Continuously Convert and Interrupt) */ Chip_ADC_SetBurstCmd(_LPC_ADC_ID, ENABLE); Chip_RIT_Init(LPC_RITIMER); Chip_RIT_SetTimerInterval(LPC_RITIMER, CONTROL_INTERVAL); NVIC_EnableIRQ(RIT_IRQn); int read_mode = WAITING_HEADER; while (1) { /* Check if host has connected and opened the VCOM port */ if ((vcom_connected() != 0) && (prompt == 0)) { //vcom_write("Hello World!!\r\n", 15); prompt = 1; } if (prompt) { unsigned char c; if (vcom_bread(&c, 1) != 0) { switch (read_mode) { case WAITING_HEADER: if (c == PACKET_HEADER) { g_buffCounter = 0; read_mode = WAITING_FOOTER; } break; case WAITING_FOOTER: if (c == PACKET_FOOTER) { onReceivePacket(); read_mode = WAITING_HEADER; } else { g_rxBuff[g_buffCounter] = c; g_buffCounter++; } break; default: break; } } } /* Sleep until next IRQ happens */ //__WFI(); } }
void batteryInit() { Chip_ADC_SetStartMode(LPC_ADC1, ADC_START_NOW, ADC_TRIGGERMODE_RISING); //This must be before the burst cmd Chip_ADC_SetBurstCmd(LPC_ADC1, ENABLE); Chip_ADC_EnableChannel(LPC_ADC1, 1, ENABLE); }
/** * @brief Main routine for ADC example * @return Nothing */ int main(void) { bool end_Flag = false; uint32_t _bitRate = ADC_MAX_SAMPLE_RATE; uint8_t bufferUART; SystemCoreClockUpdate(); Board_Init(); /* Chip_IOCON_PinMux(0, 25, IOCON_ADMODE_EN, IOCON_FUNC1); */ /*ADC Init */ Chip_ADC_Init(_LPC_ADC_ID, &ADCSetup); Chip_ADC_EnableChannel(_LPC_ADC_ID, _ADC_CHANNLE, ENABLE); while (!end_Flag) { DEBUGOUT(WelcomeMenu); while (!end_Flag) { bufferUART = 0xFF; bufferUART = DEBUGIN(); if (bufferUART == 'c') { DEBUGOUT(SelectMenu); bufferUART = 0xFF; while (bufferUART == 0xFF) { bufferUART = DEBUGIN(); if ((bufferUART != '1') && (bufferUART != '2') && (bufferUART != '3')) { bufferUART = 0xFF; } } switch (bufferUART) { case '1': /* Polling Mode */ App_Polling_Test(); break; case '2': /* Interrupt Mode */ App_Interrupt_Test(); break; case '3': /* DMA mode */ App_DMA_Test(); break; } break; } else if (bufferUART == 'x') { end_Flag = true; DEBUGOUT("\r\nADC demo terminated!"); } else if (bufferUART == 'o') { _bitRate -= _bitRate > 0 ? 1000 : 0; Chip_ADC_SetSampleRate(_LPC_ADC_ID, &ADCSetup, _bitRate); DEBUGOUT("Rate : %ld Sample/s\r\n", _bitRate); } else if (bufferUART == 'p') { _bitRate += _bitRate < 400000 ? 1000 : 0; Chip_ADC_SetSampleRate(_LPC_ADC_ID, &ADCSetup, _bitRate); DEBUGOUT("Rate : %ld Sample/s\r\n", _bitRate); } else if (bufferUART == 'b') { Burst_Mode_Flag = !Burst_Mode_Flag; ADCSetup.burstMode = Burst_Mode_Flag; Chip_ADC_SetSampleRate(_LPC_ADC_ID, &ADCSetup, _bitRate); if (Burst_Mode_Flag) { DEBUGOUT("Burst Mode ENABLED\r\n"); } else { DEBUGOUT("Burst Mode DISABLED\r\n"); } } } } return 0; }
__INLINE void skynetbase_windvane_start(void) { // activate adc Chip_ADC_EnableChannel(LPC_ADC, ADC_CHANNEL, DISABLE); Chip_ADC_EnableChannel(LPC_ADC, WINDVANE_ADC, ENABLE); Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING); }
__INLINE void skynetbase_windvane_stop(void) { // deactivate Chip_ADC_EnableChannel(LPC_ADC, WINDVANE_ADC, DISABLE); }