Mercurial > public > ostc4
comparison Small_CPU/Src/pressure.c @ 276:8e9c502c0b06 IPC_Sync_Improvment_3
Rework pressure/ temperature data aquisition
The data data provided by the I2C data had been used for calculation independend if transmission was successfull or not => state evaluation added
In the previous version data with resolution 0.5mBar and temperature was requested per cycle inparallel. This has been replaced by a requested resolution of 1mBar and an alternating aquisition (pressure / temp update every 200ms instead every 100ms) => reducing busy wait time and power consumption
author | ideenmodellierer |
---|---|
date | Sun, 28 Apr 2019 10:06:27 +0200 |
parents | 2b9775f71e30 |
children | b4c578caaafb |
comparison
equal
deleted
inserted
replaced
275:189387bf23a8 | 276:8e9c502c0b06 |
---|---|
304 statusReturn = pressure_sensor_get_data(); | 304 statusReturn = pressure_sensor_get_data(); |
305 pressure_calculation(); | 305 pressure_calculation(); |
306 return (uint8_t)statusReturn; | 306 return (uint8_t)statusReturn; |
307 } | 307 } |
308 | 308 |
309 /* Switch between pressure and temperature measurement with every successful read operation */ | |
310 void pressure_update_alternating(void) | |
311 { | |
312 static uint8_t getTemperature= 0; | |
313 | |
314 if(getTemperature) | |
315 { | |
316 if(pressure_sensor_get_temperature_raw() == HAL_OK) | |
317 { | |
318 getTemperature = 0; | |
319 } | |
320 } | |
321 else | |
322 { | |
323 if(pressure_sensor_get_pressure_raw() == HAL_OK) | |
324 { | |
325 getTemperature = 1; | |
326 } | |
327 } | |
328 pressure_calculation(); | |
329 return; | |
330 } | |
309 | 331 |
310 static uint32_t pressure_sensor_get_one_value(uint8_t cmd, HAL_StatusTypeDef *statusReturn) | 332 static uint32_t pressure_sensor_get_one_value(uint8_t cmd, HAL_StatusTypeDef *statusReturn) |
311 { | 333 { |
312 uint8_t command = CMD_ADC_CONV + cmd; | 334 uint8_t command = CMD_ADC_CONV + cmd; |
313 HAL_StatusTypeDef statusReturnTemp = HAL_TIMEOUT; | 335 HAL_StatusTypeDef statusReturnTemp = HAL_TIMEOUT; |
331 } | 353 } |
332 | 354 |
333 | 355 |
334 static HAL_StatusTypeDef pressure_sensor_get_data(void) | 356 static HAL_StatusTypeDef pressure_sensor_get_data(void) |
335 { | 357 { |
358 uint32_t requestedValue = 0; | |
336 HAL_StatusTypeDef statusReturn1 = HAL_TIMEOUT; | 359 HAL_StatusTypeDef statusReturn1 = HAL_TIMEOUT; |
337 HAL_StatusTypeDef statusReturn2 = HAL_TIMEOUT; | 360 HAL_StatusTypeDef statusReturn2 = HAL_TIMEOUT; |
338 | 361 |
339 D2 = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_4096, &statusReturn1); | 362 |
340 D1 = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_4096, &statusReturn2); | 363 |
341 | 364 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_1024, &statusReturn2); |
365 if (statusReturn2 == HAL_OK) | |
366 { | |
367 D2 = requestedValue; | |
368 } | |
369 | |
370 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_1024, &statusReturn1); | |
371 if (statusReturn1 == HAL_OK) | |
372 { | |
373 D1 = requestedValue; | |
374 } | |
342 if(statusReturn2 > statusReturn1) // if anything is not HAL_OK (0x00) or worse | 375 if(statusReturn2 > statusReturn1) // if anything is not HAL_OK (0x00) or worse |
343 return statusReturn2; | 376 return statusReturn2; |
344 else | 377 else |
345 return statusReturn1; | 378 return statusReturn1; |
346 } | 379 } |
347 | 380 |
348 | 381 |
349 void pressure_sensor_get_pressure_raw(void) | 382 HAL_StatusTypeDef pressure_sensor_get_pressure_raw(void) |
350 { | 383 { |
351 D1 = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_4096, 0); | 384 uint32_t requestedValue = 0; |
352 } | 385 HAL_StatusTypeDef statusReturn = HAL_TIMEOUT; |
353 | 386 |
354 | 387 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_1024, &statusReturn); |
355 void pressure_sensor_get_temperature_raw(void) | 388 if (statusReturn == HAL_OK) |
356 { | 389 { |
357 D2 = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_4096, 0); | 390 D1 = requestedValue; |
391 } | |
392 | |
393 return statusReturn; | |
394 } | |
395 | |
396 | |
397 HAL_StatusTypeDef pressure_sensor_get_temperature_raw(void) | |
398 { | |
399 uint32_t requestedValue = 0; | |
400 HAL_StatusTypeDef statusReturn = HAL_TIMEOUT; | |
401 | |
402 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_1024, &statusReturn); | |
403 if (statusReturn == HAL_OK) | |
404 { | |
405 D2 = requestedValue; | |
406 } | |
407 return statusReturn; | |
358 } | 408 } |
359 | 409 |
360 | 410 |
361 void pressure_calculation(void) | 411 void pressure_calculation(void) |
362 { | 412 { |