Page 241 - Mechatronics with Experiments
P. 241
MICROCONTROLLERS 227
OpenRBxINT (PORTB_CHANGE_INT_ON & RISING_EDGE_INT & PORTB_PULLUPS_ON );
/∗ Enable interrupts for PORTB pin x ∗/
CloseRBxINT () ; /∗ Disable ......................... ∗/
EnablePullups() ; /∗ Enable the internal pull-up resistors on PORTB ∗/
DisablePullups(); /∗ Disable ...................................... ∗/
PWM Input and PWM Output Signal An analog value, that is a value other
than two state (ON or OFF), can be coded to a pulse-width value signal which is called
pulse-width-modulation (PWM). The advantage of a PWM signal over an analog voltage
level signal is its immunity against noise. For instance, if we have an analog voltage level
signal in the 0 VDC to 10 VDC range, such as 4 VDC level, a noise voltage level of 0.1 V
results in 2.5% error in the signal value. However, if the same signal is coded as a PWM
signal as 40% duty cycle (that is the signal is at ON state (i.e., 5 VDC) for 40% of the
time and OFF state (i.e., 0 VDC) the other 60% of the time, the 0.1 VDC noise is not large
enough to confuse or change the ON/OFF level of the signal, and hence results in no error
in the signal. In short, PWM signals are more robust and insensitive to noise compared to
analog voltage level signals.
There are two variables that define a PWM signal (Figure 4.9):
1. PWM frequency,
2. duty cycle.
t cycle
y(t)
25% t ON
t OFF
Time
y(t)
50%
Time
y(t)
75%
Time
FIGURE 4.9: PWM signal: frequency and duty cycle. Examples shown are for 25, 50, 75% duty
cycle.