Complete the program below to have a robot move away from a light source. The ro
ID: 2081337 • Letter: C
Question
Complete the program below to have a robot move away from a light source. The robot has two wheels, similar to the robot used in lab, and has a light sensor on each side. See figure below Motor Control Assume that you are programming Timer 1 module A (for left motor) and Timer1 module B (for right motor) to generate PWM waveforms to control the speed of each wheel's motor (note, connect Timer 1 to Port B). The speed of the motor is proportional to the percentage of time the PWM signal is high (i.e. PWM duty cycle). Note: Your PWM wave must have a period of 1.4ms Note the system clock is 16 MHz Light Sensors: The light sensors are connected to Channel 4 (left sensor) and 7 (right sensor) of the ADC as single channel inputs (i.e. not different Robot behavior: The Robot should move away from the light in the following way. Where "Speed of motor" is the fraction of the motor's maximum speed. Speed of left motor Intensity of left sensor (Intensity of left sensor Intensity of right sensor) Speed of right motor Intensity of right sensor (Intensity of left sensor Intensity of right sensor) Turn away from light Front Robot BackExplanation / Answer
void get_sensor_reading(int *left_sensor, int *right_sensor)
{
//initiate SS0 conversion
ADC0_PSSI_R = ADC_PSSI_SS0;
//wait for ADC conversion to complete
while( (ADC0_RIS_R & ADC_RIS_INR0) == 0){
//wait ADC_RIS_INR0 for SS0
}
//get result
*left_sensor = ADC0_SSFIFO0_R;
//initiate SS1 conversion
ADC0_PSSI_R = ADC_PSSI_SS1;
//wait for ADC conversion to complete
while( (ADC0_RIS_R & ADC_RIS_INR1) == 0){
//wait ADC_RIS_INR1 for SS1
}
//get result
*right_sensor = ADC0_SSFIFO0_R;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.