Kim GiJeong
/
try5_2_dacadc_fast_register
ADC
Diff: main.cpp
- Revision:
- 0:82a281385638
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Aug 12 09:13:55 2019 +0000 @@ -0,0 +1,51 @@ +#include "mbed.h" + +AnalogOut dac(PA_4); +Serial pc(USBTX,USBRX); +DigitalOut check(PC_2); +void Init_ADC(void); + +int main() { + Init_ADC(); + + while(1) { + check=1; + ADC1->CR2 |= 0x40000000; // Begin sample and conversion + float value = ADC1->DR; + value = ADC2->DR; + value = ADC3->DR; + dac=ADC3->DR/4096.0f; + check=0; + value = ADC1->DR; +// pc.printf("%f\n",value); +// wait(0.025f); + } +} + + +void Init_ADC(void){ + // ADC Setup + RCC->APB2ENR |= RCC_APB2ENR_ADC3EN; // clock for ADC3 + RCC->APB2ENR |= RCC_APB2ENR_ADC2EN; // clock for ADC2 + RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; // clock for ADC1 + + RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN; // Enable clock for GPIOC + RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN; // Enable clock for GPIOA + + ADC->CCR = 0x00000016; // Regular simultaneous mode only + ADC1->CR2 |= ADC_CR2_ADON;//0x00000001; // ADC1 ON + ADC1->SQR3 = 0x0000000E; //channel // use PC_4 as input- ADC1_IN14 + ADC2->CR2 |= ADC_CR2_ADON;//0x00000001; // ADC2 ON + ADC2->SQR3 = 0x00000008; // use PB_0 as input - ADC2_IN8 + ADC3->CR2 |= ADC_CR2_ADON; // ADC3 ON + ADC3->SQR3 = 0x0000000B; // use PC_1, - ADC3_IN11 + GPIOC->MODER |= 0b1100001100; //each channel // PC_4, PC_1 are analog inputs + GPIOB->MODER |= 0x3; // PB_0 as analog input + + ADC1->SMPR1 |= 0x1000; //?? // 15 cycles on CH_14, 0b 001000000000000 + ADC2->SMPR1 |= 0x1000000; // 15 cycles on CH_8, 2^24 = 16^6 + ADC3->SMPR2 |= 0b1000; // 15 cycles on CH_11, 0b 001000; + + } + +