2015-06-24 08:35 AM
Hey!
I've been trying to use my Nucleo F334's DAC wave generation function to output white noise and I can't get it to work (I'm using Mbed compiler tools)... I used the HAL functions describedhttp://www.st.com/st-web-ui/static/active/jp/resource/technical/document/user_manual/DM001058pdf
, page Here's the code that I tried :
#include ''mbed.h''
DAC_HandleTypeDef DAC_InitStructure;
int
main() {
SystemInit();
DAC_InitStructure.Instance = DAC1;
__DAC1_CLK_ENABLE();
HAL_DAC_Init(&DAC_InitStructure);
HAL_DAC_Start(&DAC_InitStructure, DAC_CHANNEL_1);
HAL_DACEx_NoiseWaveGenerate(&DAC_InitStructure, DAC_CHANNEL_1, DAC_LFSRUNMASK_BITS6_0);
while
(1);
}
It compiles correctly but I don't get any output (I'm looking at PA_4 aka A2).
I also tried withHAL_DACEx_TriangleWaveGenerate(&DAC_InitStructure, DAC_CHANNEL_1, DAC_TRIANGLEAMPLITUDE_1023); but it doesn't work either...
I tried putting the function into the loop : no positive result.
I checked if the STM32F334R8 has the noise generation capacities and it does have it, according to the
http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM000977pdf
... I'd be glad to have some help! Thanks friends EDIT : I just read in the HAL reference that I should enable software trigger before using wave genereation so I did that but still not working EDIT2 : I tried with TIM6 trigger instead of software trigg with no result. Here is the new code :
#include ''mbed.h''
DAC_HandleTypeDef DAC_InitStructure;
DAC_ChannelConfTypeDef chan1;
int
main() {
SystemInit();
// enable TIM3 peripheral
__TIM6_CLK_ENABLE();
TIM6->CR2 &= 0;
// UG used as trigger output
TIM6->PSC = 0;
// no prescaler
TIM6->ARR = 72000;
// Reload value
TIM6->EGR = TIM_EGR_UG;
// Reinitialise the counter
TIM6->DIER = TIM_DIER_UIE;
// enable update interrupt
//DAC_InitStructure.Instance = DAC1;
chan1.DAC_Trigger = DAC_TRIGGER_T6_TRGO;
HAL_DAC_ConfigChannel(&DAC_InitStructure, &chan1, DAC_CHANNEL_1);
HAL_DACEx_NoiseWaveGenerate(&DAC_InitStructure, DAC_CHANNEL_1, DAC_LFSRUNMASK_BITS11_0);
HAL_DAC_Init(&DAC_InitStructure);
HAL_DAC_Start(&DAC_InitStructure, DAC_CHANNEL_1);
TIM6->CR1 |= TIM_CR1_CEN;
while
(1){
if
(TIM3->SR & TIM_SR_UIF)
// if UIF flag is set
TIM3->SR &= ~TIM_SR_UIF;
// clear UIF flag ///// Not really sure about this part, I figured the flag had to be reset somwhere but as i don't have interrupt routine, I didn't know where to do it.
}
}
#nucleo #noise #wave #generation