#include <aversive.h>
#include <aversive/timers.h>
#include <aversive/parts.h>
Go to the source code of this file.
Data Structures | |
struct | pwm_ng |
Defines | |
#define | PWM_NG_MODE_NORMAL 0x00 |
#define | PWM_NG_MODE_REVERSE 0x01 |
#define | PWM_NG_MODE_SIGN_INVERTED 0x02 |
#define | PWM_NG_MODE_SIGNED 0x04 |
#define | PWM_NG_MODE_SPECIAL_SIGN 0x08 |
#define | PWM_NG_TIMER_0_MODE |
#define | PWM_NG_TIMER_8BITS_INIT(n, t_mode, prsc) |
#define | PWM_NG_TIMER_8BITS_INIT_B(n, t_mode, prsc) |
#define | PWM_NG_TIMER_16BITS_INIT(n, t_mode, prsc) |
#define | PWM_NG_INIT8(pwm, n, pwm_nbits, pwm_mode, sign_port, sign_bit) |
#define | PWM_NG_INIT8_B(pwm, n, m, pwm_nbits, pwm_mode, sign_port, sign_bit) |
#define | PWM_NG_INIT16(pwm, n, m, pwm_nbits, pwm_mode, sign_port, sign_bit) |
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 *pwm, int32_t value) |
#define PWM_NG_INIT16 | ( | pwm, | |||
n, | |||||
m, | |||||
pwm_nbits, | |||||
pwm_mode, | |||||
sign_port, | |||||
sign_bit | ) |
Value:
do { \ pwm_ng_init(pwm, 16, pwm_nbits, pwm_mode, &OCR##n##m, \ COM##n##m##0, &TCCR##n##A, \ &OC##n##m##_PORT, OC##n##m##_BIT, \ sign_port, sign_bit); \ } while(0)
#define PWM_NG_INIT8 | ( | pwm, | |||
n, | |||||
pwm_nbits, | |||||
pwm_mode, | |||||
sign_port, | |||||
sign_bit | ) |
Value:
do { \ pwm_ng_init(pwm, 8, pwm_nbits, pwm_mode, &OCR##n, \ COM##n##0, &TCCR##n, &OC##n##_PORT, \ OC##n##_BIT, sign_port, sign_bit); \ } while(0)
#define PWM_NG_INIT8_B | ( | pwm, | |||
n, | |||||
m, | |||||
pwm_nbits, | |||||
pwm_mode, | |||||
sign_port, | |||||
sign_bit | ) |
Value:
do { \ pwm_ng_init(pwm, 8, pwm_nbits, pwm_mode, &OCR##n##m, \ COM##n##m##0, &TCCR##n##A, &OC##n##m##_PORT, \ OC##n##m##_BIT, sign_port, sign_bit); \ } while(0)
#define PWM_NG_MODE_REVERSE 0x01 |
#define PWM_NG_MODE_SIGNED 0x04 |
#define PWM_NG_TIMER_16BITS_INIT | ( | n, | |||
t_mode, | |||||
prsc | ) |
Value:
do { \ TCCR##n##A &= ~((1 << WGM##n##0) | (1 << WGM##n##1)); \ TCCR##n##A |= ((t_mode & 0x01) ? (1 << WGM##n##0):0) | \ ((t_mode & 0x02) ? (1 << WGM##n##1):0); \ TCCR##n##B = ((t_mode & 0x04) ? (1 << WGM##n##2):0) | \ ((t_mode & 0x08 ) ? (1 << WGM##n##3):0) | \ (prsc << CS##n##0); \ } while(0)
n | is the number of the timer. | |
timer_mode | can be TIMER_16_MODE_PWM_PC, TIMER_16_MODE_CTC, TIMER_16_MODE_PWM... | |
prsc | is the value to be loaded in the prescaler register for this timer. For instance, TIMER1_PRESCALER_DIV_256. |
#define PWM_NG_TIMER_8BITS_INIT | ( | n, | |||
t_mode, | |||||
prsc | ) |
Value:
do { \ TCCR##n = ( ((t_mode & 0x01) ? (1 << WGM##n##0):0) | \ ((t_mode & 0x02) ? (1 << WGM##n##1):0) | \ ((prsc << CS##n##0)) ); \ } while(0)
n | is the number of the timer. | |
t_mode | can be TIMER_8_MODE_PWM_PC, TIMER_8_MODE_CTC, TIMER_8_MODE_PWM. | |
prsc | is the value to be loaded in the prescaler register for this timer. For instance, TIMER0_PRESCALER_DIV_256. |
#define PWM_NG_TIMER_8BITS_INIT_B | ( | n, | |||
t_mode, | |||||
prsc | ) |
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.
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.
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.