This repository has been archived on 2020-06-14. You can view files and clone it, but cannot push or open issues or pull requests.

133 lines
2.4 KiB
C

/**
******************************************************************************
* @file main.c
* @author Ac6
* @version V1.0
* @date 01-December-2013
* @brief Default main function.
* Awesome ADC fix start project here to be good awesome!!
******************************************************************************
*/
#include "drivers/adc.h"
#include "config/eeprom.h"
#include "drivers/system_clock.h"
#include "stm32f4xx.h"
#include "system_variables.h"
#include "utilities.h"
#include <string.h>
#include "drivers/uart1_inverter.h"
// for test
uint8_t pid_pitch_pk = 10;
int main(void)
{
// Initialize the Hardware Abstraction Layer
HAL_Init();
// Configure the system clock to 100 MHz
system_clock_config();
pid_pitch_pk = 10;
setActiveProfile(1);
resetEEPROM();
for(;;)
{
setActiveProfile(3);
pid_pitch_pk = 0;
uart1_rx_inverter = 0;
pid_pitch_pk++;
setActiveProfile(1);
pid_pitch_pk++;
readEEPROM();
pid_pitch_pk = 200;
setActiveProfile(2);
pid_pitch_pk = 0;
readEEPROM();
pid_pitch_pk = 250;
resetEEPROM();
setActiveProfile(3);
int kalle = pid_pitch_pk;
setActiveProfile(2);
kalle = pid_pitch_pk;
setActiveProfile(3);
kalle = pid_pitch_pk;
}
while(true);
int i = 1;
//Add ADC Channels
adc_pin_add(ADC_CHANNEL_0);
adc_pin_add(ADC_CHANNEL_1);
adc_pin_add(ADC_CHANNEL_12);
//Configure the ADCs
adc_configure();
/* This is done in system_clock_config for all GPIO clocks */
//__GPIOB_CLK_ENABLE();
GPIO_InitTypeDef gpinit;
gpinit.Pin = GPIO_PIN_5;
gpinit.Mode = GPIO_MODE_OUTPUT_PP;
gpinit.Pull = GPIO_PULLUP;
gpinit.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(GPIOB, &gpinit);
adc_start();
int num = 2000;
int j = 0;
volatile uint32_t time_us[num];
while (1)
{
i++;
//g_ADCValue = accumulate(g_ADCBuffer,ADC_BUFFER_LENGTH) / ADC_BUFFER_LENGTH;
//HAL_Delay(100);
int g_ADCValue = adc_read(ADC_CHANNEL_0);
int g_ADCValue1 = adc_read(ADC_CHANNEL_1);
int g_ADCValue12 = adc_read(ADC_CHANNEL_12);
int offTime = g_ADCValue;
int onTime = 4096 - offTime;
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5,GPIO_PIN_SET);
for (int i = 0; i < onTime; i++)
{
asm("nop");
}
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5,GPIO_PIN_RESET);
for (int i = 0; i < offTime; i++)
{
asm("nop");
}
//Get time in microseconds
if(j < num)
time_us[j++] = clock_get_us();
}
for(;;);
}