source: trunk/firmware/HSI16/Src/hsi16 _calibration.c

Last change on this file was 6, checked in by f.jahn, 3 months ago
File size: 3.3 KB
Line 
1/******************************************************************************
2*
3* @file    hsi16_calibration.c
4* @author  ECS, Joseph Zimmer
5* @version V1.0.0
6* @date    06-05-2019
7* @brief       
8*
9******************************************************************************/
10
11//      --- INCLUDES -----------------------------------------------------------------
12#include "hsi16_calibration.h"
13#include "hsi16.h"
14#include "main.h"
15#include <stdio.h>
16//      --- EXTERNE VARIABLEN --------------------------------------------------------
17extern int32_t  aFrequenceChangeTable[128];
18
19//      --- LOKALE DEFINES - bitte hier dokumentieren --------------------------------
20#define GET_HSI16_TRIMMING_VALUE()              ((RCC->ICSCR & RCC_ICSCR_HSITRIM) >> 8)
21#define ABS_RETURN(x)                           ((x < 0) ? (-x) : (x))
22//      --- LOKALE TYPE DEFS - bitte hier dokumentieren-------------------------------
23
24//      --- DEFINITIONEN GLOBALER VARIABLEN - Bitte in Header dokumentieren ----------
25
26//      --- LOKALE VARIABLEN - bitte hier dokumentieren ------------------------------
27static uint8_t trimmingValueOrder[128];
28static uint8_t selectTrimingValue;
29//      --- LOKALE FUNKTIONS PROTOTYPEN ----------------------------------------------
30
31//      --- LOKALE FUNKTIONEN - bitte hier dokumentieren -----------------------------
32
33/*
34* @brief
35* @param        kein
36* @retval       kein
37*/
38
39//      --- GLOBALE FUNKTIONEN - bitte in Header dokumentieren------------------------
40void orderTrimmingValues(void)
41{
42  uint32_t x, y, z, a = 0;
43  int32_t actualValue;
44   
45  for(x = 0; x < 128; x ++)
46  {   
47    actualValue = aFrequenceChangeTable[x];
48    z = 0;
49    for(y = 0; y < 128; y ++)
50    {
51      if(actualValue > aFrequenceChangeTable[y])
52      {
53        z ++;
54      }
55    }
56    trimmingValueOrder[z] = x;
57    if(trimmingValueOrder[z] == 0)
58    {
59      if(a == 1)
60      {
61        printf("ERROR TRIMMING VALUES\n");
62        while(1);
63      }
64      a = 1;
65    }
66  }
67  // auf standartwert setzen
68  selectTrimingValue = 64;
69  for(x = 0; x < 128; x ++)
70  {
71    #ifdef PRINT_FREQUENCY_MEASURE_RESULT
72    printf("%3d;  %d\n", x, trimmingValueOrder[x]);
73    #endif
74    if(selectTrimingValue == trimmingValueOrder[x])
75    {
76      selectTrimingValue = x;
77    }
78  }
79}
80
81void HSI16_CALIBRATION_Process(void)
82{
83  uint32_t output = 0;
84  uint32_t frequency = 0;
85  uint32_t x;
86
87  // Frequenz messen
88  output = HSI16_FreqMeasure();
89  if(output != 2)
90  {
91    frequency = output;
92  }
93  else
94  {
95    return;
96  }
97 
98  // Grö0er oder kleiner 16MegHz
99  if(frequency > 16050000) 
100  {
101    #ifdef PRINT_FREQUENCY_MEASURE_RESULT
102    printf("HSI16 value too high\n");
103    #endif
104    selectTrimingValue --;
105    // Frequenz anpassen
106    __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(trimmingValueOrder[selectTrimingValue]); 
107  }
108  else if(frequency < 15950000) 
109  {
110    #ifdef PRINT_FREQUENCY_MEASURE_RESULT
111    printf("HSI16 value too low\n");
112    #endif
113    selectTrimingValue ++;
114    // Frequenz anpassen
115    __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(trimmingValueOrder[selectTrimingValue]); 
116  }
117 
118  #ifdef CHECK_CHANGED_FREQUENCY
119  // neue Frequenz messen für debugzwecke
120  output = 2;
121  while(output == 2)
122  {
123    output = HSI16_FreqMeasure();
124  }
125  printf("neue Frequenz = %d\n", output); 
126  #endif
127}
128/*************************** End of file ****************************/
Note: See TracBrowser for help on using the repository browser.