SDAA116 October   2025 CC2340R5

 

  1.   1
  2.   Abstract
  3.   Trademarks
  4. 1Introduction
    1. 1.1 CC2340R5
    2. 1.2 DRV8251A
    3. 1.3 BDC Motor
    4. 1.4 TMAG5213
  5. 2BDC Application
    1. 2.1 Hardware Setup
      1. 2.1.1 DRV8251AEVM Settings
    2. 2.2 Connection Diagram
  6. 3Running the Example
    1. 3.1 Dependencies
    2. 3.2 Loading Firmware
    3. 3.3 Zigbee Network Formation
  7. 4Firmware Design
    1. 4.1 Code Flow Description
    2. 4.2 LaunchPad Button Functionality
    3. 4.3 Non-Volatile Memory
    4. 4.4 Bidirectional PWM Motor Control
    5. 4.5 ADC Overcurrent Protection Feature
    6. 4.6 Hall-Effect Based Motor Position Tracking Feature with Configurable Endpoints
    7. 4.7 Logging Functionality
    8. 4.8 Interoperability with Third-Party Smart Hub Devices
  8. 5Tests and Results
    1. 5.1 PWM and Hall-effect Signal Analysis
    2. 5.2 Power Consumption Analysis with EnergyTrace™
  9. 6Summary
  10. 7References

Code Flow Description

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.

 BDC Motor Code Diagram Figure 4-1 BDC Motor Code Diagram

The 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.

Table 4-1 BDC Motor Application Defined
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