/** * @brief Configures DAC channel 1 and channel 2 * @param None * @retval None */ void DAC_Config(void) { /* Enable GPIOA Periph clock --------------------------------------*/ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* Configure PA.04 (DAC_OUT1), PA.05 (DAC_OUT2) as analog */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_Init(GPIOA, &GPIO_InitStructure); /* DAC Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); /* DAC init struct configuration */ DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; /* DAC channel1 Configuration */ DAC_Init(DAC_Channel_1, &DAC_InitStructure); /* DAC channel2 Configuration */ DAC_Init(DAC_Channel_2, &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 DAC Channel2: Once the DAC channel2 is enabled, PA.05 is automatically connected to the DAC converter. */ DAC_Cmd(DAC_Channel_2, ENABLE); /* Enable DMA for DAC Channel2 */ DAC_DMACmd(DAC_Channel_2, ENABLE); }
void setup_dac(){ #if isUsingDevBoard //Setup GPIO RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); DAC_InitTypeDef DAC_InitStructure; /* DAC channel1 Configuration */ DAC_InitStructure.DAC_Trigger = DAC_Trigger_None; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits10_0; 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); DAC_Cmd(DAC_Channel_2, ENABLE); /* Set DAC Channel1 DHR12L register */ DAC_SetChannel1Data(DAC_Align_8b_R, 0x0000); DAC_SetChannel2Data(DAC_Align_8b_R, 0x0000); #else #endif }
/** * @brief DAC Channel2 Triangle and Channel1 Noise Configuration * @param None * @retval None */ static void DAC_Noise_TriangleConfig(void) { /* 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 */ DAC_Cmd(DAC_Channel_2, ENABLE); /* Set DAC channel2 DHR12RD register */ DAC_SetChannel2Data(DAC_Align_12b_R, 0x100); /* DAC channel1 Configuration */ DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_Noise; DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits10_0; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; DAC_Init(DAC_Channel_1, &DAC_InitStructure); /* Enable DAC Channel1 */ DAC_Cmd(DAC_Channel_1, ENABLE); /* Set DAC Channel1 DHR12L register */ DAC_SetChannel1Data(DAC_Align_12b_L, 0x7FF0); }
/** * @brief Configures the DAC. * @param None * @retval None */ void DAC_Configuration(void) { DAC_InitPara DAC_InitStructure; RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_DAC, ENABLE); /* DAC channel1 Configuration */ DAC_InitStructure.DAC_Trigger = DAC_TRIGGER_T2_TRIG; DAC_InitStructure.DAC_WaveType = DAC_WAVEGENE_NOISE; DAC_InitStructure.DAC_LFSRNoise_AmplitudeTriangle = DAC_LFSR_BITS9_0; DAC_InitStructure.DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE; DAC_Init(DAC_CHANNEL_1, &DAC_InitStructure); /* DAC channel2 Configuration */ DAC_InitStructure.DAC_Trigger = DAC_TRIGGER_T3_TRIG; DAC_InitStructure.DAC_LFSRNoise_AmplitudeTriangle = DAC_LFSR_BITS10_0; DAC_Init(DAC_CHANNEL_2, &DAC_InitStructure); /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is automatically connected to the DAC converter. */ DAC_Enable(DAC_CHANNEL_1, ENABLE); /* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is automatically connected to the DAC converter. */ DAC_Enable(DAC_CHANNEL_2, ENABLE); /* Set DAC dual channel DHR12RD register */ DAC_SetDualChannelData(DAC_ALIGN_12B_R, 0x7F0, 0x7F0); }
void DAC_ConfigurationInit() { DAC_InitTypeDef DAC_InitStruct; GPIO_InitTypeDef GPIO_InitStruct; RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE ); RCC_APB1PeriphClockCmd( RCC_APB1Periph_DAC, ENABLE ); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init( GPIOA, &GPIO_InitStruct ); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init( GPIOA, &GPIO_InitStruct ); DAC_InitStruct.DAC_Trigger = DAC_Trigger_Software; DAC_InitStruct.DAC_WaveGeneration = DAC_WaveGeneration_None; DAC_InitStruct.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0; DAC_InitStruct.DAC_OutputBuffer = DAC_OutputBuffer_Disable; DAC_Init( DAC_Channel_1, &DAC_InitStruct ); DAC_Init( DAC_Channel_2, &DAC_InitStruct ); DAC_Cmd( DAC_Channel_1, ENABLE ); DAC_Cmd( DAC_Channel_2, ENABLE ); DAC_SetChannel1Data( DAC_Align_12b_R, 0X0fFF); DAC_SoftwareTriggerCmd( DAC_Channel_1, ENABLE ); DAC_SetChannel1Data( DAC_Align_12b_R, 0X03FF); DAC_SoftwareTriggerCmd( DAC_Channel_2, ENABLE ); }
void TM_DAC_Init(TM_DAC_Channel_t DACx) { DAC_InitTypeDef DAC_InitStruct; uint16_t GPIO_Pin; /* Select proper GPIO pin */ if (DACx == TM_DAC1) { GPIO_Pin = GPIO_PIN_4; } else { GPIO_Pin = GPIO_PIN_5; } /* Initialize proper GPIO pin */ TM_GPIO_Init(GPIOA, GPIO_Pin, TM_GPIO_Mode_AN, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Fast); /* Enable DAC clock */ RCC->APB1ENR |= RCC_APB1ENR_DACEN; /* Set DAC options */ DAC_InitStruct.DAC_Trigger = DAC_Trigger_None; DAC_InitStruct.DAC_WaveGeneration = DAC_WaveGeneration_None; DAC_InitStruct.DAC_OutputBuffer = DAC_OutputBuffer_Enable; /* Init and enable proper DAC */ if (DACx == TM_DAC1) { DAC_Init(DAC_Channel_1, &DAC_InitStruct); /* Enable DAC channel 1 */ DAC->CR |= DAC_CR_EN1; } else { DAC_Init(DAC_Channel_2, &DAC_InitStruct); /* Enable DAC channel 2 */ DAC->CR |= DAC_CR_EN2; } }
void init_DACs(void) { // Now to output to some pin ofcourse, PA4 for example (routed to audio PA) // Enable clock to GPIOA RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); // Init the pins GPIO_InitTypeDef GPIOInit = {0, }; GPIOInit.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; // PA4 GPIOInit.GPIO_Mode = GPIO_Mode_AN; // Analog function GPIOInit.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIOInit); // Enable the clock to the DAC RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); DAC_InitTypeDef dacInit; memset( (void *)&dacInit, 0, sizeof(DAC_InitTypeDef) ); dacInit.DAC_Trigger = DAC_Trigger_None; dacInit.DAC_OutputBuffer = DAC_OutputBuffer_Disable; DAC_Init(DAC_Channel_1, &dacInit); DAC_Cmd(DAC_Channel_1, ENABLE); DAC_Init(DAC_Channel_2, &dacInit); DAC_Cmd(DAC_Channel_2, ENABLE); }
/** * @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_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* System Clocks Configuration */ RCC_Configuration(); /* 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 */ GPIO_Configuration(); /* TIM2 Configuration */ TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = 0xF; TIM_TimeBaseStructure.TIM_Prescaler = 0xF; 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); /* DAC channel1 Configuration */ DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_Triangle; DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_2047; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; DAC_Init(DAC_Channel_1, &DAC_InitStructure); /* DAC channel2 Configuration */ DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_1023; DAC_Init(DAC_Channel_2, &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 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 dual channel DHR12RD register */ DAC_SetDualChannelData(DAC_Align_12b_R, 0x100, 0x100); /* TIM2 enable counter */ TIM_Cmd(TIM2, ENABLE); while (1) { } }
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); }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* System Clocks Configuration */ RCC_Configuration(); /* 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 */ GPIO_Configuration(); /* TIM2 Configuration */ TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = 0xF; TIM_TimeBaseStructure.TIM_Prescaler = 0xF; 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); /* DAC channel1 Configuration */ DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_Triangle; DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_2047; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; DAC_Init(DAC_Channel_1, &DAC_InitStructure); /* DAC channel2 Configuration */ DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_1023; DAC_Init(DAC_Channel_2, &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 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 dual channel DHR12RD register */ DAC_SetDualChannelData(DAC_Align_12b_R, 0x100, 0x100); /* TIM2 enable counter */ TIM_Cmd(TIM2, ENABLE); while (1) { } }
void analogout_init(dac_t *obj, PinName pin) { static uint8_t dac_initialized = 0; /* init in-memory structure */ analogout_preinit(obj, pin); if (!dac_initialized) { /* Initialize the DAC. Will disable both DAC channels, so should only be done once */ /* Use default settings */ CMU_ClockEnable(cmuClock_DAC0, true); DAC_Init_TypeDef init = DAC_INIT_DEFAULT; /* Calculate the DAC clock prescaler value that will result in a DAC clock * close to 500kHz. Second parameter is zero. This uses the current HFPERCLK * frequency instead of setting a new one. */ init.prescale = DAC_PrescaleCalc(500000, REFERENCE_FREQUENCY); /* Set reference voltage to VDD */ init.reference = dacRefVDD; DAC_Init(obj->dac, &init); dac_initialized = 1; } /* Use default channel settings */ DAC_InitChannel_TypeDef initChannel = DAC_INITCHANNEL_DEFAULT; DAC_InitChannel(obj->dac, &initChannel, obj->channel); }
void main(void) //using 0 { EA = 0; //CFG845=0x1;//enable xram PLLCON&=PLLCON_VAL;//настройка частоты процессора //-------printf-------- // T3CON = T3CON_VAL; // // T3FD = T3FD_VAL; // SCON =0x52; //0x53; //--------------------- Timer1_Initialize(); //таймер генерации частоты Frequency_Init(); DAC_Init(); WDT_Init(WDT_2000);//включить сторожевой таймер EA=1; while(1) { Frequency_Measure_Process(); WDT_Clear(); } }
/** * Configure DAC output */ void dacSetup(){ DAC_InitTypeDef DAC_InitStructure; /* Enable GPIOA clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); /* Configure PA.04 (DAC_OUT1) in analog mode */ configureAnalogOutput(GPIOA, GPIO_Pin_4); /* Configure PA.05 (DAC_OUT2) in analog mode */ /* configureAnalogOutput(GPIOA, GPIO_Pin_5); */ /* Enable DAC clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); /* DAC channel Configuration */ DAC_StructInit(&DAC_InitStructure); DAC_InitStructure.DAC_Trigger = DAC_Trigger_None; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; /* DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits10_0; */ DAC_Init(DAC_Channel_1, &DAC_InitStructure); /* DAC_Init(DAC_Channel_2, &DAC_InitStructure); */ /* Enable DAC Channels */ DAC_Cmd(DAC_Channel_1, ENABLE); /* DAC_Cmd(DAC_Channel_2, ENABLE); */ }
/** \fn void piezo_init() * \brief Initialize pin as analog output. Initialize DAC. Count sine discrete aproximation. * */ void piezo_init() { uint32_t i; DAC_InitTypeDef DAC_InitStruct; // initialize PA5 jako analogovy vystup GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = 1<<5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); // enable clock for DA converter RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); // initialize DAC2 DAC_StructInit(&DAC_InitStruct); DAC_Init(DAC_Channel_2,&DAC_InitStruct); DAC_Cmd(DAC_Channel_2, ENABLE); // count sine samples for(i=0; i<SINE_SAMPLES_COUNT; i++) { sine_samples[i] = ((sin(((2*M_PI*(double)i)/SINE_SAMPLES_COUNT) -M_PI/2)+1)*(double)0xFFF)/2; } }
/** * @brief Configures the DAC channel 1 with output buffer enabled. * @param None * @retval None */ void DAC_Config(void) { DAC_InitTypeDef DAC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIOA clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* Configure PA.04 (DAC_OUT1) in analog mode -------------------------*/ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Enable DAC clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); /* DAC channel1 Configuration */ DAC_InitStructure.DAC_Trigger = DAC_Trigger_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); }
// **************Sound_Init********************* // Initialize Systick periodic interrupts // Also calls DAC_Init() to initialize DAC // Input: none // Output: none void Sound_Init(void){ DAC_Init(); // initialise DAC NVIC_ST_CTRL_R = 0; // disable SysTick NVIC_ST_CURRENT_R = 0; // any write to current clears it NVIC_SYS_PRI3_R = NVIC_SYS_PRI3_R&0x00FFFFFF; // priority 0 NVIC_ST_CTRL_R = 0x07; // enable SysTic }
int main(void){ TExaS_Init(SW_PIN_PE3210,DAC_PIN_PB3210,ScopeOn); // bus clock at 80 MHz //Timer0A_Init(&songTask, F80HZ); Piano_Init(); Sound_Init(0); DAC_Init(); Heartbeat_Init(); // other initialization EnableInterrupts(); uint32_t input; while(1){ GPIO_PORTF_DATA_R ^= 0x04; input = Piano_In(); if (input == 0x04){ Sound_Play(A); } else if (input == 0x02){ Sound_Play(C); } else if (input == 0x01){ Sound_Play(Eb); } else if (input == 0x07){ Sound_Play(A); } else { Sound_Play(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
// *************************** Capture image dimensions out of BMP********** int main(void){ TExaS_Init(SSI0_Real_Nokia5110_Scope); // set system clock to 80 MHz Output_Init(); ADC0_Init(); DAC_Init(); SysTick_Init(); Menu_Init(); Sound_Init(); UART1_Init(); Button0_Init(); Timer0_Init(Play, 80000000/11025); // 11.025 kHz 80000000/11025 Timer1_Init(Master_Funk, 80000000/60); //Timer2_Init(SomeUART function, high speed); //for UART /* ST7735_FillScreen(0x0000); // set screen to black ST7735_SetCursor(1, 1); ST7735_OutString("GAME OVER"); ST7735_SetCursor(1, 2); ST7735_OutString("Nice try,"); ST7735_SetCursor(1, 3); ST7735_OutString("Earthling!"); ST7735_SetCursor(2, 4); LCD_OutDec(1234); */ while(1){ } }
void audio_init(void) { // DAC peripheral clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); // DAC channel 2 (DAC_OUT2 = PA.5) configuration GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); // DAC channel2 Configuration DAC_InitTypeDef DAC_InitStructure; 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_2, &DAC_InitStructure); // Enable DAC Channel2 DAC_Cmd(DAC_Channel_2, ENABLE); // from now on use DAC_SetChannel2Data to trigger a conversion sample_buf_in = 0; sample_buf_out = 0; // enable interrupt // Python interface mp_obj_t m = mp_obj_new_module(qstr_from_str_static("audio")); rt_store_attr(m, qstr_from_str_static("dac"), rt_make_function_n(1, pyb_audio_dac)); rt_store_attr(m, qstr_from_str_static("is_full"), rt_make_function_n(0, pyb_audio_is_full)); rt_store_attr(m, qstr_from_str_static("fill"), rt_make_function_n(1, pyb_audio_fill)); rt_store_name(qstr_from_str_static("audio"), m); }
int main(void){ // Real Lab13 // for the real board grader to work // you must connect PD3 to your DAC output TExaS_Init(SW_PIN_PE3210, DAC_PIN_PB3210,ScopeOn); // activate grader and set system clock to 80 MHz // PortE used for piano keys, PortB used for DAC Sound_Init(); // initialize SysTick timer and DAC Piano_Init(); EnableInterrupts(); // enable after all initialization are done DAC_Init(); while(1){ volatile unsigned long current_switch; current_switch = Piano_In(); if (current_switch == 0x01){ EnableInterrupts(); Sound_Tone(4780); } else if (current_switch == 0x02){ EnableInterrupts(); Sound_Tone(4259); } else if (current_switch == 0x04){ EnableInterrupts(); Sound_Tone(3794); } else if (current_switch == 0x08){ EnableInterrupts(); Sound_Tone(3189); } // else if (current_switch == 0x00){ // Sound_Off(); // DisableInterrupts(); // } delay(10); } }
/** * @brief Configures DAC channel 1 * @param None * @retval None */ void DAC_Config(void) { /* Enable GPIOA Periph clock --------------------------------------*/ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* Configure PA.04 DAC_OUT as analog */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_Init(GPIOA, &GPIO_InitStructure); /* DAC Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); /* Fill DAC InitStructure */ DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; /* 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); }
/**************************************************************************//** * @brief DAC_setup * Configures the DAC *****************************************************************************/ void DAC_setup(void) { /* Enable necessary clocks */ CMU_ClockEnable(cmuClock_DAC0, true); /* Use default settings */ DAC_Init_TypeDef init = DAC_INIT_DEFAULT; DAC_InitChannel_TypeDef initChannel = DAC_INITCHANNEL_DEFAULT; /* Calculate the DAC clock prescaler value that will result in a DAC clock * close to 500kHz. Second parameter is zero, if the HFPERCLK value is 0, the * function will check what the current value actually is. */ init.prescale = DAC_PrescaleCalc(500000, 0); /* Set reference voltage to Vdd */ init.reference = dacRefVDD; /* Enable PRS triggered conversion (channel 5) */ initChannel.prsEnable = true; initChannel.prsSel = dacPRSSELCh5; /* Initialize DAC and DAC channel 0 */ DAC_Init(DAC0, &init); DAC_InitChannel(DAC0, &initChannel, 0); /* Enable DAC channel 0, located on pin PB11 */ DAC_Enable(DAC0, 0, true); }
void analogout_init(dac_t *obj, PinName pin) { /* init in-memory structure */ obj->dac = (DAC_TypeDef *) pinmap_peripheral(pin, PinMap_DAC); MBED_ASSERT((int) obj->dac != NC); obj->channel = pin_location(pin, PinMap_DAC); MBED_ASSERT((int) obj->channel != NC); pin_mode(pin, Disabled); if (!dac_initialized) { /* Initialize the DAC. Will disable both DAC channels, so should only be done once */ /* Use default settings */ CMU_ClockEnable(cmuClock_DAC0, true); DAC_Init_TypeDef init = DAC_INIT_DEFAULT; /* Calculate the DAC clock prescaler value that will result in a DAC clock * close to 500kHz. Second parameter is zero. This uses the current HFPERCLK * frequency instead of setting a new one. */ init.prescale = DAC_PrescaleCalc(500000, REFERENCE_FREQUENCY); /* Set reference voltage to VDD */ init.reference = dacRefVDD; DAC_Init(obj->dac, &init); dac_initialized = 1; } /* Use default channel settings */ DAC_InitChannel_TypeDef initChannel = DAC_INITCHANNEL_DEFAULT; initChannel.enable = true; DAC_InitChannel(obj->dac, &initChannel, obj->channel); }
static void DAC1_Configuration(void) { // Timer2 trig configuration as Trigger TIM2_Trig_Configuration(); /* DAC Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); // GPIO : PIN Init GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; // (DAC0 => PA04) GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOA, &GPIO_InitStructure); // DAC channel1 Configuration DAC_InitTypeDef DAC_InitStructure; DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_Triangle; DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_2047; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; // Init channel 1 DAC_Init(DAC_Channel_1, &DAC_InitStructure); // Enable channel 1 DAC_Cmd(DAC_Channel_1, ENABLE); }
void Dac1_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; DAC_InitTypeDef DAC_InitType; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE ); //使能PORTA通道时钟 RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE ); //使能DAC通道时钟 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; // 端口配置 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; //模拟输入 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); //GPIO_SetBits(GPIOA,GPIO_Pin_4) ;//PA.4 输出高 DAC_InitType.DAC_Trigger=DAC_Trigger_None; //不使用触发功能 TEN1=0 DAC_InitType.DAC_WaveGeneration=DAC_WaveGeneration_None;//不使用波形发生 DAC_InitType.DAC_LFSRUnmask_TriangleAmplitude=DAC_LFSRUnmask_Bit0;//屏蔽、幅值设置 DAC_InitType.DAC_OutputBuffer=DAC_OutputBuffer_Disable ; //DAC1输出缓存关闭 BOFF1=1 DAC_Init(DAC_Channel_1,&DAC_InitType); //初始化DAC通道1 DAC_Cmd(DAC_Channel_1, ENABLE); //使能DAC1 DAC_SetChannel1Data(DAC_Align_12b_R, 0); //12位右对齐数据格式设置DAC值 }
void analogout_init(dac_t *obj, PinName pin) { DAC_TypeDef *dac; DAC_InitTypeDef DAC_InitStructure; // Get the peripheral name (DAC_1, ...) from the pin and assign it to the object obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); if (obj->dac == (DACName)NC) { error("DAC pin mapping failed"); } dac = (DAC_TypeDef *)(obj->dac); // Configure GPIO pinmap_pinout(pin, PinMap_DAC); // Save the channel for future use obj->pin = pin; // Enable DAC clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); // Configure and enable DAC channel DAC_StructInit(&DAC_InitStructure); DAC_Init(dac, DAC_Channel_1, &DAC_InitStructure); DAC_Cmd(dac, DAC_Channel_1, ENABLE); analogout_write_u16(obj, 0); }
void DAC2_init(void) { GPIO_InitTypeDef GPIO_InitStructure; DAC_InitTypeDef DAC_InitStructure; // Enable clocks for port A and DAC RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); // Set up PA.5 as DAC channel 2 output GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); /* DAC channel 2 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_2, &DAC_InitStructure); /* Enable DAC Channel 2 */ DAC_Cmd(DAC_Channel_2, ENABLE); }
void DacInit(void) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); 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_InitTypeDef DAC_InitStructure; DAC_StructInit(&DAC_InitStructure); DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; DAC_Init(DAC_Channel_1, &DAC_InitStructure); DAC_Cmd(DAC_Channel_1, ENABLE); DAC_SetChannel1Data(DAC_Align_12b_R, DAC_ZERO); }
void DAC_setup(void) { /* Define DAC settings */ DAC_Init_TypeDef init = { dacRefresh8, /* Refresh every 8 prescaled cycles. */ \ dacRef1V25, /* 1.25V internal reference. */ \ dacOutputPinADC, /* Output to pin and ADC. */ \ dacConvModeContinuous, /* Continuous mode. */ \ 0, /* No prescaling. */ \ false, /* Do not enable low pass filter. */ \ false, /* Do not reset prescaler on ch0 start. */ \ false, /* DAC output enable always on. */ \ false, /* Disable sine mode. */ \ false /* Single ended mode. */ \ }; DAC_InitChannel_TypeDef initChannel = DAC_INITCHANNEL_DEFAULT; /* Calculate the DAC clock prescaler value that will result in a DAC clock * close to 500kHz. Second parameter is zero, if the HFPERCLK value is 0, the * function will check what the current value actually is. */ init.prescale = DAC_PrescaleCalc(500000, 0); /* Set reference voltage to vdd.*/ init.reference = dacRefVDD; /* Initialize the DAC and DAC channel. */ DAC_Init(DAC0, &init); /*Initialize DAC channel 0.*/ DAC_InitChannel(DAC0, &initChannel, 0); }