2023-04-24 07:43 AM
2023-04-25 06:55 AM
I have formatted your code again and inserted it with the </> button under the text field:
ADC1_DeInit();
ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_2, ADC1_PRESSEL_FCPU_D2, ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL2, DISABLE); // OCD
ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_3, ADC1_PRESSEL_FCPU_D2, ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL3, DISABLE); // TEMP SENSOR
ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_4, ADC1_PRESSEL_FCPU_D2, ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL4, DISABLE); //VBAT
ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_5, ADC1_PRESSEL_FCPU_D2, ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL5, DISABLE); // MAINS VGE
ADC1_Cmd(ENABLE);
ADC1_StartConversion();
while(ADC1_GetFlagStatus(ADC1_FLAG_EOC) == FALSE);
ADC1_GetConversionValue();
ADC1_ClearFlag(ADC1_FLAG_EOC);
Well, you:
For the first measurement of OCD you should only use channel 2, so delete lines 4...6 and in the old line 12 assign the return value of ADC1_GetConversionValue(); to a variable, e.g. result_OCD, which you can then use further.
Then do the same with channels 3...5, of course with a different result variable each (e.g. result_TEMP_SENSOR, etc).
2023-04-24 08:03 AM
Welcome, @SRAM.1, to the community!
You will find an example for the use of the ADC in STSW-STM8069:
Project\STM8S_StdPeriph_Examples\ADC2\ADC2_ContinuousConversion
Hope that helps?
Good luck!
/Peter
2023-04-25 01:44 AM
Thanks for the reply but it doesn't helps as I need to read voltages from 3 channels as the example shows just convesrion with GPIO.As I am working with powersupplies,I need to get the ADC value .I have completed the samein STM8L15x but stucked at stm8s0003f
2023-04-25 05:15 AM
I don't quite understand your problem: the STM8S003 has an ADC with five multiplexed channels. The example mentioned uses the somewhat more powerful ADC2 with channel 9, but in principle it can also be used for ADC1 on one of the available channels AINx. You can therefore expand the measurement accordingly.
With the STM8S003, however, you have to bear in mind that VREF+ is internally permanently connected to VDDA. This means that you can only measure ratiometrically, i.e. relative to the supply voltage VDDA. For an absolute value measurement of a voltage at a GPIO, which must not exceed VDDA, you must therefore always perform a second comparison measurement at an external reference voltage. Then you can calculate the absolute value of the actual, first voltage.
Hope that helps?
Regards
/Peter
2023-04-25 05:50 AM
Show some code, it might help understand your approach and why it is failing.
It should be able to sequence between multiple channels, but will sample at different instances.
2023-04-25 06:37 AM
ADC1_DeInit();
ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_2, ADC1_PRESSEL_FCPU_D2,
ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL2, // OCD
DISABLE);
ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_3, ADC1_PRESSEL_FCPU_D2,
ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL3, // TEMP SENSOR
DISABLE);
ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_4, ADC1_PRESSEL_FCPU_D2,
ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL4, //VBAT
DISABLE);
ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_5, ADC1_PRESSEL_FCPU_D2,
ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL5, // MAINS VGE
DISABLE);
ADC1_Cmd(ENABLE);
ADC1_StartConversion();
while(ADC1_GetFlagStatus(ADC1_FLAG_EOC) == FALSE);
ADC1_GetConversionValue();
ADC1_ClearFlag(ADC1_FLAG_EOC);
I am not sure what I am proceeding as a starter.
how can i get the value of these channels.It would be great if any link to learn more
2023-04-25 06:55 AM
I have formatted your code again and inserted it with the </> button under the text field:
ADC1_DeInit();
ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_2, ADC1_PRESSEL_FCPU_D2, ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL2, DISABLE); // OCD
ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_3, ADC1_PRESSEL_FCPU_D2, ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL3, DISABLE); // TEMP SENSOR
ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_4, ADC1_PRESSEL_FCPU_D2, ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL4, DISABLE); //VBAT
ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_5, ADC1_PRESSEL_FCPU_D2, ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL5, DISABLE); // MAINS VGE
ADC1_Cmd(ENABLE);
ADC1_StartConversion();
while(ADC1_GetFlagStatus(ADC1_FLAG_EOC) == FALSE);
ADC1_GetConversionValue();
ADC1_ClearFlag(ADC1_FLAG_EOC);
Well, you:
For the first measurement of OCD you should only use channel 2, so delete lines 4...6 and in the old line 12 assign the return value of ADC1_GetConversionValue(); to a variable, e.g. result_OCD, which you can then use further.
Then do the same with channels 3...5, of course with a different result variable each (e.g. result_TEMP_SENSOR, etc).
2023-04-25 07:04 AM
its really helping a lot Thank you so much.I will try the same.