start firmware: Function definitions for ADC
This commit is contained in:
@@ -5,10 +5,11 @@
|
||||
* Author: mari
|
||||
*/
|
||||
#include <stm32f4xx.h>
|
||||
#include <systick.h>
|
||||
//#include <arm_math.h>
|
||||
#include <system_stm32f4xx.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define OUTPUT(pin) (0b01 << (pin * 2))
|
||||
#define ANALOG(pin) (0x03 << (pin * 2))
|
||||
@@ -34,9 +35,14 @@ void DMA2_Stream0_IRQHandler()
|
||||
DMA2->LIFCR = lisr;
|
||||
|
||||
if (lisr & DMA_LISR_TCIF0) {
|
||||
if (new_data)
|
||||
new_data = 2;
|
||||
new_data = 1;
|
||||
sample_count++;
|
||||
|
||||
GPIOB->ODR ^= (1<<3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void setup_dma(void *dest, size_t size)
|
||||
@@ -63,11 +69,16 @@ float vdd_calculated = 3.3f;
|
||||
|
||||
float vbat_lf_corr;
|
||||
|
||||
|
||||
|
||||
static void setup_timers(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
struct adc_conversions working;
|
||||
|
||||
|
||||
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
|
||||
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
|
||||
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;
|
||||
@@ -75,7 +86,6 @@ int main() {
|
||||
GPIOB->MODER = OUTPUT(2) | OUTPUT(3);
|
||||
GPIOA->MODER |= ANALOG(2);
|
||||
GPIOB->ODR |= (1<<2);
|
||||
SysTick_Config(8*1680000);
|
||||
|
||||
ADC1->SMPR2 = (7U<<(3*2));
|
||||
ADC1->SMPR1 = (7U<<18) | (7U<<21) | (7U<<24);
|
||||
@@ -88,21 +98,24 @@ int main() {
|
||||
|
||||
//while(1);
|
||||
|
||||
systick_setup();
|
||||
|
||||
setup_dma(&adc_results, 3);
|
||||
|
||||
ADC1->CR2 |= ADC_CR2_SWSTART;
|
||||
|
||||
while(1) {
|
||||
if (!new_data)
|
||||
if (!new_data) {
|
||||
continue;
|
||||
}
|
||||
|
||||
new_data = 0;
|
||||
|
||||
memcpy(&working, &adc_results, sizeof(adc_results));
|
||||
new_data = 0;
|
||||
//ref_lf = 0.995f * ref_lf + 0.005f * (float)working.ref_raw;
|
||||
//vdd_calculated = ((1.21f * 4096)/ ref_lf);
|
||||
|
||||
ref_lf = 0.995f * ref_lf + 0.005f * (float)working.ref_raw;
|
||||
vdd_calculated = ((1.21f * 4096)/ ref_lf);
|
||||
|
||||
temp_lf_corr = 0.99f * temp_lf_corr + 0.01 * (float)working.temp_raw * vdd_calculated / 2.495f;
|
||||
//temp_lf_corr = 0.99f * temp_lf_corr + 0.01 * (float)working.temp_raw * vdd_calculated / 2.495f;
|
||||
ext_lf_corr = 0.995f * ext_lf_corr + 0.005f * (float)working.pa2_raw / 4096 * 2500.0f; // * vdd_calculated / 2.495f;
|
||||
|
||||
//vbat_lf_corr = 0.99 * vbat_lf_corr + 0.01 * (float)working.vbat_raw / 4096 * vdd_calculated * 2.0f;
|
||||
@@ -110,7 +123,4 @@ int main() {
|
||||
|
||||
}
|
||||
|
||||
void SysTick_Handler()
|
||||
{
|
||||
GPIOB->ODR ^= (1<<2) | (1<<3);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user