Digital Value to DAC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-06-24 12:06 PM
Hello,
I am using the STM32F4 discovery board. I have a project in which I have a timer which generate an interrupts @ 100Khz. In the ISR it stores a new value to a variable. Now how can I use the DMA to send this value to the DAC which is updated at the same rate.ThanksRegardsSameer #stm32- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-06-24 1:16 PM
hi ,
i do it like this :#define BITDEPTH 12 // 12 bits DAC
#define SAMPLERATE (SYSCLK / (1 <<
BITDEPTH
)) // Best audio quality 192MHz / (1 << 11) = 46875Hz
// Initialise Timer2
void Timer2_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
// Clock enable
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
// Timer2 init
TIM_TimeBaseStructure.TIM_Period
=
SYSCLK
/ SAMPLERATE;
TIM_TimeBaseStructure.TIM_Prescaler
=
0
; // 192Mhz tick (adjust per your clock)
TIM_TimeBaseStructure.TIM_ClockDivision
=
TIM_CKD_DIV1
;
TIM_TimeBaseStructure.TIM_CounterMode
=
TIM_CounterMode_Up
;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
// Timer2 enable
TIM_ARRPreloadConfig(TIM2, ENABLE);
TIM_Cmd(TIM2, ENABLE);
}
// *********************************************************************************
// Timer2 interrup and DAC2 init
void Mod_Int_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef DAC_GPIO_Init;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
//---------------------------------------------
// init from Timer2 Interrupt
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
NVIC_InitStructure.NVIC_IRQChannel
=
TIM2_IRQn
;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority
=
0
;
NVIC_InitStructure.NVIC_IRQChannelSubPriority
=
0
;
NVIC_InitStructure.NVIC_IRQChannelCmd
=
ENABLE
;
NVIC_Init(&NVIC_InitStructure);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
DAC_GPIO_Init.GPIO_Pin
=
GPIO_Pin_5
;
DAC_GPIO_Init.GPIO_Mode
=
GPIO_Mode_AN
;
DAC_GPIO_Init.GPIO_Speed
=
GPIO_Speed_25MHz
;
DAC_GPIO_Init.GPIO_OType
=
GPIO_OType_PP
;
DAC_GPIO_Init.GPIO_PuPd
=
GPIO_PuPd_NOPULL
;
GPIO_Init(GPIOA, &DAC_GPIO_Init);
DAC_Cmd(DAC_Channel_2,ENABLE);
}
// *********************************************************************************
// Timer2 interrupt
void TIM2_IRQHandler(void)
{
if(File_Loaded != 0)
if(SoundBuffer.writePos != SoundBuffer.readPos)
{
// Output the Audio as mono (only DAC2 pin is free)
Sound_Out = (uint16_t)(((SoundBuffer.left[SoundBuffer.readPos] + SoundBuffer.right[SoundBuffer.readPos])) >> 1);
DAC_SetChannel2Data(DAC_Align_12b_R,Sound_Out);
SoundBuffer.readPos++;
SoundBuffer.readPos &= SOUNDBUFFERSIZE - 1;
}
Int_Count++;
// Clear interrupt flag
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
}
I hope it can help you .
It's a part from my st429 mod player.
Tou can get the full source on this page :
Cheers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-06-24 1:17 PM
double post .. delete thisd one ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-06-24 2:02 PM
If you're computing it in a periodic interrupt, could you not just write it to the DAC then? Otherwise you've got to pay particular attention to keeping the IRQ and DMA synchronized.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-06-25 11:04 AM
thank you all... U all guys are great. Also I would like to thank Clive separately for ur great help and amazing spirit.
