static void prvSetupHardware( void ) { /* Set up SPI for display of speed, distance, temperature and total time*/ setup_UART1(); initialize_CLS(); setup_SPI2(); /* Set up switches for input triggers */ setup_switches(); /* Set up hbridge for the motor running */ set_hbridge(); /* Set up the input capture module to detect SA pulses of the motors */ setup_IC2(); setup_IC3(); /* Set I2C to read temperature from Pmod Tmp2 */ setup_I2C(); /* Configure corresponding interrupts */ configure_interrupts(); /* Configure the hardware for maximum performance. */ vHardwareConfigurePerformance(); /* Setup to use the external interrupt controller. */ vHardwareUseMultiVectoredInterrupts(); portDISABLE_INTERRUPTS(); }
/** \brief main loop to run tests. * * The tests being run are described in the documentation of this file. * * \return never returns, test loop runs ad infinitum. */ int main(void) { uint8_t switch_mask = 0x00; // Input switches. Read hi when pressed uint16_t result = 0; SR_t shift_reg; /* call all of the setup_* functions */ cli(); setup_clocks(); setup_LEDs(); setup_switches(switch_mask); setup_SR(&shift_reg, &SR_PORT, &SR_SPI_MODULE, false); setup_ADC(&ADC_PORT, &ADC_SPI_MODULE, ADC_CONVST_bm, ADC_EOC_bm, ADC_callback); setup_USART_BC(); sei(); set_channel(MPx, 15, &shift_reg); set_channel(MPy, 15, &shift_reg); /* signal debugging */ PORTD.DIRCLR |= PIN4_bm; PORTD.PIN4CTRL = PORT_OPC_PULLDOWN_gc; while (1) { if (ADC_ready(&adc)) { // get a new conversion result result = ADC_sample_once(&adc); } if (PORTD.IN & PIN4_bm) { LED_PORT.OUT = 0xFF; } else { LED_PORT.OUT = (uint8_t)(result >> 4); printf("%u ", result); } } }
/** \brief main loop to run tests. * * The tests being run are described in the documentation of this file. * * \return never returns, test loop runs ad infinitum. */ int main(void) { uint8_t switch_mask = PIN6_bm; int16_t position = 0; int16_t steps = 1000; uint16_t accel = 100; uint16_t decel = 100; uint16_t speed = 800; PS_t pressure_sensor; LA_t LA_needle; LA_t LA_ring; command_t command; uint16_t steps_left = 0; /* call all of the setup_* functions */ cli(); setup_clocks(); setup_LEDs(); setup_switches(switch_mask); setup_pressure_sensor(&pressure_sensor); setup_USART_BC(); setup_linear_actuators(&LA_needle, &LA_ring); sei(); /* shows the help menu */ show_help_message(); /* show the current state of the linear actuator */ show_motor_data(position, accel, decel, speed, steps); while (1) { switch(command = parse_command(&steps, &accel, &decel, &speed)) { case STEP: LA_move(&LA_needle, steps, accel, decel, speed); LA_move(&LA_ring, steps, accel, decel, speed); position += steps; printf("\n\n"); break; case MOVE: LA_move(&LA_needle, steps, accel, decel, speed); LA_move(&LA_ring, steps, accel, decel, speed); position += steps; printf("\n\n"); break; case ACCEL: case DECEL: case SPEED: printf("\n\n"); break; case REPEAT: LA_move(&LA_needle, steps, accel, decel, speed); LA_move(&LA_ring, steps, accel, decel, speed); position += steps; printf("\n\n"); break; case HELP: show_help_message(); break; case NONE: break; default: show_help_message(); break; } if ((command != HELP) && (command != NONE)) { while (LA_get_motor_state(&LA_needle) != SM_STOP) { if (READ_SWITCHES & PIN6_bm) { LA_brake(&LA_needle); LA_brake(&LA_ring); printf("motors parked\n"); } if (steps > 0) { steps_left = (int32_t)steps * SPR / LA_needle.pitch - LA_needle.motor.speed_ramp.step_count; } else { steps_left = -1 * (int32_t)steps * SPR / LA_needle.pitch - LA_needle.motor.speed_ramp.step_count; } printf(" Running... Steps Left: %d\n", steps_left); delay_ms(250); } printf(" Done with command\n"); show_motor_data(position, accel, decel, speed, steps); } }//end while (1) }