-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDAC-EN.c
255 lines (238 loc) · 8.16 KB
/
DAC-EN.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#include "stm32f10x.h"
Void delay_us (u32 nus);
U16 i;
U16 DAC_DATA; // DAC to write the data
/ ************************************************* *****************************
*
* Function name: DAC_Ch1_Config
* Function: DAC1 configuration
* Enter: None
* Output: None
* Returns: None
************************************************** ***************************** /
Void DAC_Ch1_Config (void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DAC_InitTypeDef DAC_InitStructure;
RCC_APB1PeriphClockCmd (RCC_APB1Periph_DAC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //DAC_OUT1=PA.4
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; // This pin is in AN mode
GPIO_Init (GPIOA, & GPIO_InitStructure); // Initialize GPIOA with parameters
DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software; // software trigger
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; // only voltage output
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_2047;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; // enable output
DAC_Init (DAC_Channel_1, & DAC_InitStructure); // with parameter initial DAC1
DAC_Cmd (DAC_Channel_1, ENABLE); // enable DAC1 pass
DAC_SetChannel1Data (DAC_Align_12b_R, 0x0000); // write the initial value 0
DAC_SoftwareTriggerCmd (DAC_Channel_1, ENABLE); /// Software Trigger Conversions
}
Void DAC1_SET (u16 DAC_Data)
{
DAC_SetChannel1Data (DAC_Align_12b_R, DAC_Data); // write data
DAC_SoftwareTriggerCmd (DAC_Channel_1, ENABLE); // software trigger conversion
}
Void DAC_Config (void)
{
DAC_Ch1_Config (); // DAC1 configuration
DAC_DATA = 0X05FF; // DAC to write the data
DAC1_SET (0X05FF); // write data DAC conversion
}
// while (1)
//
// {
// DAC_DATA = 0X05FF;
// for (i = 0; i <1000; i ++)
// {
// DAC_DATA = DAC_DATA + i;
// DAC1_SET ();
// delay_us (10);
//
//}
//
//
//}
/// **
// ************************************************ ******************************
// * @file DAC / TwoChannels_TriangleWave / main.c
// * @author MCD Application Team
// * @version V3.5.0
// * @date 08-April-2011
// * @brief Main program body.
// ************************************************ ******************************
// * @attention
// *
// * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
// * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
// * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
// * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
// * FROM THE CONTENT OF SUCH FIRMWARE AND / OR THE USE MADE BY CUSTOMERS OF THE
// * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
// *
// * <h2> <center> & copy; COPYRIGHT 2011 STMicroelectronics </ center> </ h2>
// ************************************************ ******************************
// * /
//
/// * Includes --------------------------------------------- --------------------- * /
// # include "stm32f10x.h"
//
/// ** @addtogroup STM32F10x_StdPeriph_Examples
// * @ {
// * /
//
/// ** @addtogroup DAC_TwoChannels_TriangleWave
// * @ {
// * /
//
/// * Private typedef -------------------------------------------- --------------- * /
/// * Private define -------------------------------------------- ---------------- * /
/// * Init Structure definition * /
// DAC_InitTypeDef DAC_InitStructure;
// TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
//
/// * Private macro -------------------------------------------- ----------------- * /
/// * Private variables -------------------------------------------- ------------- * /
/// * Private function prototypes ------------------------------------------- ---- * /
// void RCC_Configuration (void);
// void GPIO_Configuration (void);
// void Delay (__ IO uint32_t nCount);
//
/// * Private functions -------------------------------------------- ------------- * /
//
/// **
// @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)
// {
//}
//}
//
/// **
// * @brief Configures the different system clocks.
// * @param None
// * @retval None
// * /
// void RCC_Configuration (void)
// {
// / * Enable peripheral clocks ------------------------------------------- ----- * /
// / * GPIOA Periph clock enable * /
// RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA, ENABLE);
// / * DAC Periph clock enable * /
// RCC_APB1PeriphClockCmd (RCC_APB1Periph_DAC, ENABLE);
// / * TIM2 Periph clock enable * /
// RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM2, ENABLE);
//}
//
/// **
// * @brief Configures the different GPIO ports.
// * @param None
// * @retval None
// * /
// void GPIO_Configuration (void)
// {
// GPIO_InitTypeDef GPIO_InitStructure;
//
// / * 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_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
// GPIO_Init (GPIOA, & GPIO_InitStructure);
//}
//
/// **
// * @brief Inserts a delay time.
// * @param nCount: specify the delay time length.
// * @retval None
// * /
// void Delay (__ IO uint32_t nCount)
// {
// for (; nCount! = 0; nCount--);
//}
//
// # ifdef USE_FULL_ASSERT
//
/// **
// * @brief Reports the name of the source file and the source line number
// * where the assert_param error has occurred.
// * @param file: pointer to the source file name
// * @param line: assert_param error line source number
// * @retval None
// * /
// void assert_failed (uint8_t * file, uint32_t line)
// {
// / * User can add his own implementation to report the file name and line number,
// ex: printf ("Wrong parameters value: file% s on line% d \ r \ n", file, line) * /
//
// / * Infinite loop * /
// while (1)
// {
//}
//}
//
// # endif
//
/// **
// * @}
// * /
//
/// **
// * @}
// * /
//
/// ******************* (C) COPYRIGHT 2011 STMicroelectronics ***** END OF FILE **** /