task6 finished

This commit is contained in:
Ondrej Hladuvka 2025-05-21 21:13:58 +03:00
parent 7fb97bcab7
commit 4889a5fdfe
3 changed files with 40 additions and 40 deletions

View File

@ -59,10 +59,8 @@ void TimerA3CaptureInit(void (*task0)(uint16_t time),
TIMER_A3->EX0 &= ~0x7; // input clock divider /1
NVIC->IP[3] = (NVIC->IP[3] & 0xFF0000FF) | 0x00020300; // priority 2 and 3
//? enabling something different??
NVIC->ISER[0] = (1 << 13) | (1 << 14); // enable 14 and 15
NVIC->ISER[0] = (1 << 14) | (1 << 15); // enable 14 and 15
// Start Timer A3 in continuous mode with clear
TIMER_A3->CTL |= 0x0024; // TACLR | MC__CONTINUOUS
@ -78,29 +76,4 @@ void TA3_0_IRQHandler(void) {
void TA3_N_IRQHandler(void) {
TIMER_A3->CCTL[1] &= ~0x0001; // ack
capture_task1(TIMER_A3->CCR[1]);
}
// #define PRESCALER_FACTOR 3
// static uint16_t prev_capture0 = 0;
// static uint16_t prev_capture1 = 0;
// // ISR for TA3 CCR0 (P10.4 rising edge)
// void TA3_0_IRQHandler(void) {
// uint16_t current_capture = TIMER_A3->CCR[0];
// uint16_t period = current_capture - prev_capture0;
// prev_capture0 = current_capture;
// TIMER_A3->CCTL[0] &= ~0x0001; // Acknowledge interrupt
// capture_task0(period * PRESCALER_FACTOR); // Apply prescaler
// }
// // ISR for TA3 CCR1 (P10.5 rising edge)
// void TA3_N_IRQHandler(void) {
// if (TIMER_A3->CCTL[1] & 0x0001) { // Check CCIFG1
// uint16_t current_capture = TIMER_A3->CCR[1];
// uint16_t period = current_capture - prev_capture1;
// prev_capture1 = current_capture;
// TIMER_A3->CCTL[1] &= ~0x0001; // Acknowledge interrupt
// capture_task1(period * PRESCALER_FACTOR); // Apply prescaler
// }
// }
}

View File

@ -20,7 +20,17 @@ TachDirection_t tach_r_dir, tach_l_dir;
void TachometerRightInt(uint16_t current_time) {
tach_r_time1 = tach_r_time2;
tach_r_time2 = current_time;
// write this code
tach_r_dir = (P5->IN & 0x01) ? Forward : Reverse;
// int delta = tach_r_time2 - tach_r_time1;
// int speed = 2000000 / delta;
if (tach_r_dir == Forward)
++tach_r_steps;
else
--tach_r_steps;
return;
}
// Left Encoder B connected to P5.2 (J2.12)
@ -29,7 +39,17 @@ void TachometerRightInt(uint16_t current_time) {
void TachometerLeftInt(uint16_t current_time) {
tach_l_time1 = tach_l_time2;
tach_l_time2 = current_time;
// write this code
tach_l_dir = (P5->IN & 0x04) ? Forward : Reverse;
// int delta = tach_l_time2 - tach_l_time1;
// int speed = 2000000 / delta;
if (tach_l_dir == Forward)
++tach_l_steps;
else
--tach_l_steps;
return;
}
// Initialize P5.0 and P5.2 and make them GPIO inputs,
@ -37,5 +57,11 @@ void TachometerLeftInt(uint16_t current_time) {
// Initialize the input capture interface, which
// will be used to measure the speed of rotation.
void TachometerInit(void) {
// write this code
P5->SEL0 |= 0x05; // Set SEL0 for bits 0 and 2
P5->SEL1 &= ~0x05; // Clear SEL1 for bits 0 and 2
P5->DIR &= ~0x05; // Set as inputs
tach_r_dir = tach_l_dir = Stopped;
TimerA3CaptureInit(&TachometerRightInt, &TachometerLeftInt);
}

View File

@ -61,12 +61,12 @@ void dummy() {
return;
}
int main(void) {
int main_f(void) {
CPU_cpsid(); // Disable interrupts
ClockInit48MHz(); // 48 MHz clock; 12 MHz Timer A clock
RedLEDInit();
ColorLEDInit();
PWMInitMotor(7502);
PWMInitMotor(3751);
MotorInit();
// TimerA1Init(&dummy, 1000);
TimerA3CaptureInit(&PeriodMeasure0, &PeriodMeasure1);
@ -120,12 +120,12 @@ void Collect(void) {
++time;
}
int main_collect(void) {
int main_s(void) {
CPU_cpsid(); // Disable interrupts
ClockInit48MHz(); // 48 MHz clock; 12 MHz Timer A clock
RedLEDInit();
ColorLEDInit();
PWMInitMotor(7502);
PWMInitMotor(3751);
MotorInit();
TimerA3CaptureInit(&PeriodMeasure0, &PeriodMeasure1);
TimerA1Init(&Collect, 5000); // 100 Hz
@ -134,15 +134,16 @@ int main_collect(void) {
return 0;
}
int main_tach(void) {
int main(void) {
CPU_cpsid(); // Disable interrupts
ClockInit48MHz();
PWMInitMotor(7502);
PWMInitMotor(3751);
MotorInit();
TachometerInit();
MotorForward(2000, 2000); // confirm if rotating forward
// MotorForward(2000, 2000); // confirm if rotating forward
//MotorBackward(2000, 2000); // confirm if rotating backward
CPU_cpsie(); // Enable interrupts
CPU_wfi(); // Wait for interrupt
// CPU_wfi(); // Wait for interrupt
while (1);
return 0;
}