This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2541: PWM using Timer4 free-runing with Set output on compare-up, clear on 0

Part Number: CC2541

I corded as below for motor throttling using PWM. "motorPWM" will run when speed value is changed from a smartphone.

I used Timer4 with "free-runing mode" with  "Set output on compare-up, clear on 0" mode to make PWM signal.

PWM siganl changes well until 50% duty as "speed" value increases to 127.  

When "speed value" is over 127 such as 128 and more,  duty becoms suddenly 0%.

Could you anyone let me know what is wrong or missing in my cord?

 

/** \brief Motor reference value */
#define MOTER1_CENTER            0
#define MOTER2_CENTER            0

'

'

//Initialize Timer 4
    T4CC1 = MOTER1_CENTER;       
    T4CC0 = MOTER1_CENTER;       
    T4CCTL0 = 0x1C;              //IM=0, SET OUT ON COMPARE-UP, CLEAR ON 0 output on compare  (00011100)   
    T4CCTL1 = 0x1C;              
    T4CTL = 0xE4;;        

'

'

void motorPWM(int8 speed)
{
   
      
  if (speed > 2)
    {T4CC0 = ~speed;    // PWM VALUE FOR MOTOR 1 
     T4CC1 = ~speed;    // PWM VALUE FOR MOTOR 1
     T4CTL |= 0x10;                   // Timer 4 Start 
    }
  else
    {
      T4CTL &= ~0x10;     // Timer 4 Stop
      T4CTL |= 0x04;      // Timer 4 Clear
      T4CC0 = 0;          // PWM = 0 for Motor1
      T4CC1 = 0;          // PWM = 0 for Motor2
      }

Thanks

Ken Kim