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.
Jonas Holmberg ecdeeffb6e Merge remote-tracking branch 'refs/remotes/origin/master' into Scheduler
# Conflicts:
#	UAV-ControlSystem/.cproject
#	UAV-ControlSystem/src/main.c
2016-09-21 10:25:43 +02:00

105 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 "drivers/system_clock.h"
#include "stm32f4xx.h"
#include "stm32f4xx_revo.h"
#include "system_variables.h"
#include "utilities.h"
#include <string.h>
/* Private function prototypes -----------------------------------------------*/
static void SystemClock_Config(void);
static void Error_Handler(void);
ADC_HandleTypeDef adc_testinput_handle; // For example battery voltage
ADC_HandleTypeDef adc_test2input_handle;
uint32_t g_ADCValue;
uint32_t g_ADC2;
int g_MeasurementNumber;
int main(void)
{
// Initialize the Hardware Abstraction Layer
HAL_Init();
/*##-2- Configure PA05 IO in output push-pull mode to drive external LED ###*/
//GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_6;
//GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
//GPIO_InitStruct.Pull = GPIO_PULLUP;
//GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(GPIOA, &gpinit);
// Configure the system clock to 100 MHz
system_clock_config();
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(;;);
}