ExamBank Scot · AH Engineering Science question bank · All AH Engineering Science questions
4 marks · Programming control
A student has developed a prototype to model a DC motor on a golf trolley. They have written a sub-procedure to control the motor speed. The motor driver is controlled via output pin 3 of a microcontroller. ARDUINO PBASIC void sub_procedure_A() { sub_procedure_A: for(int x = 250; x >= 1; x = x−5) for x = 250 to 1 step −5 { duty = x; duty = x * 4 analogWrite(3, duty); pwmout B.3, 255, duty for(int y = 1; y <= x; y++) for y = 1 to x { pause 1 delay(1); } next y } } next x return The graphs shown on the page opposite are sketches of voltage change as a function of time. State which of these graphs would most closely represent the voltage change that the sub-procedure would produce at pin 3 of the microcontroller. Justify your answer, referring to the outer and the inner counted loops. voltage graph 1 time graph 2 time voltage voltage graph 3 time voltage graph 4 time voltage graph 5 time voltage graph 6 time
Graph 4 The outer loop creates a decreasing value for the duty of the PWM signal that is produced at the output pin, so the output voltage decreases. The inner loop creates the time interval that a voltage at the output pin is produced for. This time decreases each time the voltage reduces. The rate at which the voltage decreases therefore increases. OR Graph 4 The outer loop controls output voltage at pin 3. The inner loop creates a time delay, so the voltage output is constant for a short interval. Both the voltage and the time delay decrease for each step of the outer loop, so the voltage decreases at an increasing rate. 1 mark - select correct graph. 1 mark - identify that the outer loop is decrementing the variable, starting at a high value, and reducing to a low value and that the variable controls the output voltage. 1 mark - identify that the inner loop is creating a time interval for which the ‘analogue’ voltage appears at the output pin and that this time interval is reduced for each iteration of the outer loop. 1 mark - the effect is that the voltage at the pin decreases at an increasing rate.