/* Interrupt routine for DAC example */ static void App_Interrupt_Test(void) { uint32_t tmp = 0; volatile uint32_t i = 0; NVIC_DisableIRQ(DAC_IRQn); NVIC_SetPriority(DAC_IRQn, ((0x01 << 2) | 0x01)); Interrupt_Continue_Flag = 1; DAC_Interrupt_Done_Flag = 1; while (Interrupt_Continue_Flag) { tmp++; if (tmp == (DATA_SIZE - 1)) { tmp = 0; } Chip_DAC_UpdateValue(LPC_DAC, tmp); if (DAC_Interrupt_Done_Flag) { DAC_Interrupt_Done_Flag = 0; NVIC_EnableIRQ(DAC_IRQn); } for (i = 0; i < 0x10000; i++) ; } /* Disable DAC interrupt */ NVIC_DisableIRQ(DAC_IRQn); }
/* * @brief Write a value in the DAC. * @param analogOutput: AO0 ... AOn * @param value: analog value to be writen in the DAC, from 0 to 1023 * @return none */ void analogWrite( uint8_t analogOutput, uint16_t value ){ if( value > 1023 ){ value = 1023; } Chip_DAC_UpdateValue( LPC_DAC, value ); }
void RIT_IRQHandler(void){ /* Clearn interrupt */ Chip_RIT_ClearInt(LPC_RITIMER); t++; t%=T; DatoDAC=(t*Vmax)/T; /* Saco dato por DAC */ Chip_DAC_UpdateValue(LPC_DAC,DatoDAC); if (t==0) { InvierteLed(1); } }
/* Polling routine for DAC example */ static void App_Polling_Test(void) { uint32_t tmp = 0; volatile uint32_t i = 0; while (DEBUGIN() != 'x') { tmp++; if (tmp == (DATA_SIZE - 1)) { tmp = 0; } Chip_DAC_UpdateValue(LPC_DAC, tmp); while (!(Chip_DAC_GetIntStatus(LPC_DAC))) {} for (i = 0; i < 0x10000; i++) ; } }
void InicializarDAC(void){ Chip_SCU_DAC_Analog_Config(); Chip_DAC_Init(LPC_DAC); Chip_DAC_UpdateValue(LPC_DAC, 0); Chip_DAC_ConfigDAConverterControl (LPC_DAC, DAC_DMA_ENA); }
void setDAC(uint16_t valor_adc){ Chip_DAC_UpdateValue(LPC_DAC, valor_adc); //hace cast de int16 a int32 }
void ActualizarValorDAC(uint16_t ValorDAC) { Chip_DAC_UpdateValue(LPC_DAC, ValorDAC); }
void escribir_DAC(int valor) { Chip_DAC_UpdateValue(LPC_DAC, valor); }
/* * @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; } }
void setDacValue (uint16_t dacValue) { Chip_DAC_UpdateValue (LPC_DAC, dacValue); while (!(Chip_DAC_GetIntStatus (LPC_DAC))); /* 0 <=> 0V & 1024 <=> 3.3V */ }
void Board_DAC_writeValue(uint32_t value) { Chip_DAC_UpdateValue(LPC_DAC,value); }
uint32_t updateDACbuffer(uint32_t buffer){ Chip_DAC_UpdateValue(LPC_DAC, buffer); return buffer; }
void DAC_Value(int count) { Chip_DAC_UpdateValue(LPC_DAC,count); while (!(Chip_DAC_GetIntStatus(LPC_DAC))) {}; }
void ConfigurarSalidaDAC(int valor){ Chip_DAC_UpdateValue(LPC_DAC,valor); };
void dacUpdate(uint32_t value){ Chip_DAC_UpdateValue(LPC_DAC,value); }