Você está na página 1de 2

PASSO A PASSO DO MÓDULO PWM

1) Ver o arquivo do Módulo PWM do microcontrolador (slide da aula de SDM:


aula15_PWM_2019_2)
2) Completar o arquivo Micro.h com a parte do PWM (verificar pag. 24/25 do Livro AVR
(44/45 no PDF));
3) Verifcar no arquivo main_prm.h, os módulos utilizados:
#define INITIALIZE_TASKS()\
{\
ADC__Initialize();\
Hal__Initialize();\
Pwm_Initialize();\
Display__Initialize();\
Sounds_Initialize();\
Appl__Initialize();\

#define SLOT_1_TASKS()\
{\
Sounds_Background();\ // chama as rotinas que tocam o buzzer
Hal__BackgroundHandler();\ // leitura do ADC

#define SLOT_2_TASKS()\
{\
Appl__Handler();\
Display__Handler();\
}

#define SLOT_3_TASKS()\
{\
ADC__Handler();\
}

4) No arquivo Pwm.h, tem-se os typedefs:


typedef enum {
PWM0 = 0,
PWM1,
PWM2,
...,
NUM_OF_PWM,
} PWM_ID_TYPE;

typedef enum {
PWM_TC0 = 0,
...
NUM_OF_PWM_TC,
} PWM_TC_TYPE;

5) No Pwm.h também temos todas as funções necessários para a interface com a


camada superior no arquivo PWM.c:
void Pwm__Initialize(void);
void Pwm_SetTCFrequency( PWM_TC_TYPE tc, unsigned short int frequency);
void Pwm_SetDutyCycle( PWM_ID_TYPE pwm, unsigned char duty);
6) Pwm__Initialize(): Configurar as saídas do PWM como saídas digitais;
Desabilitar todos os PWMs;
Configurar todas as saídas PWM para Modo PWM com fase
corrigida, prescaler de 256, TOP de 255 e saída invertida.

7) Pwm_SetTCFrequency (AD_MODE_TYPE mode, AD_CONVERSION_TYPE conv_type):


Esta função configura o TC numa determinada frequência ( verifcar no livro para
cada TC)
8) Pwm_SetDutyCycle (AD_CHANNEL_TYPE channel , unsigned char duty): Configura o
PWM num determinado ciclo de trabalho ( 0 a 100%)

9) A camada superior está no arquivo Hal.h, onde tem a função necessária


para a interface com a camada superior no arquivo Hal.c:
void Hal_SetBuzzer(unsigned char state);
void Hal_SetBuzzerFreq(unsigned short int frequency);

10) Em Hal.c tem–se uma função:


void Hal_SetBuzzer(unsigned char state)
Se o state é maior que 0, então chama o Pwm_SetDutyCycle (PWMx,
Buzzer_default_duty)
Senão, Pwm_SetDutyCycle (PWMx, 0xff).

void Hal_SetBuzzerFreq(unsigned short int frequency)


chama Pwm_SetTCFrequency (PWM_TC1, frequency)

11) No arquivo Sounds.h, tem-se os typedefs:


typedef enum {
SOUND_POWER_ON = 0,
SOUND_KEY_PRESS,
SOUND_END_CYCLE,
NUM_OF_SOUNDS,
PLAY_NO_SOUND = 0XFF // NÃO RETIRE ESTA LINHA
} SOUNDS_TYPE;
12) A camada superior está no arquivo Sounds.h, onde tem a função necessária
para a interface com a camada superior no arquivo Sounds.c:
void Sounds__Initialize(void);
void Sounds_Background(void);
void Sounds_PlaySounds( SOUNDS_TYPE sound_id);

13) Em Sounds.c, tem–se as seguintes funções:


Sounds__Initialize(): inicializa as variável global: PlaySound.

Sounds_Background(): verifica o status da variável Playsound, se acabou, deixar como


PLAY_NO_SOUND.

Sounds_PlaySounds( SOUNDS_TYPE sound_id): Atualiza a variável PlaySound

Você também pode gostar