void project_init(void) { uart0_init(); // Initialize Peripherals initialize_steppers(); initialize_actuator(); initialize_rotary(); initialize_magnet(); initialize_LCD(); //uart_init_115K(UART0_BASE); }
int main(void) { uint32_t v_sense; float tempinvolts, temperature; int counter = 0; HAL_StatusTypeDef rc; KalmanState kstate = {0.01, 0.3, 0.0, 0.1, 0.0}; /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize the ADC and GPIO and LCD display */ initialize_ADC(); initialize_GPIO(); initialize_LCD(); /* then call start */ if (HAL_ADC_Start(&ADC1_handle) != HAL_OK) Error_Handler(ADC_INIT_FAIL); while (1) { if (SYSTICK_READ_TEMP_FLAG == 1) { if ((rc = HAL_ADC_PollForConversion(&ADC1_handle, 10000)) != HAL_OK) printf("Error: %d\n", rc); v_sense = HAL_ADC_GetValue(&ADC1_handle); /* Read register from the ADC */ tempinvolts = v_sense * (V_REF / 4096); /* Scale the reading into V (resolution is 12bits with VREF+ = 3.3V) */ temperature = (tempinvolts - V_25) / AVG_SLOPE + TEMP_REF + FUDGE_FACTOR; /* Formula for temperature from doc_05 p.230 */ /* Grind through the Kalman filter */ if (Kalmanfilter_asm(&temperature, &filtered_temp, 1, &kstate) != 0) printf("Overflow error\n"); unfiltered_temp = temperature; // printf("%d %f\n", counter, filtered_temp); /* Display only once out of this many times the 7-segment display */ if (counter % SEGMENT_DISPLAY_PERIOD == 0) { displayed_segment_value = filtered_temp; display_LCD_num(filtered_temp); } if (ALARM_TRIGGERED_FLAG == 1) { /* Avoid spurious noise by waiting for a lower threshold before turning off alarm */ if (filtered_temp < LOWER_THRESHOLD_TEMP) { ALARM_TRIGGERED_FLAG = 0; turn_off_LEDs(); } } else { if (filtered_temp > THRESHOLD_TEMP) ALARM_TRIGGERED_FLAG = 1; } if (ALARM_TRIGGERED_FLAG == 1) { if (counter % ALARM_LED_TOGGLE_PERIOD == 0) toggle_LEDs(); } printf("%f, %f\n", unfiltered_temp, filtered_temp); ++counter; SYSTICK_READ_TEMP_FLAG = 0; /* Reset the flag */ } /* Systick_Handler triggers the flag once every 50ms */ if (SYSTICK_DISPLAY_SEGMENT_FLAG == 1) { display_segment_val(); SYSTICK_DISPLAY_SEGMENT_FLAG = 0; } } }