Skip to main content
MArsl.3
Associate
March 28, 2022
Question

hello how can i convert the values ​​i get from multiple ADC to multiple PWM signals again

  • March 28, 2022
  • 2 replies
  • 681 views

Hello, I'm new to embedded system programming. I'm trying to turn 2 LEDs on and off with 2 potentiometers. But every time I turn a potentiometer, the LEDs flash at the same time. Can you help me with this?

void ADC_oku()

{

 HAL_ADC_Start(&hadc1);

   HAL_ADC_PollForConversion(&hadc1, 10);

   adc0 = HAL_ADC_GetValue(&hadc1);

 TIM2->CCR1 = (adc0<<4);

 Adres0[0] =adc0 >> 4;

 USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS,Adres0,sizeof(Adres0));

}

void ADC_oku2()

{

 HAL_ADC_PollForConversion(&hadc1, 20);

 adc1 = HAL_ADC_GetValue(&hadc1);

 TIM2->CCR2 = (adc1<<4);

 Adres1[0] =adc1 >> 4;

 USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS,Adres1,sizeof(Adres1));

}

This topic has been closed for replies.

2 replies

KnarfB
Super User
March 28, 2022

The ADC code may or may not work, depending on the ADC setup and the sequence in which the functions are called. Are you getting plausible ADC values via USB, an attached debugger, or STM32CubeMonitor?

You're using "PWM", "on/off", and "flash". What do you mean exactly? PWM is on/off so quick that the LED looks dimmed. How is the timer setup, what is its period? Describe the "flash" in more detail or show logic analyzer plots.

BTW: For LED dimming, a non-linear transfer function is common.

hth

KnarfB

MArsl.3
MArsl.3Author
Associate
March 29, 2022

Namely, before, I could easily read from 1 channel adc and drive the LED with PWM signal. But when I want to drive more than one LED with multi-channel, there is a problem. I want to read ADC on PA4 and PA5 pins and output from PA0 and PA1 pins. My Prescalar value is 0 and my counter period value is 65535. I have never played with these values.You can see the data coming to the HID terminal below.

0693W00000Lw4glQAB.png