SDAA116 October 2025 CC2340R5
Figure 4-1 shows a code block diagram of the processes used inside the CC2340R5 code. The Zigbee functionality is available from window_covering.c while the motor operation is realized in the bdc_motor.c file.
Figure 4-1 BDC Motor Code DiagramThe main function initializes all TI drivers and timers necessary for the BDC motor example to operate. Once entering the main while loop, this pends further action on an event being set by hardware callbacks. For the provided application, these hardware callbacks are triggered by pressing the push buttons on the LaunchPads. After servicing the corresponding action through a subroutine, the events are reset and the process repeats.
All hardware callbacks, with a few exceptions, simply post an event for the main application to process. An exception is the ADCBuf callback which processes the status immediately and does not call for any further action from the main application loop.
There are several definitions implemented which define the motor behavior and are referenced in the following sections. These configurable definitions are located in bdc_motor.c.
| Definition | Default | Units | Function |
|---|---|---|---|
| PWM_PERIOD | 100 | µs | Duration of one PWM cycle |
| PWM_DUTY_INC | 100 | µs | Duration to increment PWM duty cycle during acceleration or decrement during deceleration |
| PWM_START_POINT | 0 | µs | PWM duty value to accelerate from/to decelerate to. Generally, is set to zero |
| PWM_END_POINT | 100 | µs | PWM duty value to accelerate to/ to decelerate from. In this case, this is set as the same value as the PWM_PERIOD for 100% duty cycle |
| ADCBUF_SAMPLE_SIZE | 100 | Integer | Size of ADC buffer transferred by DMA |
| ADCBUF_SAMPLING_FREQ | 1000 | Hz | Sampling frequency of the ADC. Note that the frequency of ADC buffers completed is equal to ADCBUF_SAMPLING_FREQ / ADCBUF_SAMPLE_SIZE |
| USE_HALL | Defined | N/A | Determines whether the hall effect sensor is used during functionality or not |
| STALL_TIMEOUT | 1000000 | µs | Timeout to stop motor if the motor has not been moving for this amount of time as detected by the hall effect sensor when USE_HALL is defined |
| MOVEMENT_TIME | 3000000 | µs | Timeout period to stop motor if the motor has been spinning longer than this duration, if USE_HALL is not defined |
| OCP_THRESHOLD | 800000 | µV | Minimum value of averaged ADC buffer to trigger an overcurrent condition |