Skip to content

Commit

Permalink
adc works
Browse files Browse the repository at this point in the history
  • Loading branch information
Jchisholm204 committed Nov 11, 2023
1 parent 502649c commit fb697ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Q24ECU/core/include/hal/hal_adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static inline void adc_start(ADC_TypeDef *adc){
if(!(adc->CR2 & ADC_CR2_ADON)){
adc->CR2 |= ADC_CR2_ADON;
volatile uint32_t counter = 0U;
counter = 3U * (SystemCoreClock/1000000U);
counter = 3U * (SYS_FREQUENCY/1000000U);
// wait for adc to stabilize
while (counter != 0U) counter--;
}
Expand All @@ -82,6 +82,6 @@ static inline void adc_stop(ADC_TypeDef *adc){
static inline uint16_t adc_poll(ADC_TypeDef *adc, uint8_t adcCh){
adc_configChannel(adc, adcCh, 1);
adc_start(adc);
while(!(adc->SR & ADC_SR_EOC)) continue;
while(!(adc->SR & ADC_SR_EOC));
return adc->DR;
}
11 changes: 10 additions & 1 deletion Q24ECU/core/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "task.h"
#include "hal/hal_adc.h"
#include <string.h>

// set up a basic test task
Expand All @@ -33,8 +34,14 @@ TaskHandle_t gDebugPrint = NULL;
// Debug Print "HI!" Task
void debugPrint(void *param){
(void)param;
gpio_set_mode(PIN_voltageSensor, GPIO_MODE_ANALOG);
printf("Task Start: debugPrint\n");
adc_init(ADC2);
for(;;){
uart_write_buf(USART2, "Hi!\n", 5);
int adcread = adc_poll(ADC2, 11);
printf("Voltage: %f\n", ((float)(adcread))*3.3*1.6/(4096));
// uart_write_buf(USART2, "Hi!\n", 5);
//printf("HI!!\n");
vTaskDelay(1000);
}
}
Expand All @@ -59,6 +66,8 @@ int main(void){
NVIC_SetPriority(TIM6_DAC_IRQn, 0x03); // Enable Timer IRQ (lowest priority)
NVIC_EnableIRQ(TIM6_DAC_IRQn);

uart_init(UART_DEBUG, 9600);

// Create Sample Blink Task
uint32_t status_tstTsk = xTaskCreate(
testTask,
Expand Down

0 comments on commit fb697ab

Please sign in to comment.