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

Implementation for the PWM module. More...

#include <aversive.h>
#include "pwm.h"
#include <aversive/parts.h>
#include <aversive/timers.h>
#include <pwm_config.h>
#include "timers_synch.h"

Go to the source code of this file.

Defines

#define pwm0_init_ddr()
#define pwm0_sign_set()
#define pwm0_sign_reset()
#define pwm1A_init_ddr()
#define pwm1A_sign_set()
#define pwm1A_sign_reset()
#define pwm1B_init_ddr()
#define pwm1B_sign_set()
#define pwm1B_sign_reset()
#define pwm1C_init_ddr()
#define pwm1C_sign_set()
#define pwm1C_sign_reset()
#define pwm2_init_ddr()
#define pwm2_sign_set()
#define pwm2_sign_reset()
#define pwm3A_init_ddr()
#define pwm3A_sign_set()
#define pwm3A_sign_reset()
#define pwm3B_init_ddr()
#define pwm3B_sign_set()
#define pwm3B_sign_reset()
#define pwm3C_init_ddr()
#define pwm3C_sign_set()
#define pwm3C_sign_reset()
#define pwm_invert_value(mode, value)
#define pwm_timer_8bits_init(n, mode, prescale, timer_mode)
#define pwm_timer_16bits_init(n, m, mode, prescale, timer_mode)
#define pwm_timer_8bits_set(n, value, mode)
#define pwm_timer_16bits_set(n, m, value, mode)

Functions

void pwm_init (void)
void pwm_set (void *data, int32_t value)


Detailed Description

Implementation for the PWM module.

Todo:
Test the module.
Test:
The modul fonctions and had been tested by Lamygalle.
This module provides functions for using a pwm

Definition in file pwm.c.


Define Documentation

 
#define pwm0_init_ddr (  ) 

Definition at line 94 of file pwm.c.

 
#define pwm0_sign_reset (  ) 

Definition at line 96 of file pwm.c.

 
#define pwm0_sign_set (  ) 

Definition at line 95 of file pwm.c.

 
#define pwm1A_init_ddr (  ) 

Definition at line 111 of file pwm.c.

 
#define pwm1A_sign_reset (  ) 

Definition at line 113 of file pwm.c.

 
#define pwm1A_sign_set (  ) 

Definition at line 112 of file pwm.c.

 
#define pwm1B_init_ddr (  ) 

Definition at line 128 of file pwm.c.

 
#define pwm1B_sign_reset (  ) 

Definition at line 130 of file pwm.c.

 
#define pwm1B_sign_set (  ) 

Definition at line 129 of file pwm.c.

 
#define pwm1C_init_ddr (  ) 

Definition at line 145 of file pwm.c.

 
#define pwm1C_sign_reset (  ) 

Definition at line 147 of file pwm.c.

 
#define pwm1C_sign_set (  ) 

Definition at line 146 of file pwm.c.

 
#define pwm2_init_ddr (  ) 

Definition at line 162 of file pwm.c.

 
#define pwm2_sign_reset (  ) 

Definition at line 164 of file pwm.c.

 
#define pwm2_sign_set (  ) 

Definition at line 163 of file pwm.c.

 
#define pwm3A_init_ddr (  ) 

Definition at line 179 of file pwm.c.

 
#define pwm3A_sign_reset (  ) 

Definition at line 181 of file pwm.c.

 
#define pwm3A_sign_set (  ) 

Definition at line 180 of file pwm.c.

 
#define pwm3B_init_ddr (  ) 

Definition at line 196 of file pwm.c.

 
#define pwm3B_sign_reset (  ) 

Definition at line 198 of file pwm.c.

 
#define pwm3B_sign_set (  ) 

Definition at line 197 of file pwm.c.

 
#define pwm3C_init_ddr (  ) 

Definition at line 213 of file pwm.c.

 
#define pwm3C_sign_reset (  ) 

Definition at line 215 of file pwm.c.

 
#define pwm3C_sign_set (  ) 

Definition at line 214 of file pwm.c.

#define pwm_invert_value ( mode,
value   ) 

Value:

do {                                                                       \
        if ( mode & PWM_SPECIAL_SIGN_MODE ) {                              \
                value = value & PWM_MAX;                                   \
        }                                                                  \
        else {                                                             \
                value = -value;                                            \
        }                                                                  \
} while(0)

Definition at line 219 of file pwm.c.

Referenced by pwm_ng_set().

#define pwm_timer_16bits_init ( n,
m,
mode,
prescale,
timer_mode   ) 

Value:

do {                                                                           \
        TCCR##n##A =   (TCCR##n##A |                                           \
                        ( ( timer_mode & 0x01 )?( 1 << WGM##n##0 ):0   )  |    \
                        ( ( timer_mode & 0x02 )?( 1 << WGM##n##1 ):0   )  )  ; \
                                                                               \
        TCCR##n##B =  ( ( ( timer_mode & 0x04 )?( 1 << WGM##n##2 ):0   )  |    \
                        ( ( timer_mode & 0x08 )?( 1 << WGM##n##3 ):0   )  |    \
                        ( ( prescale  << CS##n##0  )  )  );                    \
        if(mode & PWM_REVERSE) {                                               \
                TCCR##n##A = ( ( (TCCR##n##A) &                                \
                                 (~(0x03 << COM##n##m##0)) ) |                 \
                               (0x01  << COM##n##m##0) );                      \
        }                                                                      \
        else {                                                                 \
                TCCR##n##A = ( ( (TCCR##n##A) &                                \
                                 (~(0x03 << COM##n##m##0)) ) |                 \
                               (0x02  << COM##n##m##0) );                      \
        }                                                                      \
        OCR##n##m = 0;                                                         \
        sbi(OCR##n##m##_DDR,OCR##n##m##_BIT);                                  \
        pwm##n##m##_init_ddr();                                                \
} while(0)

Definition at line 251 of file pwm.c.

#define pwm_timer_16bits_set ( n,
m,
value,
mode   ) 

Value:

do {                                                                           \
        MAX(value, PWM_MAX);                                                   \
        if ( mode & PWM_SIGNED ) {                                             \
                MIN(value, PWM_MIN);                                           \
                if (value < 0) {                                               \
                        pwm##n##m##_sign_set();                                \
                        pwm_invert_value(mode, value);                         \
                }                                                              \
                else {                                                         \
                        pwm##n##m##_sign_reset();                              \
                }                                                              \
        }                                                                      \
        else {                                                                 \
                MIN(value, 0);                                                 \
        }                                                                      \
        OCR##n##m = ( value >> ( PWM_SIGNIFICANT_BITS                          \
                                 -  TIMER##n##_PWM_BITS )) ;                   \
} while(0)

Definition at line 300 of file pwm.c.

#define pwm_timer_8bits_init ( n,
mode,
prescale,
timer_mode   ) 

Value:

do {                                                                           \
        TCCR##n  =  ( ( ( timer_mode & 0x01 )?( 1 << WGM##n##0 ):0   )  |      \
              ( ( timer_mode & 0x02 )?( 1 << WGM##n##1 ):0   )  |              \
                      ( ( prescale  << CS##n##0  ) ) );                        \
        if(mode & PWM_REVERSE) {                                               \
                TCCR##n = ( ( (TCCR##n) & (~(0x03 << COM##n##0)) ) |           \
                            (0x01  << COM##n##0) );                            \
        }                                                                      \
        else {                                                                 \
        TCCR##n = ( ( (TCCR##n) & (~(0x03 << COM##n##0)) ) |                   \
                    (0x02  << COM##n##0) );                                    \
        }                                                                      \
        OCR##n = 0x00;                                                         \
        sbi(OCR##n##_DDR,OCR##n##_BIT);                                        \
        pwm##n##_init_ddr();                                                   \
} while(0)

Definition at line 230 of file pwm.c.

#define pwm_timer_8bits_set ( n,
value,
mode   ) 

Value:

do {                                                                           \
        MAX(value, PWM_MAX);                                                   \
        if ( mode & PWM_SIGNED ) {                                             \
                MIN(value, PWM_MIN);                                           \
                if (value < 0) {                                               \
                        pwm##n##_sign_set();                                   \
                        pwm_invert_value(mode, value);                         \
                }                                                              \
                else {                                                         \
                        pwm##n##_sign_reset();                                 \
                }                                                              \
        }                                                                      \
        else {                                                                 \
                MIN(value, 0);                                                 \
        }                                                                      \
        OCR##n =(uint8_t) ( value >> ( PWM_SIGNIFICANT_BITS - 8 ));            \
} while(0)

Definition at line 278 of file pwm.c.


Function Documentation

void pwm_init ( void   ) 

global functions

Definition at line 560 of file pwm.c.

Referenced by brushless_init().

void pwm_set ( void *  data,
int32_t  value 
)

apply a PWM.

Parameters:
data is a pointer that is casted in (uint8_t) to specify the number of the PWM.
value is the value of the pwm.

Definition at line 605 of file pwm.c.

References PWM0_NUM, PWM1A_NUM, PWM1B_NUM, PWM1C_NUM, PWM2_NUM, PWM3A_NUM, PWM3B_NUM, PWM3C_NUM, and S_MAX.


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