Académique Documents
Professionnel Documents
Culture Documents
c
/*----------------------------- Include Files -----------------------------*/
/* include header files for this service
*/
// Events and Services framework Headers
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "ES_DeferRecall.h"
#include "ES_ShortTimer.h"
#include "ADService.h"
#include "PWMService.h"
#include "BITDEFS.H"
// readability defines
#define ALL_BITS (0xff << 2)
#include "ADMulti.h"
uint8_t duty;
uint8_t Frequency;
#define PERIOD_IN_USPB6 20000
#define PERIOD_IN_USPB7 20000
#define PERIOD_IN_USPB4 250
#define PERIOD_IN_USPB5 250
#define PERIOD_IN_USPC4 250
#define PERIOD_IN_USPD0 20000
#define PWM_TICKS_PER_MS 1250 //changed from 250
#define BITS_PER_NIBBLE 4
#define GenA_NormalPB6 (PWM_0_GENA_ACTCMPAU_ONE | PWM_0_GENA_ACTCMPAD_ZERO)
#define GenB_NormalPB7 (PWM_0_GENB_ACTCMPBU_ONE | PWM_0_GENB_ACTCMPBD_ZERO)
#define GenA_NormalPB4 (PWM_1_GENA_ACTCMPAU_ONE | PWM_1_GENA_ACTCMPAD_ZERO)
#define GenB_NormalPB5 (PWM_1_GENB_ACTCMPBU_ONE | PWM_1_GENB_ACTCMPBD_ZERO)
#define GenA_NormalPC4 (PWM_3_GENA_ACTCMPAU_ONE | PWM_3_GENA_ACTCMPAD_ZERO)
#define GenA_NormalPD0 (PWM_0_GENA_ACTCMPAU_ONE | PWM_0_GENA_ACTCMPAD_ZERO)
#define GenA_NormalPE4 (PWM_1_GENA_ACTCMPAU_ONE | PWM_1_GENA_ACTCMPAD_ZERO)
MyPriority = Priority;
PWMInit();
//will be defined in separate fucntion
ThisEvent.EventType = ES_INIT;
// printf("\n\r adservice initialised ");
if (ES_PostToService(MyPriority, ThisEvent) == true)
{
return true;
}
else
{
return false;
}
}
// set duty takes value from AD service and inserts the value in compare A
if (ThisEvent.EventType == ES_NEW_KEY)
{
SetFrequency(750);
printf("changed frequency is %d", Frequency);
}
return ReturnEvent;
}
void PWMInit(void)
{
//ENABLE CLOCK TO PWM MODULEo and Module1
HWREG(SYSCTL_RCGCPWM) |= SYSCTL_RCGCPWM_R0;
HWREG(SYSCTL_RCGCPWM) |= SYSCTL_RCGCPWM_R1;
// set the up/DoWn count mode and enable the pwm generator. Both gererator updates
synchronised
void RestoreDCPB6(void)
{
HWREG(PWM0_BASE + PWM_O_0_GENA) = GenA_NormalPB6;
}
void RestoreDCPB7(void)
{
HWREG(PWM0_BASE + PWM_O_0_GENB) = GenB_NormalPB7;
}
void RestoreDCPB4(void)
{
HWREG(PWM0_BASE + PWM_O_1_GENA) = GenA_NormalPB4;
}
void RestoreDCPB5(void)
{
HWREG(PWM0_BASE + PWM_O_1_GENB) = GenB_NormalPB5;
}
void RestoreDCPC4(void)
{
HWREG(PWM0_BASE + PWM_O_3_GENA) = GenA_NormalPC4;
}
void RestoreDCPD0(void)
{
HWREG(PWM1_BASE + PWM_O_0_GENA) = GenA_NormalPD0;
}
void RestoreDCPE4(void)
{
HWREG(PWM1_BASE + PWM_O_1_GENA) = GenA_NormalPE4;
}