2015-02-24 03:41 PM
/*
* For when you don't want a triangle wave or random noise.
*/
HAL_StatusTypeDef HAL_DACEx_NoWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel)
{
/* Check the parameters */
assert_param(IS_DAC_CHANNEL(Channel));
/* Process locked */
__HAL_LOCK(hdac);
/* Change DAC state */
hdac->State = HAL_DAC_STATE_BUSY;
/* Enable the selected wave generation for the selected DAC channel */
MODIFY_REG(hdac->Instance->CR, (DAC_CR_WAVE1) <<
Channel
, (DAC_WAVEGENERATION_NONE) << Channel);
/* Change DAC state */
hdac->State = HAL_DAC_STATE_READY;
/* Process unlocked */
__HAL_UNLOCK(hdac);
/* Return function status */
return HAL_OK;
}
2015-05-06 10:27 AM
Many users would provide their own data to the 12bit DAC so an example similar to the Escalator example for the 8bit DAC would have been nice.
The attached .jpg oscilloscope image shows about 20% of the data points not on the sine wave, by amplitude insufficient on PA4. Can anybody suggest a solution ? Here are the modifications to main.c for DAC_SignalsGeneration for the stm32f429i_discovery board. #define MAXNSINE 20 const uint16_t cSine12bit[MAXNSINE] = { 0x800, 0xa78, 0xcb3, 0xe78, 0xf9b, 0xfff, 0xf9b, 0xe78, 0xcb3, 0xa78, 0x800, 0x587, 0x34c, 0x187, 0x64, 0x0, 0x64, 0x187, 0x34c, 0x587 }; static void DAC_Ch1_SineConfig12bit(void) { /*##-1- Initialize the DAC peripheral ######################################*/ if(HAL_DAC_Init(&DacHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /*##-2- DAC channel1 Configuration #########################################*/ sConfig.DAC_Trigger = DAC_TRIGGER_T6_TRGO; sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; if(HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DACx_CHANNEL1) != HAL_OK) { /* Channel configuration Error */ Error_Handler(); } /* [dy] DMA the 12 bit SineWave data */ /*##-3- Enable DAC Channel1 and associated DMA #############################*/ if(HAL_DAC_Start_DMA(&DacHandle, DACx_CHANNEL1, (uint32_t*)cSine12bit, MAXNSINE, DAC_ALIGN_12B_R) != HAL_OK) { /* Start DMA Error */ Error_Handler(); } } Thanks for providing HAL_DACEx_NoWaveGenerate ________________ Attachments : 20150506_094020.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzQQ&d=%2Fa%2F0X0000000bMs%2FMIfKugJUkucPpZbQ5mMqP4PjdURFEP8PA4YqHA4MHpc&asPdf=false2015-05-06 03:13 PM
The code changes below to stm32f4xx_hal_msp.c allows 12bit DAC of uint32_t sine_data
seen on PA4. /* [dy] For 12bit example, this may break 8bit example hdma_dac1.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; hdma_dac1.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; */ hdma_dac1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; hdma_dac1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;