Recall the Keyboard example from lecture, where a data and control register were
ID: 641487 • Letter: R
Question
Recall the Keyboard example from lecture, where a data and control register were memory mapped so that you could retrieve user key presses and keyboard status by reading the value of these registers from the address to which they were mapped.
Now let us consider a feedback directed stepper motor. In this case, your program can provide a number of steps num_steps for the motor controller. Your program also gets a feedback as to how many actual steps num_steps_moved the motor moved. Note that in the keyboard example, your program was the consumer of the data (keyboard values) and the keyboard was he producer of the data. The KBCR READY bit synchronized the producer to consumer data flow. Now you need your program to serve as producer of data for num_steps which is consumed by the stepper motor. Simultaneously, your program serves as consumer for num_steps_moved. Think about correct scenarios to manage these various producer-consumer relationships. For instance, your program should not write a new value of num_steps until it is sure that motor has acknowledged acting on the num_steps previous value. In the following, you will design and use the memory map interface for this stepper motor. Note that this is a design question, and hence there is no single correct answer.
a) Define the behavior and what meaning you want to give the bits of the following memory mapped registers called: stepper_data, stepper_feedback_data, and stepper_control, each register is 8-bits in size. Also specify what memory address you want each mapped. Part b will use part a, so read part b first before answering this part.
Note: this is a design question, so it is your job to think about how you want to define and use registers: stepper_data, stepper_feedback_data, and stepper_control.
i) Behavior and definition of bits for stepper_data: [4pts]
ii) Behavior and definition of bits for stepper_feedback_data: [4pts]
iii) Behavior and definition of bits for stepper_control: [4pts]
iv) Memory Address to use for accessing stepper_data: [1pts]
v) Memory Address to use for accessing stepper_feedback_data: [1pts]
vi) Memory Address to use for accessing stepper_control: [1pts]
b) Complete the code below using your definitions from part a.
int num_steps = STEPS_QUANTA; //number of targeted steps
int num_steps_moved = 0; //number of steps moved
// YOUR CODE HERE
while( your polling condition to write num_steps);
YOUR CODE HERE = num_steps;
while( your polling condition to read num_steps_moved);
num_steps_moved = YOUR CODE HERE;
if(num_steps_moved != num_steps)
{
num_steps = num_steps num_steps_moved;
}
Explanation / Answer
i) Behavior and definition of bits for stepper data:
The stepper_data register is written using the user program to convey the no. of steps for the motor to move. It is an 8 bit register. -ve value can imply anti clockwise steps and +ve values can specify clockwise steps.
ii) Behavior and definition of bits for stepper_feedback_data:
The stepper_feedback_data register is written using stepper motor control in order to indicate the no. of steps the motor shaft moved physically in the last round of command. It is an 8 bit register with similar encoding (i.e -ve values for anti clock wise movement and +ve values for clockwise movement).
iii) Behavior and definition of bits for stepper_control:
Only the 2 least significant bits are used for it. SDC at the Bit 0 (i.e stepper_data consumed) indicates that new data can be written into the stepper_data register using the user program. Feedback data ready (FDR) at the Bit 1 indicates that the stepper motor has placed the feedback data in the stepper_feedback register for the user program to read.
iv) Memory Address to use for accessing stepper_data:
0xff00
v) Memory Address to use for accessing stepper_feedback_data:
0xff01
vi) Memory Address to use for accessing stepper_control:
0xff02
vii)
int num_steps = STEPS_QUANTA; //number of targeted steps
int num_steps_moved = 0; //number of steps moved
signed char *stepperData= 0xff00;
signed char *stepperFeedbackData = 0xff01;
unsigned char *stepperControl = 0xff02;
while(!(*stepperControl & 0x01));
*stepperData= num_steps;
while(!(*stepperFeedbackData & 0x02);
num_steps_moved = *stepperFeedbackData ;
if(num_steps_moved != num_steps)
num_steps = num_steps – num_steps_moved;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.