コード例 #1
0
ファイル: piezo.c プロジェクト: NexusIF/ProjectsBackup
/**	\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;
    }
}
コード例 #2
0
ファイル: analogout_api.c プロジェクト: allankliu/mbed
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);
}
コード例 #3
0
ファイル: armcontrol.c プロジェクト: kozakahi/OwlWare
/** 
 * 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); */
}
コード例 #4
0
ファイル: dac.c プロジェクト: alxsh/balmer-usb-sdr
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);
}
コード例 #5
0
ファイル: dac.c プロジェクト: thegeek82000/rlc-meter-balmer-1
void DacInit(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	DAC_InitTypeDef DAC_InitStructure;

	DacSinusCalculate();

	RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
	RCC_AHBPeriphClockCmd(GENERATOR_PIN_CLK, ENABLE);
	RCC_APB1PeriphClockCmd(GENERATOR_TIMER_CLK, ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

	GPIO_StructInit(&GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin = GENERATOR_PIN;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_Init(GENERATOR_PORT, &GPIO_InitStructure);

	DAC_StructInit(&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_1, &DAC_InitStructure);

	//delay_us(100);
	DAC_Cmd(DAC_Channel_1, ENABLE);
	DAC_SetChannel1Data(DAC_Align_12b_R, DAC_ZERO);
}
コード例 #6
0
ファイル: stm32f4_dacduc.c プロジェクト: fl04t/codec2
static void dac2_config(void)
{
  DAC_InitTypeDef  DAC_InitStructure;
  DMA_InitTypeDef DMA_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;

  /* DAC channel 2 Configuration (see notes in dac1_config() above) */

  DAC_StructInit(&DAC_InitStructure);
  DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO;
  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
  DAC_Init(DAC_Channel_2, &DAC_InitStructure);

  /* DMA1_Stream6 channel7 configuration **************************************/

  DMA_DeInit(DMA1_Stream6);
  DMA_InitStructure.DMA_Channel = DMA_Channel_7;
  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)DAC_DHR12R2_ADDRESS;
  DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)dac2_buf;
  DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
  DMA_InitStructure.DMA_BufferSize = DAC_BUF_SZ;
  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_FIFOMode = DMA_FIFOMode_Disable;
  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
  DMA_Init(DMA1_Stream6, &DMA_InitStructure);

  /* Enable DMA Half & Complete interrupts */

  DMA_ITConfig(DMA1_Stream6, DMA_IT_TC | DMA_IT_HT, ENABLE);

  /* Enable the DMA Stream IRQ Channel */

  NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream6_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  /* Enable DMA1_Stream6 */

  DMA_Cmd(DMA1_Stream6, ENABLE);

  /* Enable DAC Channel 2 */

  DAC_Cmd(DAC_Channel_2, ENABLE);

  /* Enable DMA for DAC Channel 2 */

  DAC_DMACmd(DAC_Channel_2, ENABLE);

}
コード例 #7
0
ファイル: dac.c プロジェクト: matejx/stm32f10x_lib
/**
@brief Init DAC.
@param[in]	n		DAC channel
*/
void dac_init(uint8_t n)
{
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

	DAC_InitTypeDef daci;
	DAC_StructInit(&daci);
    DAC_Init(n == 1 ? DAC_Channel_1 : DAC_Channel_2, &daci);
	DAC_Cmd(n == 1 ? DAC_Channel_1 : DAC_Channel_2, ENABLE);

	GPIO_InitTypeDef iotd;
	GPIO_StructInit(&iotd);
	iotd.GPIO_Pin = n == 1 ? GPIO_Pin_4 : GPIO_Pin_5;
	iotd.GPIO_Mode = GPIO_Mode_AIN;
	GPIO_Init(GPIOA, &iotd);
}
コード例 #8
0
ファイル: MotorPort.c プロジェクト: KHIEM2812/mySTMlib
inline void Pin5DAC2Config0(void) {
	GPIO_InitTypeDef GPIO_InitStructure;
	DAC_InitTypeDef DAC_InitStructure;

	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

	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_StructInit(&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);

	DAC_Cmd(DAC_Channel_2, ENABLE);
}
コード例 #9
0
/**
  * @brief  Configures the DAC channel 1 with output buffer enabled.
  * @param  None
  * @retval None
  */
void DAC_Config(void)
{

  /* Init Structure definition */
  DAC_InitTypeDef  DAC_InitStructure;
  
  /* DAC clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

  /* Fill DAC InitStructure */
  DAC_StructInit(&DAC_InitStructure);
  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);
  
  /* Set DAC Channel1 DHR register: DAC_OUT1 = (3.3 * 2000) / 4095 ~ 1.61 V */
  DAC_SetChannel1Data(DAC_Align_12b_R, 2000);
}
コード例 #10
0
ファイル: dac.cpp プロジェクト: fin-kerr/OpenSoundModule
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
}
コード例 #11
0
ファイル: stm32f4_dacduc.c プロジェクト: fl04t/codec2
static void dac1_config(void)
{
  DAC_InitTypeDef  DAC_InitStructure;
  DMA_InitTypeDef  DMA_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;

  /* DAC channel 1 Configuration */

  /*
     This line fixed a bug that cost me 5 days, bad wave amplitude
     value, and some STM32F4 periph library bugs caused triangle wave
     geneartion to be enable resulting in a low level tone on the
     SM1000, that we thought was caused by analog issues like layour
     or power supply biasing
  */
  DAC_StructInit(&DAC_InitStructure);

  DAC_InitStructure.DAC_Trigger = DAC_Trigger_T7_TRGO;
  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;

  /*External buffering is needed to get nice square samples at Fs=2Mhz. See DM00129215.pdf */
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
  DAC_Init(DAC_Channel_1, &DAC_InitStructure);

  /* DMA1_Stream5 channel7 configuration **************************************/
  /* Table 35 page 219 of the monster data sheet */

  DMA_DeInit(DMA1_Stream5);
  DMA_InitStructure.DMA_Channel = DMA_Channel_7;
  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)DAC_DHR12R1_ADDRESS;
  DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)dac1_buf;
  DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
  DMA_InitStructure.DMA_BufferSize = DAC_DUC_BUF_SZ;
  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_FIFOMode = DMA_FIFOMode_Disable;
  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
  DMA_Init(DMA1_Stream5, &DMA_InitStructure);

  /* Enable DMA Half & Complete interrupts */

  DMA_ITConfig(DMA1_Stream5, DMA_IT_TC | DMA_IT_HT, ENABLE);

  /* Enable the DMA Stream IRQ Channel */

  NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream5_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  /* Enable DMA1_Stream5 */

  DMA_Cmd(DMA1_Stream5, ENABLE);

  /* Enable DAC Channel 1 */

  DAC_Cmd(DAC_Channel_1, ENABLE);

  /* Enable DMA for DAC Channel 1 */

  DAC_DMACmd(DAC_Channel_1, ENABLE);
}
コード例 #12
0
ファイル: Audio.c プロジェクト: trstephen/alarmclock
void InitializeAudio(int plln, int pllr, int i2sdiv, int i2sodd) {
	GPIO_InitTypeDef  GPIO_InitStructure;
	DAC_InitTypeDef 	DAC_InitStruct;
	TIM_TimeBaseInitTypeDef TIM_InitStruct;

	// Initialize state.
	CallbackFunction = NULL;
	CallbackContext = NULL;
	NextBufferSamples = NULL;
	NextBufferLength = 0;
	BufferNumber = 0;
	DMARunning = false;
    volatile int i;

	// Turn on peripherals.
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);

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





			TIM_TimeBaseStructInit(&TIM_InitStruct);
			TIM_InitStruct.TIM_Period	= 90;	//approx 44khz
			TIM_InitStruct.TIM_Prescaler = 20;
			TIM_TimeBaseInit(TIM6, &TIM_InitStruct);

			/* TIM2 TRGO selection */
			TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update);

		// Enable GPIO port A4 as an analog output
		//
			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);

		//
		// Configure DAC channel 1
		//
			DAC_StructInit( &DAC_InitStruct );
			DAC_InitStruct.DAC_WaveGeneration = DAC_WaveGeneration_None;
			DAC_InitStruct.DAC_Trigger = DAC_Trigger_T6_TRGO;
			DAC_InitStruct.DAC_OutputBuffer = DAC_OutputBuffer_Enable ;
			DAC_Init(DAC_Channel_1, &DAC_InitStruct );

			//
			// Enable DAC channel 1
			//
	//		DMAEnable();

			NVIC_InitTypeDef      NVIC_InitStructure;
			NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream5_IRQn;
			NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 4;
			NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
			NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
			NVIC_Init(&NVIC_InitStructure);

}
コード例 #13
0
ファイル: IOSTM.cpp プロジェクト: g4klx/MMDVM
void CIO::startInt()
{
  if ((ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) != RESET))
    io.interrupt();

  // ADC1   PA0   analog input
  // ADC2   PA1   analog input
  // DAC1   PA4   analog output
  
  // Init the ADC
  GPIO_InitTypeDef        GPIO_InitStruct;
  ADC_InitTypeDef         ADC_InitStructure;
  ADC_CommonInitTypeDef   ADC_CommonInitStructure;

  GPIO_StructInit(&GPIO_InitStruct);
  ADC_CommonStructInit(&ADC_CommonInitStructure);
  ADC_StructInit(&ADC_InitStructure);

  // Enable ADC clock
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
#if defined(SEND_RSSI_DATA)
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, ENABLE);
#else
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
#endif
  
  // For ADC1 on PA0, ADC2 on PA1
#if defined(SEND_RSSI_DATA)
  GPIO_InitStruct.GPIO_Pin  = GPIO_Pin_0 | GPIO_Pin_1;
#else
  GPIO_InitStruct.GPIO_Pin  = GPIO_Pin_0;
#endif
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOA, &GPIO_InitStruct);

  // Init ADCs in dual mode, div clock by two
  ADC_CommonInitStructure.ADC_Mode             = ADC_DualMode_RegSimult;
  ADC_CommonInitStructure.ADC_Prescaler        = ADC_Prescaler_Div2;
  ADC_CommonInitStructure.ADC_DMAAccessMode    = ADC_DMAAccessMode_Disabled;
  ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
  ADC_CommonInit(&ADC_CommonInitStructure);

  // Init ADC1 and ADC2: 12bit, single-conversion
  ADC_InitStructure.ADC_Resolution           = ADC_Resolution_12b;
  ADC_InitStructure.ADC_ScanConvMode         = DISABLE;
  ADC_InitStructure.ADC_ContinuousConvMode   = DISABLE;
  ADC_InitStructure.ADC_ExternalTrigConvEdge = 0;
  ADC_InitStructure.ADC_ExternalTrigConv     = 0;
  ADC_InitStructure.ADC_DataAlign            = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfConversion      = 1;

  ADC_Init(ADC1, &ADC_InitStructure);

  ADC_EOCOnEachRegularChannelCmd(ADC1, ENABLE);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_3Cycles);

  // Enable ADC1
  ADC_Cmd(ADC1, ENABLE);

#if defined(SEND_RSSI_DATA)
  ADC_Init(ADC2, &ADC_InitStructure);

  ADC_EOCOnEachRegularChannelCmd(ADC2, ENABLE);
  ADC_RegularChannelConfig(ADC2, ADC_Channel_1, 1, ADC_SampleTime_3Cycles);

  // Enable ADC2
  ADC_Cmd(ADC2, ENABLE);
#endif

  // Init the DAC
  DAC_InitTypeDef DAC_InitStructure;

  GPIO_StructInit(&GPIO_InitStruct);
  DAC_StructInit(&DAC_InitStructure);

  // GPIOA & D clock enable
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

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

  // GPIO CONFIGURATION of DAC Pins
  GPIO_InitStruct.GPIO_Pin   = GPIO_Pin_4;
  GPIO_InitStruct.GPIO_Mode  = GPIO_Mode_AN;
  GPIO_InitStruct.GPIO_PuPd  = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStruct);

  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_Cmd(DAC_Channel_1, ENABLE);

  // Init the timer
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

  TIM_TimeBaseInitTypeDef timerInitStructure;
  TIM_TimeBaseStructInit (&timerInitStructure);
  timerInitStructure.TIM_Prescaler         = 1749;  // 24 kHz
  timerInitStructure.TIM_CounterMode       = TIM_CounterMode_Up;
  timerInitStructure.TIM_Period            = 1;
  timerInitStructure.TIM_ClockDivision     = TIM_CKD_DIV1;
  timerInitStructure.TIM_RepetitionCounter = 0;
  TIM_TimeBaseInit(TIM2, &timerInitStructure);
  TIM_Cmd(TIM2, ENABLE);
  TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);

  NVIC_InitTypeDef nvicStructure;
  nvicStructure.NVIC_IRQChannel                   = TIM2_IRQn;
  nvicStructure.NVIC_IRQChannelPreemptionPriority = 0;
  nvicStructure.NVIC_IRQChannelSubPriority        = 1;
  nvicStructure.NVIC_IRQChannelCmd                = ENABLE;
  NVIC_Init(&nvicStructure);

  GPIO_ResetBits(PORT_COSLED, PIN_COSLED);
  GPIO_SetBits(PORT_LED, PIN_LED);
}
コード例 #14
0
DAC_TIM6Class::DAC_TIM6Class(){
	waveBuffer = malloc(sizeof(uint16_t) * WAVE_MEMORY_LENGTH);
	if(waveBuffer==NULL){
		while(1){}
	}
	for(int i=0;i<WAVE_MEMORY_LENGTH;i++){
		waveBuffer[i] = 2048+1024*sinf(2*M_PI*i/WAVE_MEMORY_LENGTH);
	}
	
	
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
	/////////////////////////////////////
	//GPIO
	/////////////////////////////////////
	GPIO_InitTypeDef gpioa4_5;
	GPIO_StructInit(&gpioa4_5);
	gpioa4_5.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
	gpioa4_5.GPIO_Mode = GPIO_Mode_AN;
	gpioa4_5.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_Init(GPIOA,&gpioa4_5);
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC,ENABLE);
	/////////////////////////////////////
	//DAC
	/////////////////////////////////////
	DAC_InitTypeDef dac1;
	DAC_StructInit(&dac1);
	dac1.DAC_LFSRUnmask_TriangleAmplitude =DAC_LFSRUnmask_Bits11_0;
	dac1.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
	dac1.DAC_Trigger = DAC_Trigger_T6_TRGO;
	dac1.DAC_WaveGeneration = DAC_WaveGeneration_None;
	DAC_Init(DAC_Channel_1,&dac1);
	
	DAC_SetDualChannelData(DAC_Align_12b_R,0,0);
	DAC_Cmd(DAC_Channel_1,ENABLE);
	
	DAC_DMACmd(DAC_Channel_1,ENABLE);
	
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,ENABLE);
	TIM_TimeBaseInitTypeDef timebase;
	timebase.TIM_ClockDivision = TIM_CKD_DIV1;
	timebase.TIM_CounterMode = TIM_CounterMode_Up;
	timebase.TIM_Prescaler = 168-1;
	timebase.TIM_Period = 1;
	TIM_TimeBaseInit(TIM6,&timebase);
	
	TIM6->CR2 = 0x20;	//MasterModeSelection
	
	TIM_ITConfig(TIM6,TIM_IT_Update,ENABLE);
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE);
	
	DMA_InitTypeDef dma1_5;
	DMA_StructInit(&dma1_5);
	dma1_5.DMA_PeripheralBaseAddr = (uint32_t)&(DAC->DHR12R1);
	dma1_5.DMA_Memory0BaseAddr = (uint32_t)waveBuffer;
	dma1_5.DMA_DIR = DMA_DIR_MemoryToPeripheral;
	dma1_5.DMA_BufferSize = WAVE_MEMORY_LENGTH;
	dma1_5.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
	dma1_5.DMA_MemoryInc = DMA_MemoryInc_Enable;
	dma1_5.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
	dma1_5.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
	dma1_5.DMA_Mode = DMA_Mode_Circular;
	dma1_5.DMA_Priority = DMA_Priority_VeryHigh;
	dma1_5.DMA_Channel = DMA_Channel_7;
	DMA_Init(DMA1_Stream5,&dma1_5);
	
	DMA_Cmd(DMA1_Stream5,ENABLE);
	
	
	TIM_Cmd(TIM6,ENABLE);
}
コード例 #15
0
ファイル: lte-1202-0046.c プロジェクト: miaofng/ulp
void ict_Init(void)
{
	led_Init();
	led_flash(LED_GREEN);

	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
	GPIO_InitTypeDef GPIO_InitStructure;
	ADC_InitTypeDef ADC_InitStructure;
	DAC_InitTypeDef DAC_InitStructure;

	RCC_ADCCLKConfig(RCC_PCLK2_Div8); /*72Mhz/8 = 9Mhz*/
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE| RCC_APB2Periph_GPIOD|
		RCC_APB2Periph_GPIOC| RCC_APB2Periph_GPIOA, ENABLE);

	// IO config

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
	GPIO_Init(GPIOE, &GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_Init(GPIOD, &GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_Init(GPIOC, &GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_4|
		GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	// DAC config
	DAC_StructInit(&DAC_InitStructure);
	DAC_Init(DAC_Channel_1, &DAC_InitStructure);
	DAC_Cmd(DAC_Channel_1, ENABLE);

	DAC_StructInit(&DAC_InitStructure);
	DAC_Init(DAC_Channel_2, &DAC_InitStructure);
	DAC_Cmd(DAC_Channel_2, ENABLE);

	/* ADC1 config, Power Ouput Voltage sampling,
	V1 = ADC1_CH2 = PA2 = ADC123_IN2
	V2 = ADC2_CH7 = PA7 = ADC12_IN7
	*/
	ADC_DeInit(ADC1);
	ADC_StructInit(&ADC_InitStructure);
	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
	ADC_InitStructure.ADC_ScanConvMode = ENABLE;
	ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
	ADC_InitStructure.ADC_NbrOfChannel = 0;
	ADC_Init(ADC1, &ADC_InitStructure);

	ADC_InjectedSequencerLengthConfig(ADC1, 4);
	ADC_InjectedChannelConfig(ADC1, ADC_Channel_2, 1, ADC_SampleTime_55Cycles5); //9Mhz/(71.5 + 12.5) = 107.1Khz
	ADC_InjectedChannelConfig(ADC1, ADC_Channel_7, 2, ADC_SampleTime_55Cycles5);
	ADC_InjectedChannelConfig(ADC1, ADC_Channel_1, 3, ADC_SampleTime_55Cycles5); //I0
	ADC_InjectedChannelConfig(ADC1, ADC_Channel_6, 4, ADC_SampleTime_55Cycles5); //I1
	ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_None);
	ADC_Cmd(ADC1, ENABLE);

	ADC_ResetCalibration(ADC1);
	while (ADC_GetResetCalibrationStatus(ADC1));
	ADC_StartCalibration(ADC1);
	while (ADC_GetCalibrationStatus(ADC1));
	ADC_SoftwareStartInjectedConvCmd(ADC1, ENABLE);

	/* ADC2 config, current sampling & over current protection
	 * I1 = ADC1_CH1 = PA1 = ADC123_IN1
	 */
	ADC_DeInit(ADC2);
	ADC_StructInit(&ADC_InitStructure);
	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
	ADC_InitStructure.ADC_ScanConvMode = DISABLE;
	ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
	ADC_Init(ADC2, &ADC_InitStructure);

	ADC_RegularChannelConfig(ADC2, ADC_Channel_1, 1, ADC_SampleTime_71Cycles5); //9Mhz/(71.5 + 12.5) = 107.1Khz

	ADC_Cmd(ADC2, ENABLE);
	ADC_ResetCalibration(ADC2);
	while (ADC_GetResetCalibrationStatus(ADC2));
	ADC_StartCalibration(ADC2);
	while (ADC_GetCalibrationStatus(ADC2));

	ADC_AnalogWatchdogThresholdsConfig(ADC2, mA2d(100), 0x000);
	ADC_AnalogWatchdogSingleChannelConfig(ADC2, ADC_Channel_1);
	ADC_AnalogWatchdogCmd(ADC2, ADC_AnalogWatchdog_SingleRegEnable);

	NVIC_InitTypeDef NVIC_InitStructure;
	NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	//START
	ADC_ITConfig(ADC2, ADC_IT_AWD, ENABLE);
	ADC_SoftwareStartConvCmd(ADC2, ENABLE);

	/* ADC3 config, current sampling & over current protection
	 * I2 = ADC2_CH6 = PA6 = ADC12_IN6
	 */
	ADC_DeInit(ADC3);
	ADC_StructInit(&ADC_InitStructure);
	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
	ADC_InitStructure.ADC_ScanConvMode = DISABLE;
	ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
	ADC_Init(ADC3, &ADC_InitStructure);

	ADC_RegularChannelConfig(ADC3, ADC_Channel_6, 1, ADC_SampleTime_71Cycles5); //9Mhz/(71.5 + 12.5) = 107.1Khz

	ADC_Cmd(ADC3, ENABLE);
	ADC_ResetCalibration(ADC3);
	while (ADC_GetResetCalibrationStatus(ADC3));
	ADC_StartCalibration(ADC3);
	while (ADC_GetCalibrationStatus(ADC3));
	ADC_SoftwareStartConvCmd(ADC3, ENABLE);

	ADC_AnalogWatchdogThresholdsConfig(ADC3, mA2d(100),0x000);
	ADC_AnalogWatchdogSingleChannelConfig(ADC3, ADC_Channel_6);
	ADC_AnalogWatchdogCmd(ADC3, ADC_AnalogWatchdog_SingleRegEnable);

	NVIC_InitStructure.NVIC_IRQChannel = ADC3_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	//START
	ADC_ITConfig(ADC3, ADC_IT_AWD, ENABLE);
	ADC_SoftwareStartConvCmd(ADC3, ENABLE);

	// TIM config
	TIM_TimeBaseStructure.TIM_Period = 100 - 1; //Fclk = 10KHz /100  = 100Hz
	TIM_TimeBaseStructure.TIM_Prescaler = 7200 - 1; //prediv to 72MHz to 10KHz
	TIM_TimeBaseStructure.TIM_ClockDivision = 0;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
	TIM_ClearFlag(TIM2, TIM_FLAG_Update);
	TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
	TIM_Cmd(TIM2, 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);

	GPIO_ResetBits(GPIOD, GPIO_Pin_12);
	GPIO_ResetBits(GPIOD, GPIO_Pin_13);

	mbi5025_Init(&ict_mbi5025);
	mbi5025_EnableOE(&ict_mbi5025);
}