cancel
Showing results for 
Search instead for 
Did you mean: 

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

MArsl.3
Associate

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));

}

2 REPLIES 2
KnarfB
Principal III

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
Associate

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