aversive_10-03-12/modules/hardware/pwm_ng/pwm_ng.c File Reference

#include <string.h>
#include <aversive.h>
#include <aversive/parts.h>
#include <aversive/timers.h>
#include "pwm_ng.h"
#include <stdio.h>

Go to the source code of this file.

Defines

#define PWM_SIGNIFICANT_BITS   12
#define PWM_MAX   ((1<< PWM_SIGNIFICANT_BITS)-1)
#define PWM_MIN   (-PWM_MAX)
#define PWM_NG_TYPE_8   0
#define PWM_NG_TYPE_16   1
#define PWM_NG_NBITS_8   0
#define PWM_NG_NBITS_9   1
#define PWM_NG_NBITS_10   2

Functions

void pwm_ng_init (struct pwm_ng *pwm, uint8_t timer_nbits, uint8_t pwm_nbits, uint8_t pwm_mode, volatile void *ocrn, uint8_t com0, volatile uint8_t *tccrn, volatile uint8_t *pwm_port, uint8_t pwm_bit, volatile uint8_t *sign_port, uint8_t sign_bit)
void pwm_ng_set (void *data, int32_t value)


Define Documentation

#define PWM_MAX   ((1<< PWM_SIGNIFICANT_BITS)-1)

Definition at line 30 of file pwm_ng.c.

#define PWM_MIN   (-PWM_MAX)

Definition at line 31 of file pwm_ng.c.

#define PWM_NG_NBITS_10   2

Definition at line 38 of file pwm_ng.c.

Referenced by pwm_ng_init().

#define PWM_NG_NBITS_8   0

Definition at line 36 of file pwm_ng.c.

Referenced by pwm_ng_init().

#define PWM_NG_NBITS_9   1

Definition at line 37 of file pwm_ng.c.

Referenced by pwm_ng_init().

#define PWM_NG_TYPE_16   1

Definition at line 34 of file pwm_ng.c.

Referenced by pwm_ng_init().

#define PWM_NG_TYPE_8   0

Definition at line 33 of file pwm_ng.c.

Referenced by pwm_ng_init(), and pwm_ng_set().

#define PWM_SIGNIFICANT_BITS   12

Definition at line 29 of file pwm_ng.c.

Referenced by pwm_ng_set().


Function Documentation

void pwm_ng_init ( struct pwm_ng pwm,
uint8_t  timer_nbits,
uint8_t  pwm_nbits,
uint8_t  pwm_mode,
volatile void *  ocrn,
uint8_t  com0,
volatile uint8_t *  tccrn,
volatile uint8_t *  pwm_port,
uint8_t  pwm_bit,
volatile uint8_t *  sign_port,
uint8_t  sign_bit 
)

Inititialize a PWM: set its mode, output pin DDR, DDR for sign bit if any. Example for 8 bits (for atmega128): pwm_ng_init(&pwm, 8, 8, PWM_NG_MODE_SIGNED|PWM_NG_MODE_SIGN_INVERTED, &OCR0, COM00, &TCCR0, &PORTB, 4, &PORTE, 3); Example for 16 bits (for atmega32): pwm_ng_init(&pwm, 16, 9, PWM_NG_MODE_NORMAL, &OCR1B, COM1B0, &TCCR1A, &PORTD, 5, NULL, 0); Note that you can use the helper macros PWM_NG_INIT8() or PWM_NG_INIT16() instead.

Parameters:
pwm is the pointer to the pwm structure that will be filled.
nbits is the number of bits for the timer (8 or 16).
pwm_mode is the mode of the PWM. See the PWM_NG_MODE_xxx flags above.
ocrn is a pointer to the OCRn register for this PWM.
com0 is the COMn0 for this PWM.
pwm_port is the pointer to the PORT of the pwm corresponding to the configured PWM. For instance &PORTB. This is specified in the datasheets, and depends on the AVR part.
pwm_bit is the bitnum of the configured pwm output. This is specified in the datasheets, and depends on the AVR part.
sign_port is a poinrter to the PORT for the sign bit if any, else, it can be set to NULL.
sign_bit is the bitnum of the configured sign output.

Definition at line 40 of file pwm_ng.c.

References DDR, pwm_ng::mode, pwm_ng::nbits, pwm_ng::ocr16, pwm_ng::ocr8, PWM_NG_MODE_REVERSE, PWM_NG_MODE_SIGNED, PWM_NG_NBITS_10, PWM_NG_NBITS_8, PWM_NG_NBITS_9, PWM_NG_TYPE_16, PWM_NG_TYPE_8, pwm_ng::sign_bit, pwm_ng::sign_port, pwm_ng::type, and pwm_ng::u.

void pwm_ng_set ( void *  pwm,
int32_t  value 
)

apply a PWM.

Parameters:
pwm is a pointer to the struct pwm.
value is the value of the pwm. The value is between 0 and 4095 for a non-signed pwm or -4096 and 4095 for a signed one.

Definition at line 112 of file pwm_ng.c.

References MAX, MIN, pwm_ng::mode, pwm_ng::nbits, pwm_ng::ocr16, pwm_ng::ocr8, pwm_invert_value, PWM_MAX, PWM_MIN, PWM_NG_MODE_SIGNED, PWM_NG_TYPE_8, PWM_SIGNIFICANT_BITS, pwm_ng::type, and pwm_ng::u.


Generated on Fri Mar 12 06:32:06 2010 for AVR by  doxygen 1.5.6