AnsweredAssumed Answered

Displaying the values read by ADC (ADC, DAC, sinewave, PLL...)

Question asked by Antoine.PM on Jul 5, 2016
Latest reply on Jul 8, 2016 by Antoine.PM
Hi.

My DAC is able to output a sine, and I would like to configure my ADC. Someone told me it was ridiculous to send a sine to the ADC, because the ADC performs a sine, so I would have the sine of a sine. Is it true ?

There is an example about looping the DAC on the ADC, but it uses the output of the ADC as an input for the DAC, and DAC output as ADC input. I would like to control what happens in there, what are the values the ADC read. My printf already works. How can I have a readable display? I mean, the DAC gets values like 4095, 1023... Is it possible for me to have something this clear from the ADC?


In fact, I'm absolutely not sure if I'm doing this right, and if it possible I would like to have some advice. 
Here is the thing: I want to do more or less half of a PLL: I receive two signals on two ADCs , they're potentially filtered if needed, and they're compared by a phase detector which outputs the delta of the two phases. This value is later used as an input in a VCO, which sends the signal to the DAC, which outputs a sinewave. 

So, is it in fact possible to write a phase detector in C?
Do i have to use the integrated PLL? If so, how does it work? From my observation, it is used as a clock , so is it possible to use one of its function, like the PID or/and the phase detector?

Also, in order to read the output of the ADC, I studied an old code that uses 4 LEDs to display the output in binary. I don't have 4 LEDs on my stm32 F334R8. I want to adapt it for printf, if it's still relevant regarding my previous question, but just considering the ADC_Config part I have many errors.

ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Interleave; // 2 ADC Interleaved
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; // 72 MHz / 2 = 36 MHz ADCCLK
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_2; // ADC 1 then 2
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_18Cycles; // 2 MSps (36/18 = 2)
ADC_CommonInit(&ADC_CommonInitStructure);
 
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = DISABLE; // 1 Channel
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; // Hard timed with ADCCLK
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; // Ignored
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; // Ignored
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;
 
ADC_Init(ADC1, &ADC_InitStructure);
 
/* ADC1 regular channel 12 configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1, ADC_SampleTime_15Cycles); // PC2 (3 or 15 cycles, less than 18-2)
 
ADC_Init(ADC2, &ADC_InitStructure);
 
/* ADC2 regular channel 12 configuration */
ADC_RegularChannelConfig(ADC2, ADC_Channel_12, 1, ADC_SampleTime_15Cycles); // PC2

For example, ADC_Prescaler doesn't exist. I think I can replace it with ADC_Clock.
But for the TwoSamplingDelay part, the example gives me "ADC_TwoSamplingDelay_18Cycles;", while the definition of the structure says it accepts values between 0x0 and 0xF. What is the link between these two?


Thank you.

Outcomes