Pulse-Width Modulation (PWM)

what is it?

pwm1.jpg pulse-width modulation (PWM) is literally what it sounds like, the width of the pulse and how it is modulated. PWM allows the user to generate a square signal with a user determined frequency/period and duty cycle.

the PWM frequency is calculated with equation:

Fpwm = Ftpmck/(TPMMOD + 1)

  • Fpwm is the frequency of the PWM.
  • Ftpmck is the frequency of the TPM increments in Hz.
  • TPMMOD is the modulo value stored into the TPMMOD register.

the duty cycle is the ratio between TPMMOD + 1 and the TPMCxV values:

duty cycle = ((TPMMOD + 1)/TPMCxV) * 100

so for our case:

  • TPM1MOD = 511
  • TPM1C0V = 256
  • then the duty cycle would equal 50%

why do we want this?

with a PWM we are able to focus our IR receiver on a specific IR frequency so that a lot of other lights such as sunlight and flashlights will not affect the the sensor. also, when coded with a timer, the PWM can save power by turning on for a short period of time and then going back to sleep. the timer would then wake it up again a certain period of time later and the PWM would then do its job and go back to sleep.

to sum it up, the PWM:

  • helps focus received frequency
  • save power

what we are using

the following is a list of the code we are using and why its set to those values (please purchase a copy of 'HCS08 Unleashed' for full details):

  • TPM1SC = 0×08;

TPMSC takes a hex value. this code is used to set the TPM clock equal to the BUSCLK. the hex code states that bit 3 is high and for the coding of the TPMSC, only bit 3 high sets the TPM clock equal to the BUSCLK.

  • TPM1MOD = 511;

TPMMOD takes a positive integer. this code is used to set the PWM frequency equal to 40kHz. Based on the equation above, the TPMSC/TPMMOD equals PWM frequency.

  • TPM1C0SC = 0×28;

TPMCxSC takes a hex value. this code is used to set channel x to high-true PWM mode. the hex code states that bits 3 and 5 are high and for the coding of the TPMCxSC, only bits 3 and 5 high sets the channel to high-true PWM mode.

  • TPM1C0V = 256;

TPMCxV takes a positive integer. this code is used to determine the duty cycle. based on the equation above, (TPMMOD/TPMCxV) * 100 equals the duty cycle.

quick block diagram

power calculations

LEDRadioshack IR detTSOP32228 IR det
res in series 100 ohm - -
volt of res .74V - -
Amperage 7.4mA .6mA 5mA
Voltage 3.3V 3.3V 5V
Power Usage 24mW 2mW 25mW

therefore:

  • LED + R.S. det = 26mW
  • LED + TSOP det = 49mW

The following battery comparison chart is from zbattery.com

 
Back to top
projects/securouter/tripwire/pwm.txt · Last modified: 2009/01/21 22:57 by rob3ar
 
 
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0