Module pwm.common
- Common routines for configuring PWM on the ATmega family of processors
Common routines for configuring PWM on the ATmega family of processors.
The operation of PWMs might be improved and made to be significantly more modular and robust if turned into a PROTOCOL based process. This can be done Later.
Index
-
Process
pwm16.set.compare
- Sets the compare register on the given PWM pin -
Process
pwm16.set.top
- Sets the 'top' register on the given PWM pin -
Process
pwm16.setup
- Sets up phase-and-frequency-correct Pulse Width Modulation on a 16 bit timer -
Process
pwm8.set.compare
- Sets the compare register on the given PWM pin -
Process
pwm8.setup
- Sets up phase-correct Pulse Width Modulation on an 8 bit timer -
Process
set16
- Effectively sets a 16bit register
Declarations
pwm.common.module
:53Process set16
INLINE PROC set16 (VAL INT reg, VAL INT val)
Effectively sets a 16bit register. The incoming INT is broken up into a pair BYTEs, each is then written into a pair of adjacent registers that act as a single 16bit number.
We're operating under the assumption that the high byte is always one greater than the low byte. Honestly not that trilled about it, but it seems to work.
An example:
- OCR1A = OCR1AL
- OCR1AL + 1 = OCR1AH
According to the datasheet, we always have to write the high byte first.
Parameters:
VAL INT |
reg |
The low register to be written to -- The high register (to which the higher-half of the INT gets written to) will be found automagically. |
VAL INT |
val |
The value to be written into the register pair. |
pwm.common.module
:67Process pwm8.set.compare
PROC pwm8.set.compare (VAL INT avr.pin, VAL BYTE level)
Sets the compare register on the given PWM pin.
Parameters:
VAL INT |
avr.pin |
The AVR pin to activate PWM on. |
VAL BYTE |
level |
The new level to set the compare register to. |
pwm.common.module
:83Process pwm16.set.compare
PROC pwm16.set.compare (VAL INT avr.pin, VAL INT level)
Sets the compare register on the given PWM pin.
Parameters:
VAL INT |
avr.pin |
The AVR pin to activate PWM on. |
VAL INT |
level |
The new level to set the compare register to. |
pwm.common.module
:98Process pwm16.set.top
PROC pwm16.set.top (VAL INT avr.pin, VAL INT top)
Sets the 'top' register on the given PWM pin. This effects the highest number the timer (which must be a 16 bit timer) will count up to before beginning its down-count.
Parameters:
VAL INT |
avr.pin |
The AVR pin to activate PWM on. |
VAL INT |
top |
The new top to set the 'top' register. |
pwm.common.module
:114Process pwm8.setup
PROC pwm8.setup (VAL INT avr.pin, prescale)
Sets up phase-correct Pulse Width Modulation on an 8 bit timer.
Be aware that not every pin on any given board or architecture can be operated as a PWM Pin. Consult your board for information on which pins can produce PWM.
Parameters:
VAL INT |
avr.pin |
The AVR pin to activate PWM on. |
VAL INT |
prescale |
The prescaler value to set with PWM. |
pwm.common.module
:142Process pwm16.setup
PROC pwm16.setup (VAL INT avr.pin, prescale)
Sets up phase-and-frequency-correct Pulse Width Modulation on a 16 bit timer.
Be aware that not every pin on any given board or architecture can be operated as a PWM Pin, and not every PWM pin operates on a 16 bit timer.
Consult your board's reference manual for information on which pins can produce 16 bit PWM.
Parameters:
VAL INT |
avr.pin |
The AVR pin to activate PWM on. |
VAL INT |
prescale |
The prescaler value to set with PWM. |