eecs 461 prelab 4 declarations for pwmc pwmc university of michigan eecs 461
embedded control systems pulse width modulation using flextimer module read
Written for
EECS 461
All documents for this subject (3)
Seller
Follow
ExamsConnoisseur
Reviews received
Content preview
EECS 461
Prelab 4
Due 02/04/2020
Declarations for pwm.c
/*
pwm.c
University of Michigan
EECS 461, Embedded Control Systems
Pulse-Width Modulation using FlexTimer Module
Read Chapter 45 in S32K144 User's Manual
Important sections:
45.4.2: Register Descriptions
45.5.7: Edge-Aligned PWM (EPWM) Mode
*/
#include "eecs461.h"
#include "pwm.h"
void setPWM(int submodule, int channel, int frequency, float dutyCycle)
{
uint16_t cthres;
uint16_t cmax;
float T = 1/frequency;
float Tc = 1/PWM_CLOCK_FREQ;
cmax = T/Tc - 1; /* fill in */
, cthres = dutyCycle*(cmax+1); /* fill in */
FTM_MODULE[submodule]->MOD = cmax;/* fill in */ /* Set the PWM
frequency */
FTM_MODULE[submodule]->CONTROLS[channel].CnV = cthres /* fill in */ /*
Set the PWM duty cycle */
}
2. Answer attached after code
3. initPWM
void initPWM(int submodule, int channel, int frequency, float dutyCycle)
{
uint16_t cmax;
float T = 1/frequency;
float Tc = 1/PWM_CLOCK_FREQ;
/* 45.4.3.2 - Status and Control (SC) */
FTM_MODULE[submodule]->SC = 0x00000000; /* Clear the status and control
register */
FTM_MODULE[submodule]->SC |= FTM_SC_CLKS(0b11); /* Select external
clock */
/* Enable the respective channel */
FTM_MODULE[submodule]->SC |= FTM_SC_PWMEN0(0b1);
/* Channel Control see S45.4.3.5 and Table 45-5 (S45.5.4) */
FTM_MODULE[submodule]->CONTROLS[channel].CnSC = 0; /* Clear the
register*/
FTM_MODULE[submodule]-> CONTROLS[channel].CnSC|= FTM_CnSC_MSB(1) ; /*
MSB : Edge Align PWM */
FTM_MODULE[submodule]-> CONTROLS[channel].CnSC|= FTM_CnSC_MSA(1) ; /*
MSA : Edge Align PWM */
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller ExamsConnoisseur. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $7.99. You're not tied to anything after your purchase.