Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
2 | * File Name : 91x_mc.c |
||
3 | * Author : MCD Application Team |
||
4 | * Date First Issued : 05/18/2006 : Version 1.0 |
||
5 | * Description : This file provides all the MC software functions. |
||
6 | ******************************************************************************** |
||
7 | * History: |
||
8 | * 05/22/2007 : Version 1.2 |
||
9 | * 05/24/2006 : Version 1.1 |
||
10 | * 05/18/2006 : Version 1.0 |
||
11 | ******************************************************************************** |
||
12 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
||
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
||
14 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
||
15 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
||
16 | * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
||
17 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
||
18 | *******************************************************************************/ |
||
19 | |||
20 | /* Includes ------------------------------------------------------------------*/ |
||
21 | #include "91x_mc.h" |
||
22 | #include "91x_scu.h" |
||
23 | /* Private typedef -----------------------------------------------------------*/ |
||
24 | /* Private define ------------------------------------------------------------*/ |
||
25 | /* Private macro -------------------------------------------------------------*/ |
||
26 | /* Private variables ---------------------------------------------------------*/ |
||
27 | |||
28 | #define MC_ODCS_Set 0x0001 |
||
29 | #define MC_ODCS_Reset 0x00FE |
||
30 | |||
31 | #define MC_CMS_Set 0x0004 |
||
32 | #define MC_CMS_Reset 0x00FB |
||
33 | |||
34 | #define MC_CPC_Set 0x0008 |
||
35 | #define MC_CTC_Set 0x0010 |
||
36 | |||
37 | #define MC_PCE_Set 0x0020 |
||
38 | #define MC_PCE_Reset 0xFFDF |
||
39 | |||
40 | #define MC_TCE_Set 0x0040 |
||
41 | #define MC_TCE_Reset 0x00BF |
||
42 | |||
43 | #define MC_DTE_Set 0x0080 |
||
44 | #define MC_DTE_Reset 0x007F |
||
45 | |||
46 | #define MC_TCB_Set 0x0004 |
||
47 | #define MC_TCB_Reset 0x00FB |
||
48 | |||
49 | #define MC_STC_Set 0x0008 |
||
50 | |||
51 | #define MC_TES_Set 0x0010 |
||
52 | #define MC_TES_Reset 0x00EF |
||
53 | |||
54 | #define MC_CCPT_Set 0x0020 |
||
55 | #define MC_CCPT_Reset 0x005F |
||
56 | |||
57 | #define MC_DISEST_Set 0x0040 |
||
58 | #define MC_DISEST_Reset 0x003F |
||
59 | |||
60 | #define MC_DTS_Set 0x0001 |
||
61 | #define MC_DTS_Reset 0x00FE |
||
62 | |||
63 | #define MC_SDT_Set 0x0002 |
||
64 | |||
65 | #define MC_C0SE_Set 0x0004 |
||
66 | #define MC_C0SE_Reset 0x00FB |
||
67 | |||
68 | #define MC_CUSE_Set 0x0008 |
||
69 | #define MC_CUSE_Reset 0x00F7 |
||
70 | |||
71 | #define MC_CVSE_Set 0x0010 |
||
72 | #define MC_CVSE_Reset 0x00EF |
||
73 | |||
74 | #define MC_CWSE_Set 0x0020 |
||
75 | #define MC_CWSE_Reset 0x00D0 |
||
76 | |||
77 | #define MC_RSE_Set 0x0040 |
||
78 | #define MC_RSE_Reset 0x00BF |
||
79 | |||
80 | #define MC_GPI_Set 0x0080 |
||
81 | #define MC_GPI_Reset 0x007F |
||
82 | |||
83 | #define MC_PUH_Set 0x0020 |
||
84 | #define MC_PUH_Reset 0x005F |
||
85 | #define MC_PUL_Set 0x0010 |
||
86 | #define MC_PUL_Reset 0x006F |
||
87 | |||
88 | #define MC_PVH_Set 0x0008 |
||
89 | #define MC_PVH_Reset 0x0077 |
||
90 | #define MC_PVL_Set 0x0004 |
||
91 | #define MC_PVL_Reset 0x007B |
||
92 | |||
93 | #define MC_PWH_Set 0x0002 |
||
94 | #define MC_PWH_Reset 0x007D |
||
95 | #define MC_PWL_Set 0x0001 |
||
96 | #define MC_PWL_Reset 0x007E |
||
97 | |||
98 | #define MC_ODS_Set 0x0040 |
||
99 | #define MC_ODS_Reset 0xFF3F |
||
100 | |||
101 | #define MC_ESC_Clear 0x4321 |
||
102 | |||
103 | #define MC_PCR1_TIN_MASK 0xFFFC |
||
104 | #define MC_OPR_Mask 0x0040 |
||
105 | #define MC_UDCS_Mask 0x0002 |
||
106 | /* Private function prototypes -----------------------------------------------*/ |
||
107 | /* Private functions ---------------------------------------------------------*/ |
||
108 | /****************************************************************************** |
||
109 | * Function Name : MC_DeInit |
||
110 | * Description : Deinitializes MC peripheral registers to their default reset |
||
111 | * values. |
||
112 | * Input : None |
||
113 | * Output : None |
||
114 | * Return : None |
||
115 | *******************************************************************************/ |
||
116 | void MC_DeInit(void) |
||
117 | { |
||
118 | /* MC peripheral is under Reset */ |
||
119 | SCU_APBPeriphReset(__MC, ENABLE); |
||
120 | |||
121 | /* MC peripheral Reset off */ |
||
122 | SCU_APBPeriphReset(__MC, DISABLE); |
||
123 | } |
||
124 | |||
125 | /******************************************************************************* |
||
126 | * Function Name : MC_Init |
||
127 | * Description : Initializes the MC peripheral according to the specified |
||
128 | * parameters in the MC_InitStruct . |
||
129 | * Input : IMC_InitStruct: pointer to a MC_InitTypeDef structure that |
||
130 | * contains the configuration information for the MC peripheral. |
||
131 | * Output : None |
||
132 | * Return : None |
||
133 | *******************************************************************************/ |
||
134 | void MC_Init(MC_InitTypeDef* MC_InitStruct) |
||
135 | { |
||
136 | /* Select the operating Mode */ |
||
137 | if(MC_InitStruct->MC_OperatingMode == MC_SoftwareOperating_Mode) |
||
138 | { |
||
139 | /* Select the Data transfer Mode */ |
||
140 | MC->PCR2 |= MC_DTS_Set; |
||
141 | |||
142 | /* Enable the registers Software Data Transfer */ |
||
143 | MC->PCR2 |= MC_C0SE_Set | MC_CUSE_Set | MC_CVSE_Set | MC_CWSE_Set |
||
144 | |MC_RSE_Set; |
||
145 | |||
146 | } |
||
147 | else |
||
148 | { |
||
149 | /* Select the Data transfer Mode */ |
||
150 | MC->PCR2 &= MC_DTS_Reset; |
||
151 | |||
152 | /* Disable the registers Software Data Transfer */ |
||
153 | MC->PCR2 &= MC_C0SE_Reset | MC_CUSE_Reset | MC_CVSE_Reset | MC_CWSE_Reset |
||
154 | |MC_RSE_Reset; |
||
155 | } |
||
156 | |||
157 | /* Select the MC PWM counter Mode */ |
||
158 | if(MC_InitStruct->MC_PWMMode == MC_PWMZeroCentered_Mode) |
||
159 | { |
||
160 | MC->PCR0 |= MC_CMS_Set; |
||
161 | } |
||
162 | else |
||
163 | { |
||
164 | MC->PCR0 &= MC_CMS_Reset; |
||
165 | } |
||
166 | |||
167 | /* Set the MC PWM counter Prescaler */ |
||
168 | MC->CPRS = MC_InitStruct->MC_Prescaler; |
||
169 | |||
170 | /* Set the MC PWM Period */ |
||
171 | MC->CMP0 = MC_InitStruct->MC_Period; |
||
172 | |||
173 | /* Set the MC PWM Repetition counter */ |
||
174 | MC->REP = MC_InitStruct->MC_RepetitionCounter; |
||
175 | |||
176 | /* Set the Tacho Compare value */ |
||
177 | MC->TCMP = MC_InitStruct->MC_TachoPeriod; |
||
178 | |||
179 | /* Set the Tacho Prescaler value */ |
||
180 | MC->TPRS = MC_InitStruct->MC_TachoPrescaler; |
||
181 | |||
182 | /* Set the MC Tacho Input Polarity */ |
||
183 | MC->PCR1 = (MC->PCR1 & MC_PCR1_TIN_MASK) | MC_InitStruct->MC_TachoPolarity; |
||
184 | |||
185 | /* Set the MC PWM Forced State */ |
||
186 | MC->OPR |= MC_ODS_Set; |
||
187 | MC->OPR = (MC->OPR & MC_OPR_Mask) | MC_InitStruct->MC_ForcedPWMState; |
||
188 | |||
189 | /* Select the Tacho Mode */ |
||
190 | if(MC_InitStruct->MC_TachoMode == MC_TachoOneShot_Mode) |
||
191 | { |
||
192 | MC->PCR1 |= MC_TCB_Set; |
||
193 | } |
||
194 | else |
||
195 | { |
||
196 | MC->PCR1 &= MC_TCB_Reset; |
||
197 | } |
||
198 | |||
199 | /* Select the Tacho Event Mode */ |
||
200 | if(MC_InitStruct->MC_TachoEvent_Mode == MC_TachoEvent_Software_Mode) |
||
201 | { |
||
202 | MC->PCR1 |= MC_TES_Set; |
||
203 | } |
||
204 | else |
||
205 | { |
||
206 | MC->PCR1 &= MC_TES_Reset; |
||
207 | } |
||
208 | |||
209 | /* Enable or disable the emergency input */ |
||
210 | if(MC_InitStruct->MC_Emergency == MC_Emergency_Enable) |
||
211 | { |
||
212 | MC->PCR1 &= MC_DISEST_Reset; |
||
213 | } |
||
214 | else |
||
215 | { |
||
216 | MC->PCR1 |= MC_DISEST_Set; |
||
217 | } |
||
218 | |||
219 | /* Select the complementary Mode */ |
||
220 | if(MC_InitStruct->MC_Complementary == MC_Complementary_Enable) |
||
221 | { |
||
222 | MC->DTG = MC_InitStruct->MC_DeadTime; |
||
223 | MC->PCR0 |= MC_ODCS_Set; |
||
224 | } |
||
225 | else |
||
226 | { |
||
227 | MC->PCR0 &= MC_ODCS_Reset; |
||
228 | } |
||
229 | |||
230 | /* Tacho Mode selection */ |
||
231 | if(MC_InitStruct->MC_TachoMode == MC_TachoOneShot_Mode) |
||
232 | { |
||
233 | MC->PCR1 |= MC_TCB_Set; |
||
234 | } |
||
235 | else |
||
236 | { |
||
237 | MC->PCR1 &= MC_TCB_Reset; |
||
238 | } |
||
239 | |||
240 | switch(MC_InitStruct->MC_Channel) |
||
241 | { |
||
242 | /* Channel U configuration */ |
||
243 | case MC_Channel_U: |
||
244 | { |
||
245 | MC->CMPU = MC_InitStruct->MC_PulseU; |
||
246 | |||
247 | if(MC_InitStruct->MC_PolarityUL == MC_Polarity_Inverted) |
||
248 | { |
||
249 | MC->PSR |= MC_PUL_Set; |
||
250 | } |
||
251 | else |
||
252 | { |
||
253 | MC->PSR &= MC_PUL_Reset; |
||
254 | } |
||
255 | if(MC_InitStruct->MC_PolarityUH == MC_Polarity_Inverted) |
||
256 | { |
||
257 | MC->PSR |= MC_PUH_Set; |
||
258 | } |
||
259 | else |
||
260 | { |
||
261 | MC->PSR &= MC_PUH_Reset; |
||
262 | } |
||
263 | break; |
||
264 | } |
||
265 | |||
266 | /* Channel V configuration */ |
||
267 | case MC_Channel_V: |
||
268 | { |
||
269 | MC->CMPV = MC_InitStruct->MC_PulseV; |
||
270 | |||
271 | if(MC_InitStruct->MC_PolarityVL == MC_Polarity_Inverted) |
||
272 | { |
||
273 | MC->PSR |= MC_PVL_Set; |
||
274 | } |
||
275 | else |
||
276 | { |
||
277 | MC->PSR &= MC_PVL_Reset; |
||
278 | } |
||
279 | if(MC_InitStruct->MC_PolarityVH == MC_Polarity_Inverted) |
||
280 | { |
||
281 | MC->PSR |= MC_PVH_Set; |
||
282 | } |
||
283 | else |
||
284 | { |
||
285 | MC->PSR &= MC_PVH_Reset; |
||
286 | } |
||
287 | break; |
||
288 | } |
||
289 | |||
290 | /* Channel W configuration */ |
||
291 | case MC_Channel_W: |
||
292 | { |
||
293 | MC->CMPW = MC_InitStruct->MC_PulseW; |
||
294 | |||
295 | if(MC_InitStruct->MC_PolarityWL == MC_Polarity_Inverted) |
||
296 | { |
||
297 | MC->PSR |= MC_PWL_Set; |
||
298 | } |
||
299 | else |
||
300 | { |
||
301 | MC->PSR &= MC_PWL_Reset; |
||
302 | } |
||
303 | if(MC_InitStruct->MC_PolarityWH == MC_Polarity_Inverted) |
||
304 | { |
||
305 | MC->PSR |= MC_PWH_Set; |
||
306 | } |
||
307 | else |
||
308 | { |
||
309 | MC->PSR &= MC_PWH_Reset; |
||
310 | } |
||
311 | break; |
||
312 | } |
||
313 | /* All Channel Configuration */ |
||
314 | case MC_Channel_ALL: |
||
315 | { |
||
316 | MC->CMPU = MC_InitStruct->MC_PulseU; |
||
317 | MC->CMPV = MC_InitStruct->MC_PulseV; |
||
318 | MC->CMPW = MC_InitStruct->MC_PulseW; |
||
319 | |||
320 | if(MC_InitStruct->MC_PolarityUL == MC_Polarity_Inverted) |
||
321 | { |
||
322 | MC->PSR |= MC_PUL_Set; |
||
323 | } |
||
324 | else |
||
325 | { |
||
326 | MC->PSR &= MC_PUL_Reset; |
||
327 | } |
||
328 | if(MC_InitStruct->MC_PolarityUH == MC_Polarity_Inverted) |
||
329 | { |
||
330 | MC->PSR |= MC_PUH_Set; |
||
331 | } |
||
332 | else |
||
333 | { |
||
334 | MC->PSR &= MC_PUH_Reset; |
||
335 | } |
||
336 | |||
337 | if(MC_InitStruct->MC_PolarityVL == MC_Polarity_Inverted) |
||
338 | { |
||
339 | MC->PSR |= MC_PVL_Set; |
||
340 | } |
||
341 | else |
||
342 | { |
||
343 | MC->PSR &= MC_PVL_Reset; |
||
344 | } |
||
345 | if(MC_InitStruct->MC_PolarityVH == MC_Polarity_Inverted) |
||
346 | { |
||
347 | MC->PSR |= MC_PVH_Set; |
||
348 | } |
||
349 | else |
||
350 | { |
||
351 | MC->PSR &= MC_PVH_Reset; |
||
352 | } |
||
353 | |||
354 | if(MC_InitStruct->MC_PolarityWL == MC_Polarity_Inverted) |
||
355 | { |
||
356 | MC->PSR |= MC_PWL_Set; |
||
357 | } |
||
358 | else |
||
359 | { |
||
360 | MC->PSR &= MC_PWL_Reset; |
||
361 | } |
||
362 | if(MC_InitStruct->MC_PolarityWH == MC_Polarity_Inverted) |
||
363 | { |
||
364 | MC->PSR |= MC_PWH_Set; |
||
365 | } |
||
366 | else |
||
367 | { |
||
368 | MC->PSR &= MC_PWH_Reset; |
||
369 | } |
||
370 | } |
||
371 | default: |
||
372 | break; |
||
373 | } |
||
374 | } |
||
375 | |||
376 | /******************************************************************************* |
||
377 | * Function Name : MC_StructInit |
||
378 | * Description : Fills each MC_InitStruct member with its default value. |
||
379 | * Input : MC_InitStruct : pointer to a MC_InitTypeDef structure which |
||
380 | * will be initialized. |
||
381 | * Output : None |
||
382 | * Return : None. |
||
383 | *******************************************************************************/ |
||
384 | void MC_StructInit(MC_InitTypeDef* MC_InitStruct) |
||
385 | { |
||
386 | MC_InitStruct->MC_OperatingMode = MC_HardwareOperating_Mode; |
||
387 | MC_InitStruct->MC_TachoMode = MC_TachoContinuous_Mode; |
||
388 | MC_InitStruct->MC_TachoEvent_Mode = MC_TachoEvent_Hardware_Mode; |
||
389 | MC_InitStruct->MC_Prescaler = 0x00; |
||
390 | MC_InitStruct->MC_TachoPrescaler = 0x0000; |
||
391 | MC_InitStruct->MC_PWMMode = MC_PWMClassical_Mode; |
||
392 | MC_InitStruct->MC_Complementary = MC_Complementary_Enable; |
||
393 | MC_InitStruct->MC_Emergency = MC_Emergency_Disable; |
||
394 | MC_InitStruct->MC_ForcedPWMState = 0x003F; |
||
395 | MC_InitStruct->MC_Period = 0x0000; |
||
396 | MC_InitStruct->MC_TachoPeriod = 0x00FF; |
||
397 | MC_InitStruct->MC_Channel = MC_Channel_ALL; |
||
398 | MC_InitStruct->MC_PulseU = 0x0000; |
||
399 | MC_InitStruct->MC_PulseV = 0x0000; |
||
400 | MC_InitStruct->MC_PulseW = 0x0000; |
||
401 | MC_InitStruct->MC_PolarityUL = MC_Polarity_NonInverted; |
||
402 | MC_InitStruct->MC_PolarityUH = MC_Polarity_NonInverted; |
||
403 | MC_InitStruct->MC_PolarityVL = MC_Polarity_NonInverted; |
||
404 | MC_InitStruct->MC_PolarityVH = MC_Polarity_NonInverted; |
||
405 | MC_InitStruct->MC_PolarityWL = MC_Polarity_NonInverted; |
||
406 | MC_InitStruct->MC_PolarityWH = MC_Polarity_NonInverted; |
||
407 | MC_InitStruct->MC_TachoPolarity = MC_TachoEventEdge_RisingFalling; |
||
408 | MC_InitStruct->MC_DeadTime = 0x003F; |
||
409 | MC_InitStruct->MC_RepetitionCounter = 0x0000; |
||
410 | } |
||
411 | |||
412 | /******************************************************************************* |
||
413 | * Function Name : MC_Cmd |
||
414 | * Description : Enables or disables the MC peripheral. |
||
415 | * Input : Newstate: new state of the MC peripheral. |
||
416 | * This parameter can be: ENABLE or DISABLE. |
||
417 | * Output : None |
||
418 | * Return : None |
||
419 | *******************************************************************************/ |
||
420 | void MC_Cmd(FunctionalState NewState) |
||
421 | { |
||
422 | if(NewState == ENABLE) |
||
423 | { |
||
424 | /* Enable the PWM counter */ |
||
425 | MC->PCR0 |= MC_PCE_Set; |
||
426 | |||
427 | /* Enable the Tacho counter */ |
||
428 | MC->PCR0 |= MC_TCE_Set; |
||
429 | |||
430 | /* Enable the Dead Time counter */ |
||
431 | MC->PCR0 |= MC_DTE_Set; |
||
432 | } |
||
433 | else |
||
434 | { |
||
435 | /* Disable the PWM counter */ |
||
436 | MC->PCR0 &= MC_PCE_Reset; |
||
437 | |||
438 | /* Disable the Tacho counter */ |
||
439 | MC->PCR0 &= MC_TCE_Reset; |
||
440 | |||
441 | /* Disable the Dead counter */ |
||
442 | MC->PCR0 &= MC_DTE_Reset; |
||
443 | } |
||
444 | } |
||
445 | |||
446 | /******************************************************************************* |
||
447 | * Function Name : MC_ClearPWMCounter |
||
448 | * Description : Clears the MC PWM counter. |
||
449 | * Input : None |
||
450 | * Output : None |
||
451 | * Return : None |
||
452 | *******************************************************************************/ |
||
453 | void MC_ClearPWMCounter(void) |
||
454 | { |
||
455 | /* Clear the PWM counter */ |
||
456 | MC->PCR0 |= MC_CPC_Set; |
||
457 | } |
||
458 | |||
459 | /******************************************************************************* |
||
460 | * Function Name : MC_ClearTachoCounter |
||
461 | * Description : Clears the MC Tacho counter. |
||
462 | * Input : None |
||
463 | * Output : None |
||
464 | * Return : None |
||
465 | *******************************************************************************/ |
||
466 | void MC_ClearTachoCounter(void) |
||
467 | { |
||
468 | /* Clear the Tacho counter */ |
||
469 | MC->PCR0 |= MC_CTC_Set; |
||
470 | } |
||
471 | |||
472 | /******************************************************************************* |
||
473 | * Function Name : MC_CtrlPWMOutputs |
||
474 | * Description : Enables or disables MC peripheral Main Outputs. |
||
475 | * Input : Newstate: new state of the MC peripheral Main Outputs. |
||
476 | * This parameter can be: ENABLE or DISABLE. |
||
477 | * Output : None |
||
478 | * Return : None |
||
479 | *******************************************************************************/ |
||
480 | void MC_CtrlPWMOutputs(FunctionalState Newstate) |
||
481 | { |
||
482 | if(Newstate == ENABLE) |
||
483 | { |
||
484 | /* Enable the dead time generator data */ |
||
485 | MC->OPR &= MC_ODS_Reset; |
||
486 | } |
||
487 | else |
||
488 | { |
||
489 | /* Enable the default state data */ |
||
490 | MC->OPR |= MC_ODS_Set; |
||
491 | } |
||
492 | } |
||
493 | |||
494 | /******************************************************************************* |
||
495 | * Function Name : MC_ITConfig |
||
496 | * Description : Enables or disables the MC interrupts. |
||
497 | * Input : - MC_IT: specifies the MC interrupts sources to be enabled |
||
498 | * or disabled. |
||
499 | * This parameter can be any combination of the following values: |
||
500 | * - MC_IT_CMPW: Compare W Interrupt. |
||
501 | * - MC_IT_CMPV: Compare V Interrupt. |
||
502 | * - MC_IT_CMPU: Compare U Interrupt. |
||
503 | * - MC_IT_ZPC: Zero of PWM counter Interrupt. |
||
504 | * - MC_IT_ADT: Automatic Data Transfer Interrupt. |
||
505 | * - MC_IT_OTC: Overflow of Tacho counter Interrupt. |
||
506 | * - MC_IT_CPT: Capture of Tacho counter Interrupt. |
||
507 | * - MC_IT_CM0: Compare 0 Interrupt. |
||
508 | * - Newstate: new state of IMC interrupts. |
||
509 | * This parameter can be: ENABLE or DISABLE. |
||
510 | * Output : None |
||
511 | * Return : None |
||
512 | *******************************************************************************/ |
||
513 | void MC_ITConfig(u16 MC_IT, FunctionalState NewState) |
||
514 | { |
||
515 | if(NewState == ENABLE) |
||
516 | { |
||
517 | /* Enable the specific interrupt source */ |
||
518 | MC->IMR |= MC_IT; |
||
519 | |||
520 | /* Enable the global peripheral interrupt sources */ |
||
521 | MC->PCR2 |= MC_GPI_Set; |
||
522 | } |
||
523 | else |
||
524 | { |
||
525 | /* Disable the specific interrupt source */ |
||
526 | MC->IMR &= ~MC_IT; |
||
527 | |||
528 | /* Disable the global peripheral interrupt sources */ |
||
529 | MC->PCR2 &= MC_GPI_Reset; |
||
530 | } |
||
531 | } |
||
532 | |||
533 | /******************************************************************************* |
||
534 | * Function Name : MC_SetPrescaler |
||
535 | * Description : Sets the MC prescaler value. |
||
536 | * Input : MC_Prescaler: MC prescaler new value. |
||
537 | * Output : None |
||
538 | * Return : None |
||
539 | *******************************************************************************/ |
||
540 | void MC_SetPrescaler(u8 MC_Prescaler) |
||
541 | { |
||
542 | /* Set the Prescaler Register value */ |
||
543 | MC->CPRS = MC_Prescaler; |
||
544 | } |
||
545 | |||
546 | /******************************************************************************* |
||
547 | * Function Name : MC_SetPeriod |
||
548 | * Description : Sets the MC period value. |
||
549 | * Input : MC_Period: MC period new value. |
||
550 | * Output : None |
||
551 | * Return : None |
||
552 | *******************************************************************************/ |
||
553 | void MC_SetPeriod(u16 MC_Period) |
||
554 | { |
||
555 | /* Set the Period Register value */ |
||
556 | MC->CMP0 = MC_Period; |
||
557 | } |
||
558 | |||
559 | /******************************************************************************* |
||
560 | * Function Name : MC_SetPulseU |
||
561 | * Description : Sets the MC pulse U value. |
||
562 | * Input : MC_PulseU: MC pulse U new value. |
||
563 | * Output : None |
||
564 | * Return : None |
||
565 | *******************************************************************************/ |
||
566 | void MC_SetPulseU(u16 MC_PulseU) |
||
567 | { |
||
568 | /* Set the Pulse U Register value */ |
||
569 | MC->CMPU = MC_PulseU; |
||
570 | } |
||
571 | |||
572 | /******************************************************************************* |
||
573 | * Function Name : MC_SetPulseV |
||
574 | * Description : Sets the MC pulse V value. |
||
575 | * Input : MC_PulseV: MC pulse V new value. |
||
576 | * Output : None |
||
577 | * Return : None |
||
578 | *******************************************************************************/ |
||
579 | void MC_SetPulseV(u16 MC_PulseV) |
||
580 | { |
||
581 | /* Set the Pulse V Register value */ |
||
582 | MC->CMPV = MC_PulseV; |
||
583 | } |
||
584 | |||
585 | /******************************************************************************* |
||
586 | * Function Name : MC_SetPulseW |
||
587 | * Description : Sets the MC pulse W value. |
||
588 | * Input : MC_PulseW: MC pulse W new value. |
||
589 | * Output : None |
||
590 | * Return : None |
||
591 | *******************************************************************************/ |
||
592 | void MC_SetPulseW(u16 MC_PulseW) |
||
593 | { |
||
594 | /* Set the Pulse W Register value */ |
||
595 | MC->CMPW = MC_PulseW; |
||
596 | } |
||
597 | |||
598 | /******************************************************************************* |
||
599 | * Function Name : MC_PWMModeConfig |
||
600 | * Description : Selects the MC PWM counter Mode. |
||
601 | * Input : MC_PWMMode: MC PWM counter Mode. |
||
602 | * Output : None |
||
603 | * Return : None |
||
604 | *******************************************************************************/ |
||
605 | void MC_PWMModeConfig(u16 MC_PWMMode) |
||
606 | { |
||
607 | /* Select the MC PWM counter Mode */ |
||
608 | if(MC_PWMMode == MC_PWMZeroCentered_Mode) |
||
609 | { |
||
610 | MC->PCR0 |= MC_CMS_Set; |
||
611 | } |
||
612 | else |
||
613 | { |
||
614 | MC->PCR0 &= MC_CMS_Reset; |
||
615 | } |
||
616 | } |
||
617 | |||
618 | /******************************************************************************* |
||
619 | * Function Name : MC_SetDeadTime |
||
620 | * Description : Sets the MC dead time value. |
||
621 | * Input : MC_DeadTime: MC dead time new value. |
||
622 | * Output : None |
||
623 | * Return : None |
||
624 | *******************************************************************************/ |
||
625 | void MC_SetDeadTime(u16 MC_DeadTime) |
||
626 | { |
||
627 | /* Set the dead time Register value */ |
||
628 | MC->DTG = MC_DeadTime; |
||
629 | } |
||
630 | |||
631 | /******************************************************************************* |
||
632 | * Function Name : MC_SetTachoCompare |
||
633 | * Description : Sets the MC Tacho Compare Register value. |
||
634 | * Input : MC_Compare: MC Tacho compare new value. |
||
635 | * Output : None |
||
636 | * Return : None |
||
637 | *******************************************************************************/ |
||
638 | void MC_SetTachoCompare(u8 MC_Compare) |
||
639 | { |
||
640 | /* Sets the Tacho Compare Register value */ |
||
641 | MC->TCMP = MC_Compare; |
||
642 | } |
||
643 | /******************************************************************************* |
||
644 | * Function Name : MC_EmergencyCmd |
||
645 | * Description : Enables or disables the MC emergency feauture. |
||
646 | * Input : Newstate: new state of the MC peripheral Emergency. |
||
647 | * This parameter can be: ENABLE or DISABLE. |
||
648 | * Output : None |
||
649 | * Return : None |
||
650 | *******************************************************************************/ |
||
651 | void MC_EmergencyCmd(FunctionalState NewState) |
||
652 | { |
||
653 | if(NewState == ENABLE) |
||
654 | { |
||
655 | /* Reset the DISEST Bit in the PCR1 Register to enable the emergency stop input */ |
||
656 | MC->PCR1 &= MC_DISEST_Reset; |
||
657 | } |
||
658 | else |
||
659 | { |
||
660 | /* Set the DISEST Bit in the PCR1 Register to disable the emergency stop input */ |
||
661 | MC->PCR1 |= MC_DISEST_Reset; |
||
662 | } |
||
663 | } |
||
664 | |||
665 | /******************************************************************************* |
||
666 | * Function Name : MC_EmergencyClear |
||
667 | * Description : Clears the MC Emergency Register. |
||
668 | * Input : None |
||
669 | * Output : None |
||
670 | * Return : None |
||
671 | *******************************************************************************/ |
||
672 | void MC_EmergencyClear(void) |
||
673 | { |
||
674 | /* Force PWM outputs in safe state (All OFF) */ |
||
675 | MC->OPR |= MC_ODS_Set; |
||
676 | |||
677 | /* Clear EST bit */ |
||
678 | MC->ESC = MC_ESC_Clear; |
||
679 | |||
680 | /* Re-enable protection */ |
||
681 | MC->ESC = 0; |
||
682 | |||
683 | /* Enables the Outputs */ |
||
684 | MC->OPR &= MC_ODS_Reset; |
||
685 | } |
||
686 | |||
687 | /******************************************************************************* |
||
688 | * Function Name : MC_GetPeriod |
||
689 | * Description : Gets the MC period value. |
||
690 | * Input : None |
||
691 | * Output : None |
||
692 | * Return : MC period value. |
||
693 | *******************************************************************************/ |
||
694 | u16 MC_GetPeriod(void) |
||
695 | { |
||
696 | /* Return the PWM signal period value */ |
||
697 | return MC->CMP0; |
||
698 | } |
||
699 | |||
700 | /******************************************************************************* |
||
701 | * Function Name : MC_GetPulseU |
||
702 | * Description : Gets the MC pulse U value. |
||
703 | * Input : None |
||
704 | * Output : None |
||
705 | * Return : MC pulse U value. |
||
706 | *******************************************************************************/ |
||
707 | u16 MC_GetPulseU(void) |
||
708 | { |
||
709 | /* Return the PWM pulse U Register value */ |
||
710 | return MC->CMPU; |
||
711 | } |
||
712 | |||
713 | /******************************************************************************* |
||
714 | * Function Name : MC_GetPulseV |
||
715 | * Description : Gets the MC pulse V value. |
||
716 | * Input : None |
||
717 | * Output : None |
||
718 | * Return : MC pulse V value. |
||
719 | *******************************************************************************/ |
||
720 | u16 MC_GetPulseV(void) |
||
721 | { |
||
722 | /* Return the PWM pulse V Register value */ |
||
723 | return MC->CMPV; |
||
724 | } |
||
725 | |||
726 | /******************************************************************************* |
||
727 | * Function Name : MC_GetPulseW |
||
728 | * Description : Gets the MC pulse W value. |
||
729 | * Input : None |
||
730 | * Output : None |
||
731 | * Return : MC pulse W value. |
||
732 | *******************************************************************************/ |
||
733 | u16 MC_GetPulseW(void) |
||
734 | { |
||
735 | /* Return the PWM pulse W Register value */ |
||
736 | return MC->CMPW; |
||
737 | } |
||
738 | |||
739 | /******************************************************************************* |
||
740 | * Function Name : MC_GetTachoCapture |
||
741 | * Description : Gets the MC Tacho period value. |
||
742 | * Input : None |
||
743 | * Output : None |
||
744 | * Return : MC Tacho capture value. |
||
745 | *******************************************************************************/ |
||
746 | u16 MC_GetTachoCapture(void) |
||
747 | { |
||
748 | /* Return the Tacho Capture Register value */ |
||
749 | return MC->TCPT; |
||
750 | } |
||
751 | |||
752 | /******************************************************************************* |
||
753 | * Function Name : MC_ClearOnTachoCapture |
||
754 | * Description : Enables or disables the the Clear on capture of tacho counter. |
||
755 | * Input : Newstate: new state of the CCPT bit. |
||
756 | * This parameter can be: ENABLE or DISABLE. |
||
757 | * Output : None |
||
758 | * Return : None |
||
759 | *******************************************************************************/ |
||
760 | void MC_ClearOnTachoCapture(FunctionalState NewState) |
||
761 | { |
||
762 | if(NewState == ENABLE) |
||
763 | { |
||
764 | /* Enable the Clear on capture of tacho counter */ |
||
765 | MC->PCR1 |= MC_CCPT_Set; |
||
766 | } |
||
767 | else |
||
768 | { |
||
769 | /* Disable the Clear on capture of tacho counter */ |
||
770 | MC->PCR1 &= MC_CCPT_Reset; |
||
771 | } |
||
772 | } |
||
773 | /******************************************************************************* |
||
774 | * Function Name : MC_ForceDataTransfer |
||
775 | * Description : Sets the MC Outputs default states. |
||
776 | * Input : MC_ForcedData: MC outputs new states. |
||
777 | * Output : None |
||
778 | * Return : None |
||
779 | *******************************************************************************/ |
||
780 | void MC_ForceDataTransfer(u8 MC_ForcedData) |
||
781 | { |
||
782 | /* Set the MC PWM Forced State */ |
||
783 | MC->OPR |= MC_ODS_Set; |
||
784 | MC->OPR = (MC->OPR & MC_OPR_Mask) | MC_ForcedData; |
||
785 | } |
||
786 | |||
787 | /******************************************************************************* |
||
788 | * Function Name : MC_PreloadConfig |
||
789 | * Description : Enables the Software Data Transfer. |
||
790 | * Input : None |
||
791 | * Output : None |
||
792 | * Return : None |
||
793 | *******************************************************************************/ |
||
794 | void MC_SoftwarePreloadConfig(void) |
||
795 | { |
||
796 | /* Set the SDT: Software Data Transfer bit */ |
||
797 | MC->PCR2 |= MC_SDT_Set; |
||
798 | } |
||
799 | |||
800 | /******************************************************************************* |
||
801 | * Function Name : MC_SoftwareTachoCapture |
||
802 | * Description : Enables the Software Tacho Capture. |
||
803 | * Input : None |
||
804 | * Output : None |
||
805 | * Return : None |
||
806 | *******************************************************************************/ |
||
807 | void MC_SoftwareTachoCapture(void) |
||
808 | { |
||
809 | /* Set the STC: Software Tacho Capture bit */ |
||
810 | MC->PCR1 |= MC_STC_Set; |
||
811 | } |
||
812 | |||
813 | /******************************************************************************* |
||
814 | * Function Name : MC_GetCountingStatus |
||
815 | * Description : Checks whether the PWM Counter is counting Up or Down. |
||
816 | * Input : None |
||
817 | * Output : None |
||
818 | * Return : The new state of the PWM Counter(DOWN or UP). |
||
819 | *******************************************************************************/ |
||
820 | CountingStatus MC_GetCountingStatus(void) |
||
821 | { |
||
822 | if((MC->PCR0 & MC_UDCS_Mask) != DOWN) |
||
823 | { |
||
824 | return UP; |
||
825 | } |
||
826 | else |
||
827 | { |
||
828 | return DOWN; |
||
829 | } |
||
830 | } |
||
831 | |||
832 | /******************************************************************************* |
||
833 | * Function Name : MC_GetFlagStatus |
||
834 | * Description : Checks whether the specified MC flag is set or not. |
||
835 | * Input : MC_FLAG: specifies the flag to check. |
||
836 | * This parameter can be one of the following values: |
||
837 | * - MC_FLAG_CMPW: Compare W Flag. |
||
838 | * - MC_FLAG_CMPV: Compare V Flag. |
||
839 | * - MC_FLAG_CMPU: Compare U Flag. |
||
840 | * - MC_FLAG_ZPC: Zero of PWM counter Flag. |
||
841 | * - MC_FLAG_ADT: Automatic Data Transfer Flag. |
||
842 | * - MC_FLAG_OTC: Overflow of Tacho counter Flag. |
||
843 | * - MC_FLAG_CPT: Capture of Tacho counter Flag. |
||
844 | * - MC_FLAG_CM0: Compare 0 Flag. |
||
845 | * - MC_FLAG_EST: Emergency Stop Flag. |
||
846 | * Output : None |
||
847 | * Return : The new state of the MC_FLAG(SET or RESET). |
||
848 | *******************************************************************************/ |
||
849 | FlagStatus MC_GetFlagStatus(u16 MC_FLAG) |
||
850 | { |
||
851 | if((MC->IPR & MC_FLAG) != RESET) |
||
852 | { |
||
853 | return SET; |
||
854 | } |
||
855 | else |
||
856 | { |
||
857 | return RESET; |
||
858 | } |
||
859 | } |
||
860 | |||
861 | /******************************************************************************* |
||
862 | * Function Name : MC_ClearFlag |
||
863 | * Description : Clears the MC’s pending flags. |
||
864 | * Input : MC_FLAG: specifies the flag to clear. |
||
865 | * This parameter can be any combination of the following values: |
||
866 | * - MC_FLAG_CMPW: Compare W Flag. |
||
867 | * - MC_FLAG_CMPV: Compare V Flag. |
||
868 | * - MC_FLAG_CMPU: Compare U Flag. |
||
869 | * - MC_FLAG_ZPC: Zero of PWM counter Flag. |
||
870 | * - MC_FLAG_ADT: Automatic Data Transfer Flag. |
||
871 | * - MC_FLAG_OTC: Overflow of Tacho counter Flag. |
||
872 | * - MC_FLAG_CPT: Capture of Tacho counter Flag. |
||
873 | * - MC_FLAG_CM0: Compare 0 Flag. |
||
874 | * Output : None |
||
875 | * Return : None |
||
876 | *******************************************************************************/ |
||
877 | void MC_ClearFlag(u16 MC_FLAG) |
||
878 | { |
||
879 | /* Clear the corresponding Flag */ |
||
880 | MC->IPR &= ~MC_FLAG; |
||
881 | } |
||
882 | |||
883 | /******************************************************************************* |
||
884 | * Function Name : MC_GetITStatus |
||
885 | * Description : Checks whether the MC interrupt has occurred or not. |
||
886 | * Input : MC_IT: specifies the MC interrupt source to check. |
||
887 | * This parameter can be one of the following values: |
||
888 | * - MC_IT_CMPW: Compare W Interrupt. |
||
889 | * - MC_IT_CMPV: Compare V Interrupt. |
||
890 | * - MC_IT_CMPU: Compare U Interrupt. |
||
891 | * - MC_IT_ZPC: Zero of PWM counter Interrupt. |
||
892 | * - MC_IT_ADT: Automatic Data Transfer Interrupt. |
||
893 | * - MC_IT_OTC: Overflow of Tacho counter Interrupt. |
||
894 | * - MC_IT_CPT: Capture of Tacho counter Interrupt. |
||
895 | * - MC_IT_CM0: Compare 0 Interrupt. |
||
896 | * Output : None |
||
897 | * Return : The new state of the MC_IT(SET or RESET). |
||
898 | *******************************************************************************/ |
||
899 | ITStatus MC_GetITStatus(u16 MC_IT) |
||
900 | { |
||
901 | if((MC->IPR & MC_IT) && (MC->IMR & MC_IT)) |
||
902 | { |
||
903 | return SET; |
||
904 | } |
||
905 | else |
||
906 | { |
||
907 | return RESET; |
||
908 | } |
||
909 | } |
||
910 | |||
911 | /******************************************************************************* |
||
912 | * Function Name : MC_ClearITPendingBit |
||
913 | * Description : Clears the IMC's interrupt pending bits. |
||
914 | * Input : MC_IT: specifies the pending bit to clear. |
||
915 | * This parameter can be any combination of the following values: |
||
916 | * - MC_IT_CMPW: Compare W Interrupt. |
||
917 | * - MC_IT_CMPV: Compare V Interrupt. |
||
918 | * - MC_IT_CMPU: Compare U Interrupt. |
||
919 | * - MC_IT_ZPC: Zero of PWM counter Interrupt. |
||
920 | * - MC_IT_ADT: Automatic Data Transfer Interrupt. |
||
921 | * - MC_IT_OTC: Overflow of Tacho counter Interrupt. |
||
922 | * - MC_IT_CPT: Capture of Tacho counter Interrupt. |
||
923 | * - MC_IT_CM0: Compare 0 Interrupt. |
||
924 | * Output : None |
||
925 | * Return : None |
||
926 | *******************************************************************************/ |
||
927 | void MC_ClearITPendingBit(u16 MC_IT) |
||
928 | { |
||
929 | /* Clear the corresponding interrupt pending bit */ |
||
930 | MC->IPR &= ~MC_IT; |
||
931 | } |
||
932 | |||
933 | /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |