EmbDev.net

Forum: µC & Digital Electronics STM32 Changing PWM Duty Cycle in interrupt handler


von André V. (Company: The IT Philosopher) (philosopher)


Attached files:

Rate this post
useful
not useful
I am trying to control WS2812 style LEDS. When I looked at the protocol, 
I noticed a short high, long low signal is a zero and a long high, short 
low signal is a one.

So, I got the idea, such a signal could be generated by a PWM generator, 
updating the duty cycle in the interrupt handler. I am using a 
STM32F103C8T6 microcontroller to implement this.

However, the output is not as expected. The bits are outputted double. 
When I slow down the signal it is generated as expected. Therefore I 
suspect I am spending too much time in the interrupt handler.

Am I correct in this analysis, and if so, would an implementation in 
assembler be a solution for this?

An alternative implementation would be a timer running at triple the 
speed I do now, and then control a pin from software. However, this 
would give me even less time in the interrupt, and so, if the problem is 
spending too much time in the interrupt handler, would not be a fix.

von aSma>> (Guest)


Rate this post
useful
not useful
Servus,
use DMA with a buffer for leds.

von André V. (Company: The IT Philosopher) (philosopher)


Rate this post
useful
not useful
DMA is one of the paths I was thinking about. If I understand the DMA 
implementation correctly, I would need to set up a buffer with 32 bit 
int values for each period. Thinking about the amount of RAM it would 
require I didn't look into that further.

Perhaps I could do something with two buffers to minimize the RAM usage, 
but I would need to see how to switch between RAM buffers seamlessly (so 
doing two DMA transfers sequentially without missing a period)

In the end I would like to be able to output on all four PWM outputs, 
would that be possible without using too much RAM?

von aSma>> (Guest)


Rate this post
useful
not useful
André V. wrote:
> DMA is one of the paths I was thinking about. If I understand the DMA
> implementation correctly, I would need to set up a buffer with 32 bit
> int values for each period. Thinking about the amount of RAM it would
> require I didn't look into that further.

The stm32f103 timer has only 16 bits.

> Perhaps I could do something with two buffers to minimize the RAM usage,
> but I would need to see how to switch between RAM buffers seamlessly (so
> doing two DMA transfers sequentially without missing a period)

Of course, you can use the half complete transfer interrupt to save RAM. 
So you can split your buffer in very small pieces. But be aware not to 
stay in the ISR. You should find the right mix.

> In the end I would like to be able to output on all four PWM outputs,
> would that be possible without using too much RAM?

With how much leds do you plan? How fast is your refresh rate?

von André V. (Company: The IT Philosopher) (philosopher)


Rate this post
useful
not useful
aSma>> wrote:
> The stm32f103 timer has only 16 bits.

I assumed I needed to provide my data as uint32_t as the example from 
the SDK ( 
/STM32Cube_FW_F1_V1.4.0/Projects/STM3210E_EVAL/Examples/TIM/TIM_DMA/Src/ 
main.c  ) declares a uint32_t buffer.

aSma>> wrote:
> With how much leds do you plan? How fast is your refresh rate?

I haven't fixed my plans yet. I want to see how much I can get out of 
the controller. Possibly use multiple channels and timers.

I am planning to create a controller that can work with WS2812/SK6812 
RGB led strips as well as the SK6812 RGBW led strips. I also want to 
look into the SPI and USART to control AP103/SK9288 led strips.

von aSma>> (Guest)


Rate this post
useful
not useful
André V. wrote:
> I assumed I needed to provide my data as uint32_t as the example from
> the SDK (
> /STM32Cube_FW_F1_V1.4.0/Projects/STM3210E_EVAL/Examples/TIM/TIM_DMA/Src/
> main.c  ) declares a uint32_t buffer.

I dont have the source.

> I haven't fixed my plans yet. I want to see how much I can get out of
> the controller. Possibly use multiple channels and timers.

https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf
1
When the refresh rate is 30fps,
2
cascade number are not less than 1024 points.

Before think about multiple channels and timers you need more RAM.

von André V. (Company: The IT Philosopher) (philosopher)


Rate this post
useful
not useful
aSma>> wrote:
> I dont have the source.

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef1.html

aSma>> wrote:
> Before think about multiple channels and timers you need more RAM.

As said, I didn't look into DMA before as my initial analysis was it 
would need too much RAM.

However, a commercially available solution, the FadeCandy, has 8 
channels of 64 pixels WS2812 RGB. If I could create a similar solution 
which also supports RGBW leds.

I suppose my targets are for now
* get one channel working
* get all four channels of the same timer working

Once that works, I will look at USB communication.

von aSma>> (Guest)


Rate this post
useful
not useful
André V. wrote:
> 
http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef1.htm

I won't registrate me there.

> As said, I didn't look into DMA before as my initial analysis was it
> would need too much RAM.

stm32f103 has 20kb RAM.

8 ch  64 pixel  24bits/pixel * 1/8 byte/bits = 1.54kb
With a 16bit timer you need about 3kb.

von André V. (Company: The IT Philosopher) (philosopher)


Rate this post
useful
not useful
It has been a long time ago since I started this thread. I would like to 
share the projects that resulted of this question:

The initial project lives here: 
https://github.com/BlaatSchaapArchive/LEDcontroller
That told project is kinda messy, so I started a new project, extracting 
the WS2812 code into a library. The library can run on the original 
STM32F1 but also has support for the Nordic nRF52 series: 
https://github.com/a-v-s/libws2812dma

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.