Exemplo n.º 1
0
int main(void)
{
//init:
    DAC_DeInit();
	init_GPIOA();
    init_GPIOC();
    init_GPIOD();
    init_DMA1();
    init_DMA2();
    init_TIM2();
    init_TIM3();
    init_TIM4();
    init_TIM6();
    init_ADC3();
	init_DAC();
	init_filter(&ap_1);
	init_filter(&ap_2);
	init_filter(&ap_3);
	init_filter(&ap_4);
	ap_filter_coefs(&ap_1);
	ap_filter_coefs(&ap_2);
	ap_filter_coefs(&ap_3);
	ap_filter_coefs(&ap_4);
    ADC_SoftwareStartConv(ADC3);
    while (1)
    {
		counter++;
    }
}
Exemplo n.º 2
0
void DAC_Config( void )
{
	
  /* DAC Periph clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

  /* GPIOA clock enable */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  
  /* Configure PA.04 (DAC_OUT1) as analog */
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
	
	/* DAC channel1 Configuration */
  DAC_DeInit(); 
  DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
  /* DAC Channel1 Init */
  DAC_Init(DAC_Channel_1, &DAC_InitStructure);
        
  /* Enable DAC Channel1 */
  DAC_Cmd(DAC_Channel_1, ENABLE);
	
	
} //end DAC_Config
Exemplo n.º 3
0
void analogout_free(dac_t *obj) {
    DAC_TypeDef *dac = (DAC_TypeDef *)(obj->dac);
    // Disable DAC
    DAC_DeInit(dac);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, DISABLE);
    // Configure GPIO
    pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
}
Exemplo n.º 4
0
void DAC_VOLTAGE_Configuration(void)
{
	DAC_InitTypeDef DAC_InitStructure;
	DAC_DeInit();
	DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
	DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;      
	DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
	DAC_Init(DAC_Channel_1, &DAC_InitStructure);
	DAC_Cmd(DAC_Channel_1, ENABLE);
	DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);
}
Exemplo n.º 5
0
void SOUNDInitDAC(uint32_t sampleRate)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	DAC_InitTypeDef DAC_InitStructure;

//	CS43L22Init();

	RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC | RCC_APB1Periph_TIM6, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1 | RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC, ENABLE);

	// PC5 MAX4410 Audio Amp Shutdown
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_Init(GPIOC, &GPIO_InitStructure);	// 初期化関数を読み出します。

	AUDIO_OUT_SHUTDOWN;

	// PA4 PA5 DAC_OUT1 DAC_OUT2
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_Init(GPIOA, &GPIO_InitStructure);	// 初期化関数を読み出します。

	DAC_DeInit();
	DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO;
	DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
	DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;
	DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
	DAC_Init(DAC_Channel_1, &DAC_InitStructure);
	DAC_Init(DAC_Channel_2, &DAC_InitStructure);

	DAC_DMACmd(DAC_Channel_1, ENABLE);
	DAC_DMACmd(DAC_Channel_2, ENABLE);

	DAC_Cmd(DAC_Channel_1, ENABLE);
	DAC_Cmd(DAC_Channel_2, ENABLE);

	TIM6->ARR = ((SystemCoreClock / 4) * 2) / sampleRate - 1;
	TIM6->PSC = 0;

	TIM6->CR1 |= _BV(7);
	TIM6->CR2 |= TIM_TRGOSource_Update;
	TIM6->DIER |= TIM_DMA_Update | _BV(0); // Interrupt Enable;
	TIM6->CR1 |= _BV(0);
}
Exemplo n.º 6
0
/**
  * @brief  Initializes the DAT ...
  * @param  None
  * @retval None
  */
void AudioOut_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /* DAC Periph clock enable */
  RCC_APB1PeriphClockCmd(DAC_CLK, ENABLE);

  /* GPIOA clock enable */
  RCC_AHBPeriphClockCmd(AUDIO_OUT_GPIO_CLK, ENABLE);

  /* Configure PA.04 (DAC_OUT1) as analog */
  GPIO_InitStructure.GPIO_Pin =  AUDIO_OUT_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(AUDIO_OUT_GPIO_PORT, &GPIO_InitStructure);

  DAC_DeInit();
}
Exemplo n.º 7
0
// initValue - 0 - 4095
void Init_DAC_1(int initValue)
{
    DAC_InitTypeDef  DAC_InitStructure;
    
    //Set DAC clock
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
    
    /* DAC channel1 Configuration */
    DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
    DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
    DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
    
    
    DAC_DeInit(); 
    DAC_Init(DAC_Channel_1, &DAC_InitStructure);
    DAC_Cmd(DAC_Channel_1, ENABLE);
    DAC_SetChannel1Data(DAC_Align_12b_R, initValue);
    DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
}
Exemplo n.º 8
0
/**
  * @brief  Configures the DAC channel 1 with output buffer disabled.
  * @param  None
  * @retval None
  */
static void DAC_Config(void)
{
  DAC_InitTypeDef  DAC_InitStructure;
  
  /* DAC clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
  
  /* Deinitialize DAC */
  DAC_DeInit();

  /* DAC Channel1 Init */
  DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
  DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
  DAC_Init(DAC_Channel_1, &DAC_InitStructure);

  /* Enable DAC Channel1 */
  DAC_Cmd(DAC_Channel_1, ENABLE);
}
Exemplo n.º 9
0
int main(void)
{

//init:
    DAC_DeInit();
    init_DMA_GPIO_ADC();
    /* Start ADC3 Software Conversion */
    ADC_SoftwareStartConv(ADC3);

//say hello:
    Blink(1000000L);

    while (1)
    {
        DAC1ConvertedValue = ADC3ConvertedValue;
        //Blink((uint32_t)ADC3ConvertedValue*1000L);
        //Pulse();
        Blink2((u)
    }
}
Exemplo n.º 10
0
void BIAS_Config(void){
	DAC_InitTypeDef DAC_InitStructure;
	GPIO_InitTypeDef GPIO_InitStructure;
	DAC_DeInit();
  /* DAC Periph clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
	 /* DAC channel1 Configuration */
  DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
  DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude =  DAC_TriangleAmplitude_1;
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
  DAC_Init(DAC_Channel_1, &DAC_InitStructure);
	/* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is 
     automatically connected to the DAC converter. */
  DAC_Cmd(DAC_Channel_1, ENABLE);
  /* Set DAC Channel1 DHR12L register */
  //DAC_SetChannel1Data(DAC_Align_12b_L, 0x7FF0);
  //DAC_SetChannel1Data(DAC_Align_12b_L, 0x9B20);
	//DAC_SetChannel1Data(DAC_Align_12b_R, 0x04D9);
	//BIAS_DAC_Value = DAC_GetDataOutputValue(DAC_Channel_1);
	DAC_SetChannel1Data(DAC_Align_12b_R, DAC_OUT_BOOT);
	//BIAS_DAC_Value = DAC_GetDataOutputValue(DAC_Channel_1);
	DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
	BIAS_DAC_Value = DAC_GetDataOutputValue(DAC_Channel_1);
  /* Once the DAC channel is enabled, the corresponding GPIO pin is automatically 
     connected to the DAC converter. In order to avoid parasitic consumption, 
     the GPIO pin should be configured in analog */
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);	 
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
	 /* Used peripherals clock enable -------------------------------------------*/
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
	
	 /* configure PC9 as output push-pull  */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
	GPIO_SetBits(GPIOC, GPIO_Pin_9);	
}
Exemplo n.º 11
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{  
  /*!< At this stage the microcontroller clock setting is already configured, 
  this is done through SystemInit() function which is called from startup
  file (startup_stm32f0xx.s) before to branch to application main.
  To reconfigure the default setting of SystemInit() function, refer to
  system_stm32f0xx.c file
  */ 
  
  /* Preconfiguration before using DAC----------------------------------------*/
  DAC_Config();
  
  /* TIM2 configuration to trigger DAC */
  TIM2_Config();
  
  /* Configures User Button */
  STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI);
  
  while (1)
  {
    /* If the User Button is pressed */
    if (KeyPressed == RESET)
    {            
      DAC_DeInit(); 
      
      /* select waves forms according to the Key Button status */
      if (SelectedWavesForm == 1)
      {
        /* The sine wave and the escalator wave has been selected */
        DAC_Sine_EscalatorConfig();        
      }
      else
      {
        /* The triangle wave and the noise wave has been selected */
        DAC_Noise_TriangleConfig();
      }
      
      KeyPressed = SET; 
    }
  }
}
Exemplo n.º 12
0
void dac_init() {
#ifdef PHOTON_DAC
  pinMode(DAC1, OUTPUT);
  pinMode(DAC2, OUTPUT);
#else
  // DAC pins are PA4 and PA5
  GPIO_InitTypeDef GPIO_InitStructure;
  GPIO_StructInit(&GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_5;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  DAC_InitTypeDef DAC_InitStructure;
  DAC_StructInit(&DAC_InitStructure);
  /* DAC Periph clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
  DAC_DeInit();
  /* DAC channel1 & channel2 Configuration */
  DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
  DAC_Init(DAC_Channel_1, &DAC_InitStructure);
  DAC_Init(DAC_Channel_2, &DAC_InitStructure);

  /* Enable DAC Channel1 */
  DAC_Cmd(DAC_Channel_1, ENABLE);
  /* Enable DAC Channel2 */
  DAC_Cmd(DAC_Channel_2, ENABLE);

  /* Enable DAC conversion by software */
  DAC_DualSoftwareTriggerCmd(ENABLE);
  DAC_SetDualChannelData(DAC_Align_12b_R, 0x800, 0x800);
#endif
}
Exemplo n.º 13
0
void main(void)
#endif
{
  RST_CLK_DeInit();
  RST_CLK_CPU_PLLconfig (RST_CLK_CPU_PLLsrcHSIdiv2,0);
  /* Enable peripheral clocks --------------------------------------------------*/
  RST_CLK_PCLKcmd((RST_CLK_PCLK_RST_CLK | RST_CLK_PCLK_DMA | RST_CLK_PCLK_PORTE),ENABLE);
  RST_CLK_PCLKcmd((RST_CLK_PCLK_TIMER1 | RST_CLK_PCLK_DAC),ENABLE);
  RST_CLK_PCLKcmd((RST_CLK_PCLK_SSP1 | RST_CLK_PCLK_SSP2),ENABLE);

  /* Disable all interrupt */
  NVIC->ICPR[0] = 0xFFFFFFFF;
  NVIC->ICER[0] = 0xFFFFFFFF;

  /* Reset PORTE settings */
  PORT_DeInit(MDR_PORTE);

  /* Configure DAC pin: DAC1_OUT */
  /* Configure PORTE pin 9 */
  PORT_InitStructure.PORT_Pin   = PORT_Pin_2;
  PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
  PORT_InitStructure.PORT_MODE  = PORT_MODE_ANALOG;
  PORT_Init(MDR_PORTE, &PORT_InitStructure);

  /* DMA Configuration */
  /* Reset all DMA settings */
  DMA_DeInit();
  DMA_StructInit(&DMA_InitStr);
  /* Set Primary Control Data */
  DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)Sine12bit;
  DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)(&(MDR_DAC->DAC1_DATA));
  DMA_PriCtrlStr.DMA_SourceIncSize = DMA_SourceIncHalfword;
  DMA_PriCtrlStr.DMA_DestIncSize = DMA_DestIncNo;
  DMA_PriCtrlStr.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_PriCtrlStr.DMA_Mode = DMA_Mode_PingPong;
  DMA_PriCtrlStr.DMA_CycleSize = 32;
  DMA_PriCtrlStr.DMA_NumContinuous = DMA_Transfers_1;
  DMA_PriCtrlStr.DMA_SourceProtCtrl = DMA_SourcePrivileged;
  DMA_PriCtrlStr.DMA_DestProtCtrl = DMA_DestPrivileged;
  /* Set Alternate Control Data */
  DMA_AltCtrlStr.DMA_SourceBaseAddr = (uint32_t)Sine12bit;
  DMA_AltCtrlStr.DMA_DestBaseAddr   = (uint32_t)(&(MDR_DAC->DAC1_DATA));
  DMA_AltCtrlStr.DMA_SourceIncSize = DMA_SourceIncHalfword;
  DMA_AltCtrlStr.DMA_DestIncSize = DMA_DestIncNo;
  DMA_AltCtrlStr.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_AltCtrlStr.DMA_Mode = DMA_Mode_PingPong;
  DMA_AltCtrlStr.DMA_CycleSize = 32;
  DMA_AltCtrlStr.DMA_NumContinuous = DMA_Transfers_1;
  DMA_AltCtrlStr.DMA_SourceProtCtrl = DMA_SourcePrivileged;
  DMA_AltCtrlStr.DMA_DestProtCtrl = DMA_DestPrivileged;
  /* Set Channel Structure */
  DMA_InitStr.DMA_PriCtrlData = &DMA_PriCtrlStr;
  DMA_InitStr.DMA_AltCtrlData = &DMA_AltCtrlStr;
  DMA_InitStr.DMA_Priority = DMA_Priority_Default;
  DMA_InitStr.DMA_UseBurst = DMA_BurstClear;
  DMA_InitStr.DMA_SelectDataStructure = DMA_CTRL_DATA_PRIMARY;

  /* Init DMA channel TIM1*/
  DMA_Init(DMA_Channel_REQ_TIM1, &DMA_InitStr);

  /* Enable dma_req or dma_sreq to generate DMA request */
  MDR_DMA->CHNL_REQ_MASK_CLR = DMA_SELECT(DMA_Channel_REQ_TIM1);
  MDR_DMA->CHNL_USEBURST_CLR = DMA_SELECT(DMA_Channel_REQ_TIM1);

  /* Enable DMA_Channel_TIM1 */
  DMA_Cmd(DMA_Channel_REQ_TIM1, ENABLE);

  /* ADC Configuration */
  /* Reset all ADC settings */
  DAC_DeInit();
  /* DAC channel1 Configuration */
  DAC1_Init(DAC1_AVCC);
  /* DAC channel1 enable */
  DAC1_Cmd(ENABLE);

  /* TIMER1 Configuration */
  /* Time base configuration */
  TIMER_DeInit(MDR_TIMER1);
  TIMER_BRGInit(MDR_TIMER1,TIMER_HCLKdiv1);
  sTIM_CntInit.TIMER_Prescaler                = 0;
  sTIM_CntInit.TIMER_Period                   = 0xFF;
  sTIM_CntInit.TIMER_CounterMode              = TIMER_CntMode_ClkFixedDir;
  sTIM_CntInit.TIMER_CounterDirection         = TIMER_CntDir_Up;
  sTIM_CntInit.TIMER_EventSource              = TIMER_EvSrc_None;
  sTIM_CntInit.TIMER_FilterSampling           = TIMER_FDTS_TIMER_CLK_div_1;
  sTIM_CntInit.TIMER_ARR_UpdateMode           = TIMER_ARR_Update_Immediately;
  sTIM_CntInit.TIMER_ETR_FilterConf           = TIMER_Filter_1FF_at_TIMER_CLK;
  sTIM_CntInit.TIMER_ETR_Prescaler            = TIMER_ETR_Prescaler_None;
  sTIM_CntInit.TIMER_ETR_Polarity             = TIMER_ETRPolarity_NonInverted;
  sTIM_CntInit.TIMER_BRK_Polarity             = TIMER_BRKPolarity_NonInverted;
  TIMER_CntInit (MDR_TIMER1,&sTIM_CntInit);

  /* Enable DMA for TIMER1 */
  TIMER_DMACmd(MDR_TIMER1, TIMER_STATUS_CNT_ARR, TIMER_DMA_Channel0, ENABLE);

  /* TIMER1 enable counter */
  TIMER_Cmd(MDR_TIMER1,ENABLE);

  /* Enable DMA IRQ */
  NVIC_EnableIRQ(DMA_IRQn);

  /* Infinite loop */
  while(1)
  {
  }
}
Exemplo n.º 14
0
/**
  * @brief  DAC Channel1 Escalator and Cannel2 Sine Configuration
  * @param  None
  * @retval None
  */
static void DAC_Sine_EscalatorConfig(void)
{  
  DMA_InitTypeDef   DMA_InitStructure;

  /* DAC channel1 Configuration */
  DAC_DeInit(); 
  DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;
  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
  
  /* DAC Channel1 Init */
  DAC_Init(DAC_Channel_1, &DAC_InitStructure);
  
  /* Enable DAC Channel1 */
  DAC_Cmd(DAC_Channel_1, ENABLE);
  
  /* DMA1 channel3 configuration */
  DMA_DeInit(DMA1_Channel3); 
  DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12R1_ADDRESS;
  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&Sine12bit;
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
  DMA_InitStructure.DMA_BufferSize = 32;
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
  DMA_Init(DMA1_Channel3, &DMA_InitStructure);
  
  /* Enable DMA1 Channel3 */
  DMA_Cmd(DMA1_Channel3, ENABLE);
  
  /* Enable DMA for DAC Channel2 */
  DAC_DMACmd(DAC_Channel_1, ENABLE);
  
  /* Escalator Wave generator ----------------------------------------*/
  
  /* DAC channel2 Configuration */
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
  DAC_Init(DAC_Channel_2, &DAC_InitStructure);
  
  /* DMA1 channel4 configuration */
  DMA_DeInit(DMA1_Channel4);
  DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR8R2_ADDRESS;
  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&Escalator8bit;
  DMA_InitStructure.DMA_BufferSize = 6;
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
  DMA_Init(DMA1_Channel4, &DMA_InitStructure);
  
  /* Enable DMA1 Channel4 */
  DMA_Cmd(DMA1_Channel4, ENABLE);
  
  /* Enable DAC1 Channel1: Once the DAC1 channel2 is enabled, PA.05 is 
  automatically connected to the DAC converter. */
  DAC_Cmd(DAC_Channel_2, ENABLE);
  
  /* Enable DMA for DAC Channel1 */
  DAC_DMACmd(DAC_Channel_2, ENABLE);
}
Exemplo n.º 15
0
int init_DAC()
{
    GPIO_InitTypeDef gpinit[1] = {{0}};
    gpinit->GPIO_Pin   = GPIO_Pin_4;
    gpinit->GPIO_Mode  = GPIO_Mode_AIN;
    gpinit->GPIO_Speed = GPIO_Speed_50MHz;
    gpinit->GPIO_PuPd  = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOA, gpinit);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);



    DAC_DeInit();
    DAC_InitTypeDef dac[1];
    dac->DAC_Trigger = DAC_Trigger_T6_TRGO;
    dac->DAC_WaveGeneration = DAC_WaveGeneration_None;
    dac->DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits11_0;
    dac->DAC_OutputBuffer = DAC_OutputBuffer_Enable;
    DAC_Init(DAC_Channel_1, dac);

    DAC_Cmd(DAC_Channel_1, ENABLE);

    DMA_DeInit(DMA1_Stream5);
    DMA_InitTypeDef dma[1];
    dma->DMA_Channel = DMA_Channel_7;
    dma->DMA_PeripheralBaseAddr = (uint32_t) &DAC->DHR12L1;
    dma->DMA_Memory0BaseAddr = (uint32_t) buffer;
    dma->DMA_DIR = DMA_DIR_MemoryToPeripheral;
    dma->DMA_BufferSize = NUMEL(buffer);
    dma->DMA_PeripheralInc = DMA_PeripheralInc_Disable;
    dma->DMA_MemoryInc = DMA_MemoryInc_Enable;
    dma->DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
    dma->DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
    dma->DMA_Mode = DMA_Mode_Circular;
    dma->DMA_Priority = DMA_Priority_High;
    dma->DMA_FIFOMode = DMA_FIFOMode_Disable;
    dma->DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
    dma->DMA_MemoryBurst = DMA_MemoryBurst_Single;
    dma->DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
    DMA_Init(DMA1_Stream5, dma);

    DMA_ITConfig(DMA1_Stream5, DMA_IT_TC, ENABLE);
    DMA_ITConfig(DMA1_Stream5, DMA_IT_HT, ENABLE);

    NVIC_InitTypeDef nvic[1];
    nvic->NVIC_IRQChannel = DMA1_Stream5_IRQn;
    nvic->NVIC_IRQChannelPreemptionPriority = 7;
    nvic->NVIC_IRQChannelSubPriority = 7;
    nvic->NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(nvic);
    DMA_Cmd(DMA1_Stream5, ENABLE);

    DAC_DMACmd(DAC_Channel_1, ENABLE);

    TIM_DeInit(TIM6);

    TIM_TimeBaseInitTypeDef    TIM_TimeBaseStructure;
    TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
    TIM_TimeBaseStructure.TIM_Period = 1749;
    TIM_TimeBaseStructure.TIM_Prescaler = 0;
    TIM_TimeBaseStructure.TIM_ClockDivision = 0;
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);

    TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update);

    TIM_Cmd(TIM6, ENABLE);


    return 0;
}
Exemplo n.º 16
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void DAC_SignalsGeneration(void)
{
    /*!< At this stage the microcontroller clock setting is already configured,
         this is done through SystemInit() function which is called from startup
         file (startup_stm32f30x.s) before to branch to application main.
         To reconfigure the default setting of SystemInit() function, refer to
         system_stm32f30x.c file
       */

    /* Preconfiguration before using DAC----------------------------------------*/
    DAC_Config();

    /* TIM2 configuration to trigger DAC */
    TIM_Config();

    /* Configures Key Button EXTI Line */
    STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);

    /* Infinite loop */
    while (1)
    {
        /* If the wave form is changed */
        if (WaveChange == 1)
        {
            /* Switch the selected waves forms according the Button status */
            if (SelectedWavesForm == 1)
            {
                /* The sine wave and the escalator wave has been selected */
                /* Sine Wave generator ---------------------------------------------*/

                /* DAC channel2 Configuration */
                DAC_DeInit();
                DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;
                DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
                DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;

                /* DAC Channel2 Init */
                DAC_Init(DAC_Channel_2, &DAC_InitStructure);

                /* Enable DAC Channel2 */
                DAC_Cmd(DAC_Channel_2, ENABLE);

                /* DMA2 channel3 configuration */
                DMA_DeInit(DMA2_Channel3);
                DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12R2_ADDRESS;
                DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&Sine12bit;
                DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
                DMA_InitStructure.DMA_BufferSize = 32;
                DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
                DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
                DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
                DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
                DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
                DMA_InitStructure.DMA_Priority = DMA_Priority_High;
                DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
                DMA_Init(DMA2_Channel3, &DMA_InitStructure);

                /* Enable DMA2 Channel3 */
                DMA_Cmd(DMA2_Channel3, ENABLE);

                /* Enable DMA for DAC Channel2 */
                DAC_DMACmd(DAC_Channel_2, ENABLE);

                /* Escalator Wave generator ----------------------------------------*/

                /* DAC channel1 Configuration */
                DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
                DAC_Init(DAC_Channel_1, &DAC_InitStructure);

                /* DMA2 channel4 configuration */
                DMA_DeInit(DMA2_Channel4);
                DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR8R1_ADDRESS;
                DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&Escalator8bit;
                DMA_InitStructure.DMA_BufferSize = 6;
                DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
                DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
                DMA_Init(DMA2_Channel4, &DMA_InitStructure);

                /* Enable DMA2 Channel4 */
                DMA_Cmd(DMA2_Channel4, ENABLE);

                /* Enable DAC1 Channel1: Once the DAC1 channel1 is enabled, PA.05 is
                   automatically connected to the DAC converter. */
                DAC_Cmd(DAC_Channel_1, ENABLE);

                /* Enable DMA for DAC Channel1 */
                DAC_DMACmd(DAC_Channel_1, ENABLE);
            }
            /* The triangle wave and the noise wave has been selected */
            else
            {
                /* Noise Wave generator --------------------------------------------*/

                /* DAC channel1 Configuration */
                DAC_DeInit();
                DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;
                DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_Noise;
                DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits11_0;
                DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
                DAC_Init(DAC_Channel_1, &DAC_InitStructure);

                /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.05 is
                   automatically connected to the DAC converter. */
                DAC_Cmd(DAC_Channel_1, ENABLE);

                /* Set DAC Channel1 DHR12L register */
                DAC_SetChannel1Data(DAC_Align_12b_L, 0x7FF0);

                /* Enable DAC channel1 wave generator */
                DAC_WaveGenerationCmd(DAC_Channel_1, DAC_Wave_Noise , ENABLE);

                /* Triangle Wave generator -----------------------------------------*/

                /* DAC channel2 Configuration */
                DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;
                DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_Triangle;
                DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_1023;
                DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
                DAC_Init(DAC_Channel_2, &DAC_InitStructure);

                /* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is
                   automatically connected to the DAC converter. */
                DAC_Cmd(DAC_Channel_2, ENABLE);

                /* Set DAC channel2 DHR12RD register */
                DAC_SetChannel2Data(DAC_Align_12b_R, 0x100);
            }
            WaveChange = !WaveChange;
        }
    }
}
Exemplo n.º 17
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f2xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f2xx.c file
     */

  /* Preconfiguration before using DAC----------------------------------------*/
  GPIO_InitTypeDef GPIO_InitStructure;

  /* DMA1 clock and GPIOA clock enable (to be used with DAC) */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1 | RCC_AHB1Periph_GPIOA, ENABLE);

  /* DAC Periph clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

  /* DAC channel 1 & 2 (DAC_OUT1 = PA.4)(DAC_OUT2 = PA.5) configuration */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* TIM6 Configuration ------------------------------------------------------*/
  TIM6_Config();

  /* Configures Key Button */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);

  while (1)
  {
    /* If the Key is pressed */
    if (KeyPressed != RESET)
    {
      DAC_DeInit();

      /* select waves forms according to the Key Button status */
      if (SelectedWavesForm == 1)
      {
        /* The sine wave and the escalator wave has been selected */

        /* Escalator Wave generator ------------------------------------------*/
        DAC_Ch1_EscalatorConfig();

        /* Sine Wave generator -----------------------------------------------*/
        DAC_Ch2_SineWaveConfig();

      }
      else
      {
        /* The triangle wave and the noise wave has been selected */

        /* Noise Wave generator ----------------------------------------------*/
        DAC_Ch1_NoiseConfig();

        /* Triangle Wave generator -------------------------------------------*/
        DAC_Ch2_TriangleConfig();
      }

      KeyPressed = RESET;
    }
  }
}
Exemplo n.º 18
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f0xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
     */ 

  /* Preconfiguration before using DAC----------------------------------------*/
  DAC_Config();
  
  /* TIM2 Periph clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
  
  /* Time base configuration */
  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); 
  TIM_TimeBaseStructure.TIM_Period = 0xFF;          
  TIM_TimeBaseStructure.TIM_Prescaler = 0x0;       
  TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;    
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

  /* TIM2 TRGO selection */
  TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);
  
  /* TIM2 enable counter */
  TIM_Cmd(TIM2, ENABLE);
  
  /* Configures Button GPIO and EXTI Line */
  STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI);

  /* Infinite loop */
  while (1)
  {
    /* If the wave form is changed */
    if (WaveChange == 1)
    {  
      /* Switch the selected waves forms according the Button status */
      if (SelectedWavesForm == 1)
      {
          /* The sine wave has been selected */
          /* Sine Wave generator ---------------------------------------------*/
          DAC_DeInit(); 
          
          /* DAC channel1 Configuration */
          DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;
          DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
          
          /* DMA channel3 Configuration */
          DMA_DeInit(DMA1_Channel3); 
          DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12R1_ADDRESS;
          DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&Sine12bit;
          DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
          DMA_InitStructure.DMA_BufferSize = 32;
          DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
          DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
          DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
          DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
          DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
          DMA_InitStructure.DMA_Priority = DMA_Priority_High;
          DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
          DMA_Init(DMA1_Channel3, &DMA_InitStructure);

          /* Enable DMA1 Channel3 */
          DMA_Cmd(DMA1_Channel3, ENABLE);

          /* DAC Channel1 Init */
          DAC_Init(DAC_Channel_1, &DAC_InitStructure);

          /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is 
             automatically connected to the DAC converter. */
          DAC_Cmd(DAC_Channel_1, ENABLE);

          /* Enable DMA for DAC Channel1 */
          DAC_DMACmd(DAC_Channel_1, ENABLE);
         
      }
          /* The Escalator wave has been selected */
       else
       {
         
          /* Escalator Wave generator -----------------------------------------*/
          DAC_DeInit();
          
          /* DAC channel1 Configuration */
          DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;
          DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
          
  
          /* DMA1 channel2 configuration */
          DMA_DeInit(DMA1_Channel3);

          DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR8R1_ADDRESS;
          DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&Escalator8bit;
          DMA_InitStructure.DMA_BufferSize = 6;
          DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
          DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
          DMA_Init(DMA1_Channel3, &DMA_InitStructure);
    
          /* Enable DMA1 Channel2 */
          DMA_Cmd(DMA1_Channel3, ENABLE);
    
          /* DAC channel1 Configuration */
          DAC_Init(DAC_Channel_1, &DAC_InitStructure);

          /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is 
             automatically connected to the DAC converter. */
          DAC_Cmd(DAC_Channel_1, ENABLE);

          /* Enable DMA for DAC Channel1 */
          DAC_DMACmd(DAC_Channel_1, ENABLE);
      }
      WaveChange = !WaveChange;
    }
  }
}
Exemplo n.º 19
0
/**
  * @brief  Save Demonstration context (GPIOs Configurations, peripherals,...).
  * @param  None
  * @retval None
  */
void IDD_Measurement_SaveContext(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
  EXTI_InitTypeDef EXTI_InitStructure;

  /* Deinitialize all peripherals used in the Demo */
  DAC_DeInit();
  ADC_DeInit(ADC1);
  DMA_DeInit(DMA1_Channel2);
  SPI_DeInit(SPI1);
  TIM_DeInit(TIM2);
  EXTI_DeInit();
  TIM_DeInit(TIM6);
  LCD_DeInit();
  SYSCFG_DeInit();
  I2C_DeInit(I2C1);
  COMP_DeInit();
    
  GPIOA_MODER = GPIOA->MODER;
  GPIOB_MODER = GPIOB->MODER;
  GPIOC_MODER = GPIOC->MODER;
  GPIOD_MODER = GPIOD->MODER;
  GPIOE_MODER = GPIOE->MODER;
  GPIOH_MODER = GPIOH->MODER;

  GPIOA_PUPDR = GPIOA->PUPDR;
  GPIOB_PUPDR = GPIOB->PUPDR;
  GPIOC_PUPDR = GPIOC->PUPDR;
  GPIOD_PUPDR = GPIOD->PUPDR;
  GPIOE_PUPDR = GPIOE->PUPDR;
  GPIOH_PUPDR = GPIOH->PUPDR;

  /* Configure all GPIO port pins in Analog Input mode */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  GPIO_Init(GPIOD, &GPIO_InitStructure);
  GPIO_Init(GPIOE, &GPIO_InitStructure);
  GPIO_Init(GPIOH, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = IDD_CNT_EN_PIN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(IDD_CNT_EN_GPIO_PORT, &GPIO_InitStructure);

  /* Configure IDD_CNT_EN pin as output push-pull ----------------------------*/
  GPIO_SetBits(IDD_CNT_EN_GPIO_PORT, IDD_CNT_EN_PIN);
  
  /* Connect Button EXTI Line to Button GPIO Pin */
  SYSCFG_EXTILineConfig(IDD_WAKEUP_EXTI_PORTSOURCE, IDD_WAKEUP_EXTI_PINSOURCE);

  /* Configure IDD_WAKEUP pin as input pull-down -----------------------------*/
  GPIO_InitStructure.GPIO_Pin = IDD_WAKEUP_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(IDD_WAKEUP_GPIO_PORT, &GPIO_InitStructure);

  /* Configure the IDD_WAKEUP EXTI Line */
  EXTI_ClearITPendingBit(IDD_WAKEUP_EXTI_LINE);

  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Line = IDD_WAKEUP_EXTI_LINE;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  /* Enable the EXTI Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = IDD_WAKEUP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);  
}
Exemplo n.º 20
0
/**
  * @brief  inicializace DAC
  * @param  DAC deskriptor
  * @retval None
  */
void DAC_init(PTO_DAC_InitTypeDef * p_DAC_desc)
{
  DAC_InitTypeDef            DAC_InitStructure;
  DMA_InitTypeDef            DMA_InitStructure;
	GPIO_InitTypeDef 					 GPIO_InitStructure;
	TIM_TimeBaseInitTypeDef    TIM_TimeBaseStructure;
	
	/* DMA2 clock enable (to be used with DAC) */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);

  /* DAC Periph clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

  /* GPIOA clock enable */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  
  /* Configure PA.04 (DAC_OUT1) as analog */
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
	
	/* TIM2 Periph clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
  
  /* Time base configuration */
  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
	
	if(0xFFFFFFFF/(20*p_DAC_desc->DAC_samplingFrequency) < 1) {
		TIM_TimeBaseStructure.TIM_Period = 1;          
	} else if(0xFFFFFFFF/(20*p_DAC_desc->DAC_samplingFrequency) > 0xFFFFFFFF) {
		TIM_TimeBaseStructure.TIM_Period = 0xFFFFFFFF;
	} else {
		TIM_TimeBaseStructure.TIM_Period = (uint32_t) 0xFFFFFFFF/(20*p_DAC_desc->DAC_samplingFrequency);//0x8C9;          
	}
  TIM_TimeBaseStructure.TIM_Prescaler = 0x00;       
  TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;    
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

  /* TIM2 TRGO selection */
  TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);
  
  /* TIM2 enable counter */
  TIM_Cmd(TIM2, ENABLE);
	
	/* DAC channel1 Configuration */
	DAC_DeInit(); 
	DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;
	DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
	DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits11_0;
	DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
	/* DAC Channel1 Init */
	DAC_Init(DAC_Channel_1, &DAC_InitStructure);
	
	/* Enable DAC Channel2 */
	DAC_Cmd(DAC_Channel_1, ENABLE);
	
	
	/* DMA2 channel3 configuration */
	DMA_DeInit(DMA2_Channel3); 
	DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12R1_ADDRESS;
	//DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&genSine;
	DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) p_DAC_desc->p_DAC_memory;
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
	DMA_InitStructure.DMA_BufferSize = p_DAC_desc->DAC_memorySize;//32;
	DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
	DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
	DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
	DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
	DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
	DMA_InitStructure.DMA_Priority = DMA_Priority_High;
	DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
	DMA_Init(DMA2_Channel3, &DMA_InitStructure);
	
	/* Enable DMA2 Channel3 */
	//DMA_Cmd(DMA2_Channel3, ENABLE);
	
	/* Enable DMA for DAC Channel2 */
	//DAC_DMACmd(DAC_Channel_1, ENABLE);
	dacState = DAC_IDLE;
}
Exemplo n.º 21
0
int main(void)
{
	WWDG_SetPrescaler(WWDG_Prescaler_8);
//init:
	for(k=0; k<VECSIZE; k++) //initialize output vector
	{
		DAC1ConvertedValue[k] = 0;
		DAC2ConvertedValue[k] = 0;
	}

//	init_filter(&ap_1);
//	init_filter(&ap_2);
//	init_filter(&ap_3);
//	init_filter(&ap_4);
	for(k = 0; k<nfilters; k++)
	{
		//init_filter(&filters[k]);
	}

//	ap_filter_coefs(&ap_1);
//	ap_filter_coefs(&ap_2);
//	ap_filter_coefs(&ap_3);
//	ap_filter_coefs(&ap_4);
	for(k = 0; k<nfilters; k++)
	{
		//ap_filter_coefs(&filters[k]);
	}
	for(k = 0; k<VECSIZE; k++)
	{
		vector_a[k] = 0.0;
		vector_b[k] = 0.0;
	}

	noise.add = 3;
	noise.mod = gsize;
	noise.mul = 1;
	noise.out = 0;

	noise2.add = 3;
	noise2.mod = gsize;
	noise2.mul = 1;
	noise2.out = 0;

	noise3.add = 3;
	noise3.mod = gsize;
	noise3.mul = 1;
	noise3.out = 0;

	saw.add = 1.0/800;
	saw.mul = 1;
	saw.out = 0;
	saw.prev_add = 0;
	saw.slew = 0.994;

    melody.add = 1.0/10000;
	melody.mul = 1;
	melody.out = 0;
	melody.prev_add = 0;
	melody.slew = 0.9994;

    harmony.add = 1.0/10000;
	harmony.mul = 1;
	harmony.out = 0;
	harmony.prev_add = 0;
	harmony.slew = 0.9994;

    drone.add = 1.0/10000;
	drone.mul = 1;
	drone.out = 0;
	drone.prev_add = 0;
	drone.slew = 0.999994;

    dronelo.add = 1.0/10000;
	dronelo.mul = 1;
	dronelo.out = 0;
	dronelo.prev_add = 0;
	dronelo.slew = 0.99994;


	for(k = 0; k<(nfilters*5); k++) //repeat coefs nfilters times
	{
		coefTable[k] = coef_single[(k%5)];
	}
	arm_biquad_cascade_df2T_init_f32(
			&S1,
			nfilters,
			&coefTable,
			&biquadState);

    DAC_DeInit();
	init_GPIOA();
    init_GPIOC();
    init_GPIOD();
    init_DMA1();
    init_DMA2();
    init_TIM2();
    init_TIM3();
    init_TIM4();
    init_TIM6();
    init_ADC3();
	init_DAC();
    ADC_SoftwareStartConv(ADC3);
    while (1)
    {
		counter++;
    }
}