Prusa MINI Firmware overview
adc.h File Reference
#include <inttypes.h>
#include "config.h"

Go to the source code of this file.

Functions

void adc_init (void)
 
void adc_cycle (void)
 

Variables

uint32_t adc_val [ADC_CHAN_CNT]
 
uint32_t adc_sim_val [ADC_CHAN_CNT]
 
uint32_t adc_sim_msk
 

Function Documentation

◆ adc_init()

void adc_init ( void  )
53  {
54  for (int i = 0; i < ADC_CHAN_CNT; i++) {
55  adc_val[i] = 0;
56  adc_cnt[i] = 0;
57  adc_chn[i] = adc_chan(i);
58  }
59  adc_idx = 0;
60  adc_sta = 0x00;
62 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ adc_cycle()

void adc_cycle ( void  )
65  {
66  uint8_t seq;
67  uint32_t val;
68  if (adc_sta == 0xff)
69  return; //skip sampling if not initialized
70  if (adc_sta & 0x80) {
72  if ((1 << adc_idx) & adc_sim_msk)
73  val = adc_sim_val[adc_idx];
74  else
75  val = HAL_ADC_GetValue(&hadc1);
76  adc_val[adc_idx] += val;
77  if (++adc_cnt[adc_idx] >= ADC_OVRSAMPL) {
79  adc_val[adc_idx] = 0;
80  adc_cnt[adc_idx] = 0;
81  }
82  seq = (adc_sta & 0x1f) + 1;
83  if (seq >= ADC_SEQ_LEN)
84  seq = 0;
85  adc_idx = ADC_SEQ2IDX(seq);
87  adc_sta = seq;
88  } else {
89  Error_Handler();
90  }
91  } else {
93  adc_sta |= 0x80;
94  }
95 }
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ adc_val

uint32_t adc_val[ADC_CHAN_CNT]

◆ adc_sim_val

uint32_t adc_sim_val[ADC_CHAN_CNT]

◆ adc_sim_msk

uint32_t adc_sim_msk
adc_init_sim_vals
void adc_init_sim_vals(void)
Definition: adc.c:97
HAL_ADC_Start
HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef *hadc)
ADC_FLAG_EOC
#define ADC_FLAG_EOC
Definition: stm32f4xx_hal_adc.h:430
adc_sim_val
uint32_t adc_sim_val[ADC_CHAN_CNT]
Definition: adc.c:23
i
uint8_t i
Definition: screen_test_graph.c:72
HAL_ADC_GetValue
uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef *hadc)
adc_cnt
uint8_t adc_cnt[ADC_CHAN_CNT]
Definition: adc.c:18
ADC_SEQ_LEN
#define ADC_SEQ_LEN
Definition: config_a3ides2209_02.h:32
adc_chan
uint8_t adc_chan(uint8_t idx)
Definition: adc.c:29
adc_val
uint32_t adc_val[ADC_CHAN_CNT]
Definition: adc.c:17
hadc1
ADC_HandleTypeDef hadc1
Definition: main.c:75
ADC_SEQ2IDX
uint8_t ADC_SEQ2IDX(uint8_t seq)
uint8_t
const uint8_t[]
Definition: 404_html.c:3
ADC_OVRSAMPL
#define ADC_OVRSAMPL
Definition: config_a3ides2209_02.h:31
Error_Handler
void Error_Handler(void)
This function is executed in case of error occurrence.
Definition: main.c:1057
adc_sta
uint8_t adc_sta
Definition: adc.c:20
adc_idx
int8_t adc_idx
Definition: adc.c:21
ADC_CHAN_CNT
#define ADC_CHAN_CNT
Definition: config_a3ides2209_02.h:30
adc_set_mux
void adc_set_mux(uint8_t chn)
Definition: adc.c:42
adc_chn
uint8_t adc_chn[ADC_CHAN_CNT]
Definition: adc.c:19
adc_sim_msk
uint32_t adc_sim_msk
Definition: adc.c:24
__HAL_ADC_GET_FLAG
#define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__)
Get the selected ADC's flag status.
Definition: stm32f4xx_hal_adc.h:515
ADC_READY
void ADC_READY(uint8_t index)