ExamBank Scot · Higher Engineering Science question bank · All Higher Engineering Science questions
4 marks · Programmable control
Correct the two different faults in the program opposite by writing the corrected code. You may show corrections for either PBASIC or ARDUINO. Correction 1 Correction 2 Complete the graph below to show a PWM signal with a mark to space ratio of 1:3. You must show at least three pulses. voltage (V) time (ms) An electronic engineer has written code to control a microcontroller-operated motor for a running machine. The code is written to meet the following specification: • If the start switch is on and the runner is sensed, the motor switches on. • The motor operates using pulse-width modulation (PWM) with a mark to space ratio of 1:3. • The sequence repeats. The pin connection table is shown below. Input connection Pin Output connection 7 motor runner sensor (high when sensed) 1 start switch 0 Part of the same program is shown below in PBASIC and ARDUINO code. PBASIC ARDUINO main: if pin 0 = 0 then main void loop() { if pin 1 = 1 then main if (digitalRead(pin0)==LOW){ loop();} pwm: high 7 if (digitalRead(pin1)==HIGH){ pause 15 loop();} low 7 } pause 15 goto main void pwm(){ digitalWrite(pin7,HIGH); delay(15); digitalWrite(pin7,LOW); delay(15); return; } Two faults in the code opposite are shown in bold.
Correction 1 PBASIC: if pin 1 = 0 then main ARDUINO: if digitalRead(pin1)==LOW){ loop();} Correction 2 PBASIC: pause 45 ARDUINO: delay(45); 1 mark for Correction 1. Also accept: if pin 1 = 1 then pwm (must be followed by ‘goto main’) OR: if digitalRead(pin1)==HIGH){ pwm();} (must be followed by ‘return’) 1 mark for Correction 2. The same correction may not be given for two different codes. 1 mark for marks with same voltage. 1 mark for all three correct mark:space ratio. Response must include minimum of three marks and two spaces to establish correct duty cycle.
Previous question: Higher Engineering Science 2024 Question 5