Solutions to Exercise 7: Stepping motors
Exercise 7.2 - 7.3: The different stepping modes
The solutions to this exercise are very similar to the solution to the traffic light exercise. Again a table with values for the 4 stepping motor phases is used and the program itself implements a state machine which runs through the table and sends currents through stepping motor coils as defined in the table. The following code snippet shows the function that sends out the signals to the coils for the single phase forward mode. For the other modes only the table must be changed. For half step modes the size of the table doubles and the function must loop over 8 half steps instead of 4 full steps as shown in this example.
The solutions of all the different modes are collected in this tar file:
https://iotworkshop.africa/pub/Embedded_Systems/Exercise7Solutions/step.tar.gz
Exercise 7.4 User control through command line arguments
This exercise is a combination of all exercises before with the addition of user control through command line parameters.It is a lot more complex! It uses the getopt_long system library function (check this out with
man getopt_long to understand the details) to parse the command line arguments the user enters.
I just give you the solution for study. Of course you are invited to try it on real hardware.
https://iotworkshop.africa/pub/Embedded_Systems/Exercise7Solutions/stepper.tar.gz