As we replied in your another post, you may just add your own code to check the input of key without changing anything on the motor control algorithm in the original lab11e. Set the reference speed (gMotorVars.SpeedRef_krpm) to a positive or negative value for forwarding or reversing rotation according to the input signal of the key. It seems like you don't consider the noise on the input signal of the key, and the control logic is not correct also. I would recommend some MCU programming books to look though I don't have a specific one in mind.
↧