Subversion Repositories EDIS_Ignition

Rev

Rev 19 | Rev 21 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19 Rev 20
Line 65... Line 65...
65
 
65
 
66
/* USER CODE BEGIN PV */
66
/* USER CODE BEGIN PV */
67
int const T100MS = 100;
67
int const T100MS = 100;
68
 
68
 
69
int const DISPLAY_REINITIALISE = 60 * 1000;
69
int const DISPLAY_REINITIALISE = 60 * 1000;
70
// compensated pressure in mb * 100
70
/// @brief compensated pressure in mb * 100
71
uint32_t comp_pres = 0;
71
uint32_t compensatedManifoldPressure = 0;
-
 
72
/// @brief compensated atmospheric pressure
-
 
73
uint32_t compensatedAtmosphericPressure = 0;
72
// compensated temperature
74
/// @brief compensated temperature
73
int32_t comp_temp = -10000;
75
int32_t compensatedTemperature = -10000;
74
 
76
 
75
int32_t timing = 0;
77
int32_t timing = 0;
76
 
78
 
77
// 6 degrees error in timing wheel this time ..
79
// 6 degrees error in timing wheel this time ..
78
int const TIMING_OFFSET = -6 * TIMING_SCALE;
80
int const TIMING_OFFSET = -6 * TIMING_SCALE;
Line 83... Line 85...
83
uint32_t const DEFAULT_ATMOSPHERIC_PRESSURE = 1014 * 100;
85
uint32_t const DEFAULT_ATMOSPHERIC_PRESSURE = 1014 * 100;
84
 
86
 
85
uint32_t const DEFAULT_ATMOSPHERIC_TEMPERATURE = 25 * 100;
87
uint32_t const DEFAULT_ATMOSPHERIC_TEMPERATURE = 25 * 100;
86
 
88
 
87
// Serial buffers
89
// Serial buffers
88
#define TX_BUFFER_SIZE 128  
90
#define TX_BUFFER_SIZE 128
89
#define RX_BUFFER_SIZE 128
91
#define RX_BUFFER_SIZE 128
90
unsigned volatile char tx_buffer[TX_BUFFER_SIZE];
92
unsigned volatile char tx_buffer[TX_BUFFER_SIZE];
91
unsigned volatile char rx_buffer[RX_BUFFER_SIZE];
93
unsigned volatile char rx_buffer[RX_BUFFER_SIZE];
92
 
94
 
93
/* USER CODE END PV */
95
/* USER CODE END PV */
Line 103... Line 105...
103
static void MX_USART2_UART_Init(void);
105
static void MX_USART2_UART_Init(void);
104
static void MX_TIM3_Init(void);
106
static void MX_TIM3_Init(void);
105
static void MX_IWDG_Init(void);
107
static void MX_IWDG_Init(void);
106
/* USER CODE BEGIN PFP */
108
/* USER CODE BEGIN PFP */
107
 
109
 
108
void libPLXcallbackRecievedData(PLX_SensorInfo * info)
110
void libPLXcallbackRecievedData(PLX_SensorInfo *info)
-
 
111
{
109
{ (void)info; }
112
  (void)info;
-
 
113
}
110
 
114
 
111
void libPLXcallbackSendUserData()
115
void libPLXcallbackSendUserData()
112
{
116
{
113
  // send MAP
117
  // send MAP
114
  PLX_SensorInfo info;
118
  PLX_SensorInfo info;
115
  ConvToPLXInstance(libPLXgetNextInstance(PLX_MAP), &info);
119
  ConvToPLXInstance(libPLXgetNextInstance(PLX_MAP), &info);
116
  ConvToPLXAddr(PLX_MAP, &info);
120
  ConvToPLXAddr(PLX_MAP, &info);
117
  ConvToPLXReading(ConveriMFDData2Raw(PLX_MAP, PRESSURE_kPa, (float)(comp_pres) / 100.0), &info);
121
  ConvToPLXReading(ConveriMFDData2Raw(PLX_MAP, PRESSURE_kPa, (float)(compensatedManifoldPressure) / 100.0), &info);
118
  sendInfo(&uc2, &info);
122
  sendInfo(&uc2, &info);
119
 
123
 
120
  ConvToPLXInstance(libPLXgetNextInstance(PLX_Timing), &info);
124
  ConvToPLXInstance(libPLXgetNextInstance(PLX_Timing), &info);
121
  ConvToPLXAddr(PLX_Timing, &info);
125
  ConvToPLXAddr(PLX_Timing, &info);
122
  ConvToPLXReading(ConveriMFDData2Raw(PLX_Timing, 0, (float)(timing) / TIMING_SCALE), &info);
126
  ConvToPLXReading(ConveriMFDData2Raw(PLX_Timing, 0, (float)(timing) / TIMING_SCALE), &info);
Line 200... Line 204...
200
  // Start the input capture and the falling edge interrupt
204
  // Start the input capture and the falling edge interrupt
201
  HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_2);
205
  HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_2);
202
 
206
 
203
  __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 5); // delay of 5 uS
207
  __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 5); // delay of 5 uS
204
 
208
 
205
 // HAL_I2C_ClearBusyFlagErrata_2_14_7(&hi2c1);
209
  // HAL_I2C_ClearBusyFlagErrata_2_14_7(&hi2c1);
206
  MX_I2C1_Init();
210
  MX_I2C1_Init();
207
  init_bmp(&hi2c1);
211
  init_bmp(&hi2c1, &bmp);
-
 
212
  init_bmp(&hi2c1, &bmpAtm);
-
 
213
 
208
  uint32_t lastTick = HAL_GetTick();
214
  uint32_t lastTick = HAL_GetTick();
209
 
215
 
210
  uint32_t displayOff = lastTick + 10000;
216
  uint32_t displayOff = lastTick + 10000;
211
  uint32_t displayReinitialise = lastTick + DISPLAY_REINITIALISE; // every minute, reinitialise display because of risk of noise
217
  uint32_t displayReinitialise = lastTick + DISPLAY_REINITIALISE; // every minute, reinitialise display because of risk of noise
212
 
218
 
Line 262... Line 268...
262
    if (HAL_GetTick() - lastTick > T100MS)
268
    if (HAL_GetTick() - lastTick > T100MS)
263
    {
269
    {
264
      lastTick = HAL_GetTick();
270
      lastTick = HAL_GetTick();
265
      /* Reading the raw data from sensor */
271
      /* Reading the raw data from sensor */
266
      struct bmp280_uncomp_data ucomp_data;
272
      struct bmp280_uncomp_data ucomp_data;
-
 
273
 
267
      uint8_t rslt = bmp280_get_uncomp_data(&ucomp_data, &bmp);
274
      uint8_t rslt = bmp280_get_uncomp_data(&ucomp_data, &bmp);
268
 
275
 
269
      uint8_t rslt2 = 1;
276
      uint8_t manifoldStatus = 1;
270
      uint8_t rslt3 = 1;
277
      uint8_t temperatureStatus = 1;
-
 
278
      uint8_t atmosphericStatus = 1;
271
 
279
 
272
      if (rslt == 0)
280
      if (rslt == BMP280_OK)
273
      {
281
      {
274
        rslt2 = bmp280_get_comp_pres_32bit(&comp_pres, ucomp_data.uncomp_press, &bmp);
282
        manifoldStatus = bmp280_get_comp_pres_32bit(&compensatedManifoldPressure, ucomp_data.uncomp_press, &bmp);
275
 
283
 
276
        rslt3 = bmp280_get_comp_temp_32bit(&comp_temp, ucomp_data.uncomp_temp, &bmp);
284
        temperatureStatus = bmp280_get_comp_temp_32bit(&compensatedTemperature, ucomp_data.uncomp_temp, &bmp);
277
 
285
 
278
#if defined TEST_CODE
286
#if defined TEST_CODE
279
        comp_pres = 100000;
287
        compensatedManifoldPressure = 100000;
280
        comp_temp = 4000;
288
        compensatedTemperature = 4000;
281
#endif
289
#endif
282
      }
290
      }
-
 
291
      // get atmospheric data
-
 
292
      if (rslt == BMP280_OK)
-
 
293
      {
-
 
294
        rslt = bmp280_get_uncomp_data(&ucomp_data, &bmpAtm);
-
 
295
        // now to read the environmental pressure
-
 
296
        if (rslt == BMP280_OK)
-
 
297
          atmosphericStatus = bmp280_get_comp_pres_32bit(&compensatedAtmosphericPressure, ucomp_data.uncomp_press, &bmpAtm);
-
 
298
      }
-
 
299
      if (manifoldStatus != BMP280_OK)
-
 
300
        compensatedManifoldPressure = DEFAULT_ATMOSPHERIC_PRESSURE;
-
 
301
      if (temperatureStatus != BMP280_OK)
-
 
302
        compensatedTemperature = DEFAULT_ATMOSPHERIC_TEMPERATURE;
-
 
303
      if (atmosphericStatus != BMP280_OK)
-
 
304
        compensatedAtmosphericPressure = DEFAULT_ATMOSPHERIC_PRESSURE;
-
 
305
 
-
 
306
      uint32_t vacuum = compensatedAtmosphericPressure - compensatedManifoldPressure;
283
      // if the BMP280 pressure is good, then allow it through, otherwise drop to
307
      // if the BMP280 pressure is good, then allow it through, otherwise drop to
284
      // centrifugal advance only.
308
      // centrifugal advance only.
285
      if (rslt == BMP280_OK && rslt2 == BMP280_OK && rslt3 == BMP280_OK)
-
 
286
        cc_feed_env(comp_pres, comp_temp);
309
      // feed difference and add default pressure
287
      else
-
 
288
        cc_feed_env(DEFAULT_ATMOSPHERIC_PRESSURE, DEFAULT_ATMOSPHERIC_TEMPERATURE);
310
      cc_feed_env(vacuum + DEFAULT_ATMOSPHERIC_PRESSURE, compensatedTemperature);
289
 
311
 
290
        // compute RPM value, feed to display
312
      // compute RPM value, feed to display
291
#if defined TEST_CODE
313
#if defined TEST_CODE
292
      int rpm = 1000;
314
      int rpm = 1000;
293
#else
315
#else
294
      int rpm = CalculateRPM();
316
      int rpm = CalculateRPM();
295
#endif
317
#endif
296
      if (rpm > 0)
318
      if (rpm > 0)
297
      {
319
      {
298
        cc_feed_rpm(rpm);
320
        cc_feed_rpm(rpm);
299
        // compute timing value, feed to display
321
        // compute timing value, feed to display
300
        timing = mapTiming(rpm, 1000 - comp_pres / 100);
322
        timing = mapTiming(rpm, 1000 - vacuum / 100);
301
        cc_feed_timing(timing);
323
        cc_feed_timing(timing);
302
        // enable double spark below 1200 rpm
324
        // enable double spark below 1200 rpm
303
        int microsecs = mapTimingToMicroseconds(timing + TIMING_OFFSET, rpm > DOUBLE_SPARK_RPM);
325
        int microsecs = mapTimingToMicroseconds(timing + TIMING_OFFSET, rpm > DOUBLE_SPARK_RPM);
304
        __HAL_TIM_SET_AUTORELOAD(&htim1, microsecs + SAW_DELAY);
326
        __HAL_TIM_SET_AUTORELOAD(&htim1, microsecs + SAW_DELAY);
305
      }
327
      }