Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use BASIC Stamp 2 to develope a program to rotate a DC motor clockwise with a co

ID: 2082435 • Letter: U

Question

Use BASIC Stamp 2 to develope a program to rotate a DC motor clockwise with a constant acceleration for 1 second, to run for 5 second at a constant speed, and to decelerate at a constant rate for 1 second before stopping. Use BASIC Stamp 2 to develope a program to rotate a DC motor clockwise with a constant acceleration for 1 second, to run for 5 second at a constant speed, and to decelerate at a constant rate for 1 second before stopping.

Explanation / Answer

#include /* PIC Configuration Bit: ** INTIO - Using Internal RC No Clock ** WDTDIS - Wacthdog Timer Disable ** PWRTEN - Power Up Timer Enable ** MCLREN - Master Clear Enable ** UNPROTECT - Code Un-Protect ** UNPROTECT - Data EEPROM Read Un-Protect ** BORDIS - Borwn Out Detect Disable ** IESODIS - Internal External Switch Over Mode Disable ** FCMDIS - Monitor Clock Fail Safe Disable */ __CONFIG(INTIO & WDTDIS & PWRTEN & MCLREN & UNPROTECT & UNPROTECT & BORDIS & IESODIS & FCMDIS); // Using Internal Clock of 8 Mhz #define FOSC 8000000L // Servo definition and variables #define MAX_VALUE 200 #define CCW_ROTATION MAX_VALUE - 20 #define CW_ROTATION MAX_VALUE - 10 #define STOP_ROTATION MAX_VALUE #define THRESHOLD_VALUE 50 unsigned char pulse_max=0; unsigned char pulse_top=0; unsigned char top_value = 0; static void interrupt isr(void) { if(T0IF) { // TIMER0 Interrupt Flag pulse_max++; // Pulse Max Increment pulse_top++; // Pulse Top Increment /* MAX_VALUE=200 turn off the pulse */ if (pulse_max >= MAX_VALUE) { pulse_max=0; pulse_top=0; RC2=0; // Turn off RC2 } /* top_value = MAX_VALUE - n, n=10: 50 x 0.1ms = 5.0ms, n=20: 10 x 0.1ms = 1.0ms */ /* 5ms -> CCW Rotation, 1ms -> CW Rotation */ if (pulse_top == top_value) { RC2=1; // Turn On RC2 } TMR0 = 156; // Initial Value for 0.1ms Interrupt T0IF = 0; // Clear TIMER0 interrupt flag } } void main(void) { unsigned char ldr_left; unsigned char ldr_right; int ldr_diff; OSCCON=0x70; // Select 8 Mhz internal clock /* Initial Port Used */ TRISC = 0x03; // Set RC0 and RC1 as input others as Output ANSEL = 0x30; // Set PORT AN4 and AN5 as analog input ANSELH = 0x00; // Set PORT AN8 to AN11 as Digital I/O PORTC = 0x00; // Turn Off all PORTC /* Init Servo Pulse */ pulse_max=0; pulse_top=0; top_value = MAX_VALUE; // top_value = MAX_VALUE: Servo Motor Stop /* Initial ADC */ ADCON1=0b00110000; // Select the FRC for 8 Mhz /* Init TIMER0: Period: Fosc/4 x Prescaler x TMR0 0.0005 ms x 2 * 100 = 0.1 ms */ OPTION = 0b00000000; // 1:2 Prescaller TMR0=156; // Interupt every 0.1 ms T0IE = 1; // Enable interrupt on TMR0 overflow GIE = 1; // Global interrupt enable for(;;) { /* Read the ADC here */ ADCON0=0b00010001; // select left justify result. ADC port channel AN4 GODONE=1; // initiate conversion on the channel 4 while(GODONE) continue; // Wait for ldr_left conversion done ldr_left=ADRESH; // Read 8 bits MSB, Ignore 2 bits LSB in ADRESL ADCON0=0b00010101; // select left justify result. ADC port channel AN5 GODONE=1; // initiate conversion on the channel 5 while(GODONE) continue; // Wait for ldr_right conversion done ldr_right=ADRESH; // Read 8 bits MSB, Ignore 2 bits LSB in ADRESL /* Get the different */ ldr_diff=ldr_left - ldr_right; if ((ldr_diff >= -THRESHOLD_VALUE) && (ldr_diff THRESHOLD_VALUE) { top_value = CCW_ROTATION; // Counterclockwise Rotation } else { top_value = CW_ROTATION; // Clockwise Rotation } } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote