2013-05-10 12:00 AM
i have connected a potentiometer(via stm32f103 3.3 v) to stm32f103 adc channel 1 (ADC1_IN1), with continuous mode, sampling 1.5. i am getting the values in DR register, and want to change the values during run time by changing resistor values through potentiometer but somehow values are not swinging that much as wanted. i am getting all flags in SR register. am i doing something wrong in implementing this... plz help me
#stm32 #board #stm32l #discovery #adc #adc #discovery #board2013-05-10 04:07 AM
Make sure the ADC clock is less than 14 MHz, use a sample time significantly greater than 1.5, try 28.5, the range (right aligned) should be 0 .. 4095, for a single turn pot attached to the rails, measuring the center.
2013-05-10 04:48 AM
2013-05-10 09:13 AM
have look at my code...
I have a policy of not supporting register level code. You might want to make sure you enable the GPIOA clock, and suitably configure the pin.2013-05-10 09:24 AM
#include ''stm32F10x.h''
/******************************************************************************/
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
/* Enable ADC1 and GPIOA clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOA, ENABLE);
/* Configure PA.01 (ADC Channel1) as analog input -------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* ADC1 configuration ------------------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE; // Single Channel
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; // Scan on Demand
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channel1 configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_55Cycles5);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC1 reset calibaration register */
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibaration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
while(1)
{
if (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == SET)
{
int adc;
adc = ADC_GetConversionValue(ADC1);
printf(''ADC %d
'',adc);
/* Probably overkill */
ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
} // sourcer32@gmail.com
while(1); /* does not exit - kind of important */
}
2013-05-15 12:12 AM
2013-05-15 12:18 AM
2013-05-15 01:36 AM
''is it not good to code in register level?''
If you're going to program at the register level, then you must have a solid understanding of the registers and their functions and how to sonfigure them.
If you want people to review your code for free, don't expect them to have to wade through the arcane details of register-level minutiae!2013-05-15 02:16 AM
2013-05-15 04:42 AM
is it not good to code in register level?
It has it's place, but requires a much more thorough understanding of how the silicon behaves than the average beginner is likely to possess. If you want to waste hours on minutia and nuances, then have at it, but you own all that work.the code you had written is more like the same i posted except you have used calibration. Does the calibration affecting my reading? The F1 requires calibration, as I recall, your very quick conversion will also cause the result to vary quite a lot. A thorough review of the reference manual would be enlightening.