bexus_adc.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "bexus_adc.h"
  2. // memory adress of calibration values for STM32F429
  3. const uint16_t* ADC_TEMP_3V3_30C = (uint16_t*)(0x1FFF7A2C); //bei uns 0°C
  4. const uint16_t* ADC_TEMP_3V3_110C = (uint16_t*)(0x1FFF7A2E); //bei uns 30°C
  5. const double CALIBRATION_REF_VOLTAGE_ADC = 3.3;
  6. const double REF_VOLTAGE_ADC = 3.; // supplied with Vref+ or VDDA
  7. // scale constants to current reference voltage
  8. double adcCalTemp30C = 0;
  9. double adcCalTemp110C = 0;
  10. uint32_t adc3_buff[4],adc1_buff[1];
  11. struct Dataset *data_adc;
  12. void Adc_Init() {
  13. HAL_ADC_Start_DMA(&hadc3, adc3_buff,3);
  14. //HAL_ADC_Start_DMA(&hadc1,&data_adc->adc_temperature_internal_raw,1);
  15. HAL_ADC_Start_DMA(&hadc1,adc1_buff,1);
  16. HAL_ADC_Start_IT(&hadc3);
  17. HAL_ADC_Start_IT(&hadc1);
  18. adcCalTemp30C = (double)(*ADC_TEMP_3V3_30C) * (REF_VOLTAGE_ADC/CALIBRATION_REF_VOLTAGE_ADC);
  19. adcCalTemp110C = (double)(*ADC_TEMP_3V3_110C) * (REF_VOLTAGE_ADC/CALIBRATION_REF_VOLTAGE_ADC);
  20. }
  21. int Adc_Read() {
  22. //HAL_ADC_Start_IT(&hadc1);
  23. //HAL_ADC_Start_IT(&hadc3);
  24. data_adc = &Dataset_Master[buff_sensor_data_index];
  25. //data_adc->adc_temperature_internal_raw = adc1_buff[0] - (adc1_buff[0] & 0xFFFF0000);
  26. data_adc->adc_temperature_internal_raw = adc1_buff[0];
  27. data_adc->adc_voltage_raw = (adc3_buff[0]>>16);
  28. data_adc->adc_current_raw = adc3_buff[0] - (adc3_buff[0] & 0xFFFF0000);
  29. data_adc->adc_temperature_raw = adc3_buff[1];
  30. //Temperature
  31. //PT1000
  32. //data_adc->adc_temperature=(double)((-3.9083) + sqrt(15.27480889+0.00231*(1000-((data_adc->adc_temperature_raw*0.125)/4096)*3./0.0002)))/(-0.001155);
  33. data_adc->adc_temperature=(double)((-3.9083) + sqrt(15.27480889+0.00231*(1000-data_adc->adc_temperature_raw*0.6105)))/(-0.001155);
  34. //internal
  35. //data_adc->adc_temperature_internal = ((data_adc->adc_temperature_internal_raw*1.) - adcCalTemp30C)/(adcCalTemp110C - adcCalTemp30C) * (110. - 30.) + 30.;
  36. data_adc->adc_temperature_internal = ((data_adc->adc_temperature_internal_raw*1.) - adcCalTemp30C)/(adcCalTemp110C - adcCalTemp30C) * 30. ;
  37. //Spannung
  38. data_adc->adc_voltage=(REF_VOLTAGE_ADC/4096*data_adc->adc_voltage_raw)*20;
  39. //Strom - Shunt?!
  40. data_adc->adc_current=(REF_VOLTAGE_ADC/4095*data_adc->adc_current_raw)/100/0.015;
  41. //data_adc->adc_current=(REF_VOLTAGE_ADC/4096*data_adc->adc_current_raw);
  42. return HAL_OK;
  43. }