iLLD_TC27xC  1.0
IfxCcu6_PwmBc.c
Go to the documentation of this file.
1 /**
2  * \file IfxCcu6_PwmBc.c
3  * \brief CCU6 PWMBC details
4  *
5  * \version iLLD_0_1_0_10
6  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
7  *
8  *
9  * IMPORTANT NOTICE
10  *
11  *
12  * Infineon Technologies AG (Infineon) is supplying this file for use
13  * exclusively with Infineon's microcontroller products. This file can be freely
14  * distributed within development tools that are supporting such microcontroller
15  * products.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
18  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
20  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
21  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
22  *
23  *
24  */
25 
26 /******************************************************************************/
27 /*----------------------------------Includes----------------------------------*/
28 /******************************************************************************/
29 
30 #include "IfxCcu6_PwmBc.h"
31 
32 /******************************************************************************/
33 /*-------------------------Function Implementations---------------------------*/
34 /******************************************************************************/
35 
37 {
38  uint32 currentTime, previousTime;
39  float32 speed;
40 
43 
44  // TODO -- FIX IT --
45  speed = (currentTime - previousTime) * (6 / (pwmBc->base.t13Frequency));
46  speed = speed * 60 * 100000; //convertion to RPM (minutes),
47  return speed;
48 }
49 
50 
52 {
53  Ifx_CCU6 *ccu6SFR = config->ccu6; // pointer to CCU6 registers
54  pwmBc->ccu6 = ccu6SFR; // adding register pointer to module handler
55 
56  /* -- hardware module initialisation -- */
57 
58  // enable module if it hasn't been enabled by any other interface //
59  if (IfxCcu6_isModuleEnabled(ccu6SFR) == FALSE)
60  {
61  IfxCcu6_enableModule(ccu6SFR);
62  }
63 
64  /* -- Timer13 initialisation -- */
65 
66  // enable Timer13 if it hasn't been enabled by any other interface //
68  {
70  }
71 
72  // clock initialisation //
73  pwmBc->base.t13Frequency = IfxCcu6_setT13Frequency(ccu6SFR, config->base.t13Frequency, config->base.t13Period);
74 
75  // duty cycle initialisation //
76 
78 
80 
81  // if Timer 13 start is in sync with Timer 12 //
82 
83  if (config->trigger.t13InSyncWithT12)
84  {
87  }
88 
89  /* -- Timer12 initialisation -- */
90 
91  // enable Timer12 if it hasn't been enabled by any other interface //
93  {
95  }
96 
97  // clock initialisation //
98 
99  IfxCcu6_setT12Frequency(ccu6SFR, config->base.t12Frequency, config->base.t12Period, config->timer12.countMode);
100 
101  // duty cycle initialisation //
102 
104 
105  // hall effect noise filter initialisation
106  if (config->base.noiseFilter)
107  {
108  IfxCcu6_setDeadTimeValue(ccu6SFR, config->base.noiseFilter);
111  }
112 
113  // channel initialisation for hall sensor mode ( for Brush Less DC motor)
117 
118  // phase delay initialisation
120 
121  // multichannel control / output pattern control initialisation
124 
125  /* -- output path initialisation -- */
126 
127  //enable Timer13 modulation output path for all T12 channel outs//
128 
132 
133  if (config->pins->cout63 != NULL_PTR)
134  {
136  }
137 
138  // output passive logic configuration //
139  //TODO check correct polarity:
140 
144 
145  if (config->pins->cout63 != NULL_PTR)
146 
147  {
149  }
150 
151  /* -- Pin mapping -- */
152 
153  const IfxCcu6_PwmBc_Pins *pins = config->pins;
154 
155  if (pins != NULL_PTR)
156  {
157  // modulation output pins
158 
159  IfxCcu6_Cc60_Out *cc60Out = pins->cc60Out;
160 
161  if (cc60Out != NULL_PTR)
162  {
163  IfxCcu6_initCc60OutPin(cc60Out, pins->outputMode, pins->pinDriver);
164  }
165 
166  IfxCcu6_Cc61_Out *cc61Out = pins->cc61Out;
167 
168  if (cc61Out != NULL_PTR)
169  {
170  IfxCcu6_initCc61OutPin(cc61Out, pins->outputMode, pins->pinDriver);
171  }
172 
173  IfxCcu6_Cc62_Out *cc62Out = pins->cc62Out;
174 
175  if (cc62Out != NULL_PTR)
176  {
177  IfxCcu6_initCc62OutPin(cc62Out, pins->outputMode, pins->pinDriver);
178  }
179 
180  IfxCcu6_Cout60_Out *cout60 = pins->cout60;
181 
182  if (cout60 != NULL_PTR)
183  {
184  IfxCcu6_initCout60Pin(cout60, pins->outputMode, pins->pinDriver);
185  }
186 
187  IfxCcu6_Cout61_Out *cout61 = pins->cout61;
188 
189  if (cout61 != NULL_PTR)
190  {
191  IfxCcu6_initCout61Pin(cout61, pins->outputMode, pins->pinDriver);
192  }
193 
194  IfxCcu6_Cout62_Out *cout62 = pins->cout62;
195 
196  if (cout62 != NULL_PTR)
197  {
198  IfxCcu6_initCout62Pin(cout62, pins->outputMode, pins->pinDriver);
199  }
200 
201  IfxCcu6_Cout63_Out *cout63 = pins->cout63;
202 
203  if (cout63 != NULL_PTR)
204  {
205  IfxCcu6_initCout63Pin(cout63, pins->outputMode, pins->pinDriver);
206  }
207 
208  // hall sensor input pins
209 
210  IfxCcu6_Ccpos0_In *ccpos0 = pins->ccpos0;
211 
212  if (ccpos0 != NULL_PTR)
213  {
214  IfxCcu6_initCcpos0Pin(ccpos0, pins->inputMode);
215  }
216 
217  IfxCcu6_Ccpos1_In *ccpos1 = pins->ccpos1;
218 
219  if (ccpos1 != NULL_PTR)
220  {
221  IfxCcu6_initCcpos1Pin(ccpos1, pins->inputMode);
222  }
223 
224  IfxCcu6_Ccpos2_In *ccpos2 = pins->ccpos2;
225 
226  if (ccpos2 != NULL_PTR)
227  {
228  IfxCcu6_initCcpos2Pin(ccpos2, pins->inputMode);
229  }
230 
231  IfxCcu6_T12hr_In *t12hr = pins->t12hr;
232 
233  if (t12hr != NULL_PTR)
234  {
235  IfxCcu6_initT12hrPin(t12hr, pins->t1xhrInputMode);
236  }
237 
238  IfxCcu6_T13hr_In *t13hr = pins->t13hr;
239 
240  if (t13hr != NULL_PTR)
241  {
242  IfxCcu6_initT13hrPin(t13hr, pins->t1xhrInputMode);
243  }
244  }
245 
246  /* -- hall pattern configuration (when to start the hall pattern evaluation) -- */
247 
249 
250  /* -- interrupt initialisation -- */
251 
254 
255  if (config->interrupt.priority > 0)
256  {
257  volatile Ifx_SRC_SRCR *src;
258  src = IfxCcu6_getSrcAddress(ccu6SFR, config->interrupt.serviceRequest);
259  IfxSrc_init(src, config->interrupt.typeOfService, config->interrupt.priority);
260  IfxSrc_enable(src);
261  }
262 
263  /* -- output trigger initialisation --*/
264 
265  if (config->trigger.outputTriggerEnabled)
266  {
268  }
269 
270  pwmBc->trigger = config->trigger;
271  pwmBc->hallPatternIndex = 0;
272 
273 #if IFX_CFG_USE_STANDARD_INTERFACE
274  IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, (uint32)pwmBc == ((uint32)&pwmBc->base));
275  pwmBc->base.functions.start = (PwmBc_Start) & IfxCcu6_PwmBc_start;
276  pwmBc->base.functions.stop = (PwmBc_Stop) & IfxCcu6_PwmBc_stop;
277  pwmBc->base.functions.updateHallPattern = (PwmBc_UpdateHallPattern) & IfxCcu6_PwmBc_updateHallPattern;
278  pwmBc->base.functions.getMotorSpeed = (PwmBc_GetMotorSpeed) & IfxCcu6_PwmBc_getMotorSpeed;
279 #endif
280 }
281 
282 
284 {
285  const IfxCcu6_PwmBc_Config defaultConfig = {
286  .ccu6 = NULL_PTR, // will be initialized below
287 
288  .base.t12Frequency = 400000,
289  .base.t13Frequency = 400000,
290  .base.t12Period = 100,
291  .base.t13Period = 100,
292  .base.phaseDelay = 20,
293  .base.noiseFilter = 10,
294  .base.activeState = Ifx_ActiveState_high,
295 
296  .timer12 = {
298  .counterValue = 0,
299  },
300 
301  .timer13 = {
302  .counterValue = 0,
303  .compareValue = 0,
304  .t12SyncEvent = IfxCcu6_T13TriggerEvent_noAction,
305  .t12SyncDirection = IfxCcu6_T13TriggerDirection_noAction,
306  },
307 
308  .hallSyncEvent = IfxCcu6_HallSensorTriggerMode_t13PM,
309 
310  .hallPatternIndex = 0,
311 
312  .multiChannelControl = {
315  },
316 
317  .pins = NULL_PTR,
318 
319  .interrupt = {
320  .interruptSource = IfxCcu6_InterruptSource_cc61FallingEdge, // after phase delay
321  .serviceRequest = IfxCcu6_ServiceRequest_sR2,
322  .priority = 0, // interrupt priority 0
323  .typeOfService = IfxSrc_Tos_cpu0, // type of service CPU0
324  },
325 
326  .trigger = {
327  .t12ExtInputTrigger = NULL_PTR,
328  .t12ExtInputTriggerMode = IfxCcu6_ExternalTriggerMode_risingEdge,
329  .t13ExtInputTrigger = NULL_PTR,
330  .t13ExtInputTriggerMode = IfxCcu6_ExternalTriggerMode_risingEdge,
331  .t13InSyncWithT12 = FALSE,
332 
333  .outputTriggerEnabled = TRUE,
334  .outputLine = IfxCcu6_TrigOut_0,
335  .outputTrigger = IfxCcu6_TrigSel_cout63,
336  },
337  };
338 
339  /* Default Configuration */
340  *config = defaultConfig;
341 
342  /* take over module pointer */
343  config->ccu6 = ccu6;
344 }
345 
346 
348 {
349  // enable shadow transfers
351 
352  // internal start
353  if ((pwmBc->trigger.t13ExtInputTrigger == NULL_PTR) && (pwmBc->trigger.t12ExtInputTrigger == NULL_PTR))
354  {
355  // if T13 start is in sync with T12 start the T12
356  if (pwmBc->trigger.t13InSyncWithT12)
357  {
358  IfxCcu6_startTimer(pwmBc->ccu6, TRUE, FALSE);
359  }
360  else // start both timers
361  {
362  IfxCcu6_startTimer(pwmBc->ccu6, TRUE, TRUE);
363  }
364  }
365 
366  // external start
367  else
368  {
369  // if T13 start is not in sync with T12
370  if (!(pwmBc->trigger.t13InSyncWithT12))
371  {
372  // T13 external start if selected
373  if (pwmBc->trigger.t13ExtInputTrigger != NULL_PTR)
374  {
377  }
378  else // internal start of T13 alone
379  {
380  IfxCcu6_startTimer(pwmBc->ccu6, FALSE, TRUE);
381  }
382  }
383  else
384  {}
385 
386  // T12 external start if selected
387  if (pwmBc->trigger.t12ExtInputTrigger != NULL_PTR)
388  {
391  }
392  else // internal start of T12 alone
393  {
394  IfxCcu6_startTimer(pwmBc->ccu6, TRUE, FALSE);
395  }
396  }
397 }
398 
399 
401 {
403 
404  // if T13 start is in sync with T12, remove sync trigger
405  if (pwmBc->trigger.t13InSyncWithT12)
406  {
409  }
410 
411  // remove external triggers if any
412  if ((pwmBc->trigger.t13ExtInputTrigger != NULL_PTR) || (pwmBc->trigger.t12ExtInputTrigger != NULL_PTR))
413  {
414  if (pwmBc->trigger.t13ExtInputTrigger != NULL_PTR)
415  {
417  }
418  else
419  {
421  }
422  }
423  else
424  {}
425 
426  // stop both timers
427  IfxCcu6_stopTimer(pwmBc->ccu6, TRUE, TRUE);
428 
429  //disable Timer13 modulation output path for all T12 channel outs//
430 
435 }
436 
437 
438 void IfxCcu6_PwmBc_updateHallPattern(IfxCcu6_PwmBc *pwmBc, uint8 controlTable[6][3])
439 {
440  uint8 index = pwmBc->hallPatternIndex;
441 
442  IfxCcu6_updateHallPattern(pwmBc->ccu6, controlTable[index][0], controlTable[index][1], controlTable[index][2]);
443 
444  index++;
445 
446  if (index >= 6)
447  {
448  index = 0;
449  }
450 
451  pwmBc->hallPatternIndex = index;
452 }