Question: /***************************************************************************** * Code Warrior Project: PWM File Name: pwm control streamlined pax.c * * ECET 340 Lab 7: Measure PWM of uC output WITH scope

/***************************************************************************** * Code Warrior Project: PWM File Name: pwm control streamlined pax.c * * ECET 340 Lab 7: Measure PWM of uC output WITH scope * * Description: * Outputs PWM signal used to control electrical actuators. * * Lab Deliverables: capture (2) different PWM frequencies and (2) different * duty cycles on scope: show measurement for 1. freq * 2. duty cycle or pulse width 3. Vpk-pk * SHOW HORIZONTAL TIME/DIV AND VERTICAL VOLTS/DIV * INCLUDE PIC OF SCOPE WIRING TO TOWER PWM OUTPUT * WIHT POWER ON. INCLUDE CALCULATIONS OF PWM REGISTERS * FOR FREQ AND DUTY CYCLE IN LAB REPORT. * * Reference MC9S12GRMV1.pdf data sheet for CPU * Chapter 19 for PWM registers * * * Practical Uses: * PWM can be used as a speed signal to AC/DC motors, control position of * valves(flow control), dim lighting, etc. * * PWM Channel 0 (Port P bit 0) configured for 5 kHz for motor speed signal. * PWM clock is configured to divide by 6 to get 1 MHz & PWM * frequency is set to 5 kHz, so period count = 1 MHz / 5 kHz = 200. * * Port Usage: * * PWM Port Connections * tower Function Connect To * --------- ------------ --------------------- * PP0(J3-16) PWM out connect scope CH1 here * GND(J3-20) GND scope GND * * Programmer: pax * Tested feb2017 TWR-S12G128, TWR-DEV-PERIPH * & CodeWarrior 5.9.0 MC9S12G128 Open Source BDM ****************************************************************************/

#include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */

// Support functions in this file void initializePWMreg(void);

// Global Constant // PWM period count = 200 for 20 kHz const unsigned char PERIOD = 200;

void main(void) {

asm sei; // Disable interrupts for intl'ztn.

initializePWMreg( );

// Set PWM duty cycle with this register PWMDTY0 = 100;

asm cli; // ENABLE interrupts now }

void initializePWMreg(void) { // Ch 0 clock source = SA (pg 629) PWMCLK_PCLK0 = 1; PWMCLKAB_PCLKAB0 = 0; PWMPRCLK &= 0xF8; // CLKA = fE / 1 = 6.25MHz (PCKA[2:0] = 000) PWMSCLA = 3; // CLKSA = CLKA / (2 x PWMSCLA) = 6.25Mhz / 6 = 1 MHz, change this to change PWM freq PWMPOL_PPOL0 = 1; // Initial HIGH output (LOW after duty cycle count) PWMPER0 = PERIOD; // Count = 1MHz/5kHz = 200 (defined constant) PWMDTY0 = 0; // Start with PWM at zero PWME_PWME0 = 1; // Turn on PWM ch. 0 }

#pragma CODE_SEG DEFAULT

Please help if possible.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!