Playing with Arduino
A page to record my playing with Arduino
turnOffPWM()

Abstract

The turnOffPWM() stops PWM output of a specified timer. Please refer to the explanation of the analogWrite().

Stopping the PWM output is carried out by controlling timer/counter register.

Source Code

The turnOffPWM() is defined in hardware/arduino/avr/cores/arduino/wiring_digital.c as below. The function deals with many chips using #ifs.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
static void turnOffPWM(uint8_t timer)
{
    switch (timer)
    {
        case TIMER1A:   cbi(TCCR1A, COM1A1);    break;
        case TIMER1B:   cbi(TCCR1A, COM1B1);    break;
        case  TIMER0A:  cbi(TCCR0A, COM0A1);    break;
        case  TIMER0B:  cbi(TCCR0A, COM0B1);    break;
        case  TIMER2A:  cbi(TCCR2A, COM2A1);    break;
        case  TIMER2B:  cbi(TCCR2A, COM2B1);    break;
    }
}

The input is timer and its type is uint8_t. According to the value of timer, it operates the compare match output bit of Timer/Counter Control Registers(TCCRnx) to stop the output.

The cbi() is a macro to set the bit(the second argument) of the address(the first argument) to 0.

Version

Arduino 1.8.13

Last Update

June 19, 2020

inserted by FC2 system