2023-08-28 09:14 PM
Here, i am working on STM32F401 controller, where i am using PLL with HSI working at 72MHz freq. The timer is generating a PWM output but instead of generating 24 pulses as per my requirement it is only generating 6 pulses. Hence 2 pulses for every 8 inputs. Where can it be wrong, as i am newly working on high frequencies i am not sure.
uint8_t pwmData[24]={61,61,61,61,61,61,61,61, 39,39,39,39,39,39,39,39, 39,39,39,39,39,39,39,39};
2023-08-28 10:09 PM
There might be several problems.
0) In general, for better readability use bit defines instead of "(1 << 0)", these should be in some "*f401*.h" file (and there is a better forum option to show source code, it's in the "..." menu)
1) Your timer settings are strange, you write the timer gets 16 MHz, then set PSC to 0, and ARR to 89 -> that will not give you 100 ms
2) In the while loop, think about what's going on there:
the for loop is called all the time, almost at CPU clock frequency, and each time CCR1 is set with a new value.
So you better use DMA to feed the CCR register, thus only when the current pwmData[i] "time" has elapsed, a new value is given to CCR.
2023-08-28 10:37 PM - edited 2023-08-28 10:40 PM
Well the thing is i am not trying to generate a PWM wave of 100ms. The HSI (16MHz) is used to supply clock to PLL which generates 72MHz. Now i have taken a pre-scaler of 1 which when multiplied by the ARR of 90 gives me an output wave with a time period of 1.25 micro-seconds. Here also i am using NRZ protocol based concept as my LED's work on it, meaning the PWM pulse will never become 0, hence the changing CCR1 value. The for loop is just for testing.
The ultimate idea is to use DMA only but my concern is related to whether it is possible to use this way at high speeds or not at all possible.
Also about the bits shifting, the thing is we have made our own header from scratch for better understanding thus we have not made macros for every position.
Also i will attach my RCC_Init function which enables PLL.
2023-08-29 02:25 AM
This has nothing to do with PLL.
As @LCE said above, in the for() loop, before storing the new value to TIM2_CCR1, you have to wait until the previous period elapsed, i.e. you have to wait for TIM2_SR.UIF going high, clear it, and then write the next CCR1 value.
JW
2023-08-29 04:15 AM - edited 2023-08-29 04:31 AM
I tried that but it is jumbling my output on LED. Actually i am using Addressable RGB LED, for which 1 LED takes 24 bit/pulse (NRZ) PWM data (1 pulse may it be 0 or 1 has a time period of 1.25 micro sec). I have generated a precise time period as required by its datasheet still the overall issue is i am not able to completely control them. Also i am working on Timer DMA parallelly but facing few issues in it. One of the reason for working with PLL also was due to these LED's only as they need high freq. Please do suggest something efficient.
I am able to get primary colors on the LED but the issue starts with different color patterns. Also without PLL, i am getting 24 pulses.