Question: Modify the PWM motor control code so that motor RPM changes smoothly between 1 0 0 % and 5 0 % and back. You can
Modify the PWM motor control code so that motor RPM changes smoothly between and and back. You can modify the case statement and add a subroutine to set the PWM through OCR register.
main.cpp
short explanation of how your code works.
#include
#define PWM
#define PWM
#define PWM
#define PWM
uintt uMsCnt, starttime, currenttime;
void setup
Leds: RED Uno #PD GREEN Uno #PD
DDRD PD; GREEN output Uno # DDRD
DDRD PD; TBD RED output Uno # DDRD
PORTD PD; GREEN off
PORTD PD; RED off...
Timer setupPWM output
DDRB PB; PWM output on pinOCA Uno #
TCCRA COMA WGM; toggle OCA on compare match, bit phase corrected PWM
OCRA PWM; start with PWM duty cycle output low
TCCRB CS; prescalerPWM MHz kHz T us starttimer
uMsCnt ; reset ms counter
starttime millis; reset ms counter starttime
void loop
put your main code here, to run repeatedly:
switch uMsCnt
uMsCnt goesfrom to ms to be reset on maxvalue
case :
OCRA PWM; PWM
OCRA PWM; PWM
PORTD PD; GREEN off
PORTD & ~ PD; RED on
break;
case :
OCRA PWM; PWM
PORTD & ~ PD; GREEN on
PORTD PD; RED off
break;
case : after s back to beginningPWM
uMsCnt ; reset ms counter
starttime millis; reset ms counter starttime
break;
default:
break;
endswitch
currenttime millis; get current time in ms
if currenttime starttime
if starttime or more ms passed
uMsCnt currenttime starttime;
update ms count
starttime currenttime; reset starttime
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
