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.

PWM generation using software by UCD3138

Other Parts Discussed in Thread: UCD3138

Hi All,

I am using UCD3138, and I  have to use TCAP pin to generate PWM signals(all of my other DPWM modules as well as PWM outputs are busy) to control  a fan. At this point, I just want to make sure that I can generate some PWM signals using software on pin TCAP. As I am a hardware engineer, I am not so familiar with software.I came up with the following codes: Can you please let me know if it will be giving me PWM signals on TCAP? (Forget about the duty cycle and frequency at this point):

   for(;;)
    {
// Set pin TCAP to 1
  MiscAnalogRegs.GLBIOEN.bit.TMR_CAP_IO_EN = 1; // enable TCAP as GPIO
  MiscAnalogRegs.GLBIOOE.bit.TMR_CAP_IO_OE = 1; // make it output
  MiscAnalogRegs.GLBIOVAL.bit.TMR_CAP_IO_VALUE = 1;  // set output to high

// Set Timer3 to generate delay=duty cycle


   TimerRegs.T16PWM3CMP0DAT.bit.CMP_DAT = 1587; // Value to reset the counter and specify duty cycle

   TimerRegs.T16PWM3CMPCTRL.bit.CMP0_INT_ENA = 1; // interrupt when reset

   TimerRegs.T16PWM3CNTCTRL.bit.CMP_RESET_ENA = 1; // enable reset by comp0

    TimerRegs.T16PWM3CNTCTRL.bit.SW_RESET = 1; // allow counter to run
  TimerRegs.T16PWM3CMPCTRL.all |= 3; // clear interrupt flag
 
  // Set pin TCAP to 0
   MiscAnalogRegs.GLBIOVAL.bit.TMR_CAP_IO_VALUE = 0; // set output to high
 
// Set Timer3 to generate delay=off-time
    TimerRegs.T16PWM3CMP0DAT.bit.CMP_DAT = 1587; // Value to reset the counter and specify duty cycle

    TimerRegs.T16PWM3CMPCTRL.bit.CMP0_INT_ENA = 1; // interrupt when reset

     TimerRegs.T16PWM3CNTCTRL.bit.CMP_RESET_ENA = 1; // enable reset by comp0

    TimerRegs.T16PWM3CNTCTRL.bit.SW_RESET = 1; // allow counter to run

    TimerRegs.T16PWM3CMPCTRL.all |= 3;  // clear interrupt flag

   }

Thanks all in advance

  • Sina,

    This is very do-able. In-fact toggling a GPIO to emulate a PWM to be used as fan control has been done several times before.

    However, the drawback is that this will take MIPS (Millions of instructions per second) to control. This will effectively lower the available bandwidth of the UCD3138 and can make it run "slower" which could possible cause some problems.

    If you are toggling the GPIO at low frequencies, this will help to reduce the toll on the device.

    Will your fan need to be closed loop? Will you need to measure the speed of the fan and control the duty cycle of the GPIO?

    Regards,

    Brandon Vonk