#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 PWM_NG_NBITS_10 2 |
#define PWM_NG_NBITS_8 0 |
#define PWM_NG_NBITS_9 1 |
#define PWM_NG_TYPE_16 1 |
#define PWM_NG_TYPE_8 0 |
#define PWM_SIGNIFICANT_BITS 12 |
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.