iLLD_TC27xC  1.0
How to use the CCU6 PWMBC Interface driver?
Collaboration diagram for How to use the CCU6 PWMBC Interface driver?:

The PWMBC interface driver provides a default CCU6 configuration specifically for running a Brush Less DC Motor using hall sensor inputs, by utilising both the timers

After evaluating the hall input pattern at every T13 period match, new out pattern is given to the module after the phase delay at the T13 zero match

User has to prepare the control table for the respective motor he/she is using,

In the following sections it will be described, how to integrate the driver into the application framework.

Preparation

Include Files

Include following header file into your C code:

Variables

Declare the PWMBC handle and the motor control table as global variables in your C code:

// used globally
static IfxCcu6_PwmBc pwmBc;
// prepare the control table
uint8 controlTable[6][3] = {{1, 5, 17} ,
{2, 3, 36} ,
{3, 1, 6} ,
{4, 6, 18} ,
{5, 4, 24} ,
{6, 2, 9}};
// to store value of the speed
uint32 speed = 0;

Interrupt Handler Installation

See also How to define Interrupts?

Define priority for the Interrrupt handler. This is normally done in the Ifx_IntPrioDef.h file:

// priorities are normally defined in Ifx_IntPrioDef.h
#define IFX_INTPRIO_CCU6 1

Add the interrupt service routine to your C code.

IFX_INTERRUPT(ccu60ISR_PwmBc, 0, IFX_INTPRIO_CCU6)
{
//user code
}

Finally install the interrupt handlers in your initialisation function:

// install interrupt handlers
IfxCpu_Irq_installInterruptHandler(&ccu60ISR_PwmBc, IFX_INTPRIO_CCU6);

Module Initialisation

The module initialisation can be done in the same function. Here an example:

// create configuration
IfxCcu6_PwmBc_initModuleConfig(&pwmBcConfig, &MODULE_CCU60);
// configure the frequencies of both the timers
pwmBcConfig.base.t12Frequency = 400000;
pwmBcConfig.base.t13Frequency = 400000;
// configure the periods of both the timers
pwmBcConfig.base.t12Period = 100;
pwmBcConfig.base.t13Period = 100;
// configure the phase delay and noise filter for hall input
pwmBcConfig.base.phaseDelay = 20;
pwmBcConfig.base.noiseFilter = 10;
// select the active state of the output
// configure timer12
pwmBcConfig.timer12.counterValue = 0;
// configure timer13
pwmBcConfig.timer13.counterValue = 0;
pwmBcConfig.timer13.compareValue = 100;
// configure the syncronisation, in case of sync start with T12
// configure hall sync event that starts the hall input pattern evaluation
// configure multi channel control
// pin configuration
const IfxCcu6_PwmBc_Pins pins = {
IfxCcu60_CC60_P02_0_OUT, // CC60Out pin
IfxCcu60_CC61_P02_2_OUT, // CC61Out pin
IfxCcu60_CC62_P02_4_OUT, // CC62Out pin
IfxCcu60_COUT60_P02_3_OUT, // COUT61 pin
IfxCcu60_COUT60_P02_5_OUT, // COUT62 pin
NULL, // COUT63 pin not used
IfxCcu60_COUT60_P02_6_OUT // CCPOS0In pin
IfxCcu60_COUT60_P02_7_OUT // CCPOS1In pin
IfxCcu60_COUT60_P02_8_OUT // CCPOS2In pin
};
pwmBcConfig.pins = &pins;
// configure the interrupts
pwmBcConfig.interrupt.priority = IFX_INTRPRIO_CCU6;
// configure input and output triggers
// initialize the module
IfxCcu6_PwmBc_initModule(&pwmBc, &pwmBcConfig);

The PwmBc is ready for use now!

Modulation Control

The PWMBC driver provides simple to use Motor Control functions

This means: you can start, stop, the BLDC motor once the module is initialised with the appropriate configuration You can optionally get the speed of the motor at any point of time

Start the motor

Stop the motor

Update the output pattern

// prepare the control table
// assumed to be declared globally
uint8 controlTable[6][3] = {{1, 5, 17} ,
{2, 3, 36} ,
{3, 1, 6} ,
{4, 6, 18} ,
{5, 4, 24} ,
{6, 2, 9}};
// update the output pattern
IfxCcu6_PwmBc_updateHallPattern(&pwmBc, controlTable[6][3]);

Get the current motor speed (can also be called in ISR)

// assumed to be declared globally
uint32 speed = 0;
// get the current motor speed