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.

TM4C1294NCPDT: TM4C1294NCPDT

Part Number: TM4C1294NCPDT

Hi,

I am using T0CCP0, and T0CCP1 pins to control my fans with PWM. I am able to enable or change the dutyCycle but I am not able to turn the fans off completely. Which I want to turn them off completely. Any idea what is wrong in the code. Please see code below. TimerDisable(TIMER0_BASE, TIMER_A) does not work in this matter. I have to use T0CCP0 and T0CCP1, cannot use other pwm pins. Thanks.

  

    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    while (!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD))
        ;
    GPIOPinConfigure(GPIO_PD0_T0CCP0);
    GPIOPinConfigure(GPIO_PD1_T0CCP1);
    GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    TimerConfigure(TIMER0_BASE,
    TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM | TIMER_CFG_B_PWM);
    TimerLoadSet(TIMER0_BASE, TIMER_A, g_period);
    TimerLoadSet(TIMER0_BASE, TIMER_B, period);
    TimerMatchSet(TIMER0_BASE, TIMER_A,dutyCycle);
    TimerMatchSet(TIMER0_BASE, TIMER_B,dutyCycle);
    TimerEnable(TIMER0_BASE, TIMER_A);
    TimerEnable(TIMER0_BASE, TIMER_B);

    int counter = 0;
    for (counter = 0; counter < 6000000; ++counter)
    {

    }
    TimerDisable(TIMER0_BASE, TIMER_A);
    TimerDisable(TIMER0_BASE, TIMER_B);

  • Hi,
    What do you mean you can not turn off the fan completely. Do you have the scope capture to show the state of CCP0 and CCP1 after disable the timer?
    If you want the CCP0/1 to be in active state then you want to add
    TimerControlLevel(TIMER0_BASE, TIMER__BOTH, true);
  • Hi Charles,

    By saying "cant turn off the fan". I want to make duty cycle 0. I want it to stop. Until I turn it on (make duty cycle some number). Basically, what I want to do is. turn the fan on when the temp. goes up and turn off or reduce the speed when the temp. is within normal temp.

    So I enable the timers and let the fan run with speed but I cannot turn it off with disabling the timer with TImerDisable(...). But with the TimerControlLevel(TIMER0_BASE, TIMER_BOTH, true); I was able to shut off the fan and turn it back on when I wanted. Which is what I was trying to achieve. But I wonder what is the affect of using TImerDisable(...)?

    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    while (!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD))
        ;
    GPIOPinConfigure(GPIO_PD0_T0CCP0);
    GPIOPinConfigure(GPIO_PD1_T0CCP1);
    GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    TimerConfigure(TIMER0_BASE,
    TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM | TIMER_CFG_B_PWM);
    TimerLoadSet(TIMER0_BASE, TIMER_A, g_period);
    TimerLoadSet(TIMER0_BASE, TIMER_B, period);
    TimerMatchSet(TIMER0_BASE, TIMER_A,dutyCycle);
    TimerMatchSet(TIMER0_BASE, TIMER_B,dutyCycle);
    TimerEnable(TIMER0_BASE, TIMER_A);
    TimerEnable(TIMER0_BASE, TIMER_B);
     
    int counter = 0;
    for (counter = 0; counter < 6000000; ++counter)
    {
     
    }
    TimerControlLevel(TIMER0_BASE, TIMER_BOTH, true);
    for (counter = 0; counter < 6000000; ++counter)
    {
     
    }
    TimerControlLevel(TIMER0_BASE, TIMER_BOTH, false);
  • The reason is that at the moment when you turn off the timer the timer CCP pin may be in the state of high. When it is still high it is asserting 100% duty cycle to your fan. It could be possible that the moment you turn off the timer the CCP is still in the state of low and in this case your fan is turned off. With the TimerControlLevel, the CCP0 will be asserted to its active state after it is turned off and when the counter expires.
  • Thanks for the help Charles. I got another weird problem not sure why this is happening but once i play with the speed the fan does not turn off but gets the max power. Please see the code below.

    typedef enum
    {
    OFF = 0, LOW = 3000, MEDIUM = 2500, HIGH = 1250, MAX = 10000,
    } Speed;


    period=10000;
    dutyCycle=10000;

    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    while (!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD))
    ;
    GPIOPinConfigure(GPIO_PD0_T0CCP0);
    GPIOPinConfigure(GPIO_PD1_T0CCP1);
    GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    TimerConfigure(TIMER0_BASE,
    TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM | TIMER_CFG_B_PWM);
    TimerLoadSet(TIMER0_BASE, TIMER_A, period);
    TimerLoadSet(TIMER0_BASE, TIMER_B, period);
    TimerMatchSet(TIMER0_BASE, TIMER_A,dutyCycle);
    TimerMatchSet(TIMER0_BASE, TIMER_B,dutyCycle);
    TimerEnable(TIMER0_BASE, TIMER_BOTH);

    change_speed(HIGH);
    change_speed(LOW);
    change_speed(OFF);//Here it gets back to max speed.


    change_speed(Speed speed){
    if (speed == OFF)
    {
    TimerDisable(TIMER0_BASE, TIMER_BOTH);
    TimerControlLevel(TIMER0_BASE, TIMER_BOTH, true);
    return;
    }else{
    TimerEnable(TIMER0_BASE, TIMER_BOTH);
    TimerControlLevel(TIMER0_BASE, TIMER_BOTH, false);
    TimerMatchSet(TIMER0_BASE, TIMER_BOTH, speed);
    }

    }

  • Try to put the TimerControlLevel before the TimerDisable and see if that helps. And I don't understand why you want to change the TimerControlLevel to false in your change_speed(). You should just have TimerControlLevel configured to true and called one time in your initialization. Try that too.
  • Charles,

    As you suggested, I put the "TimerControlLevel before the TimerDisable ". It did not change anything. I change TimerControlLevel to false in change_speed(). Because I thought that way I can turn the fan on with desired speed. Also I tried "you should just have TimerControlLevel configured to true and called one time in your initialization. Try that too." But then it does unexpected behavior. For instance, if I change it to  MAX it turns off the fan, changing to MEDIUM does not turn the fan,changing to OFF puts it to max speed. I am not sure what the problem is. I am trying to run the fan based on the speed value and turn it off it the speed 0 is passed to change_speed(). Please see the code below.

    typedef enum
    {
    OFF = 0, LOW = 3000, MEDIUM = 2500, HIGH = 1250, MAX = 10000,
    } Speed;


    period=10000;
    dutyCycle=10000;

    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    while (!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD))
    ;
    GPIOPinConfigure(GPIO_PD0_T0CCP0);
    GPIOPinConfigure(GPIO_PD1_T0CCP1);
    GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    TimerConfigure(TIMER0_BASE,
    TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM | TIMER_CFG_B_PWM);
    TimerLoadSet(TIMER0_BASE, TIMER_A, period);
    TimerLoadSet(TIMER0_BASE, TIMER_B, period);
    TimerMatchSet(TIMER0_BASE, TIMER_A,dutyCycle);
    TimerMatchSet(TIMER0_BASE, TIMER_B,dutyCycle);
    TimerEnable(TIMER0_BASE, TIMER_BOTH);

    TimerControlLevel(TIMER0_BASE, TIMER_BOTH, true);

    change_speed(HIGH);
    change_speed(LOW);
    change_speed(OFF);//Here it gets back to max speed.


    change_speed(Speed speed){
    if (speed == OFF)
    {
    TimerDisable(TIMER0_BASE, TIMER_BOTH);

    return;
    }else{
    TimerEnable(TIMER0_BASE, TIMER_BOTH);
    TimerMatchSet(TIMER0_BASE, TIMER_BOTH, speed);
    }

    }

  • Try not to use 0% and 100%. These are boundary conditions where it may not work perfectly. Try with 0.1% and 99.9% duty cycle first to confirm if it makes a difference and we can confirm if my theory holds.
  • It still does the same thing with 0.1% and 99.9% duty cycle. Not always but sometimes OFF makes it go MAX.
    If I put on HIGH the leds are on and I see the correct duty cycle on the scopemeter but fan does not turn on. If you go as MEDIUM(which does not never turns the fan but duty cycle is is seen on the scopemeter). Cant figure out what the problem is.
  • If you see proper duty cycle on the scope then the MCU is behaving correctly. You need to check your fan. are you connecting the MCU directly to the fan? Do you ave the transistor driver in between? How much current does the fan source? You need to check all these and do your debugging. Again, use the scope to check the duty cycle and period without the fan. If they are proper then the MCU is running as expected. You need to debug the rest of stuffs on your system.

    This article may help.

    https://www.baldengineer.com/pwm-3-pin-pc-fan-arduino.html