EmbDev.net

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


Author: André V. (Company: The IT Philosopher) (philosopher)
Posted on:
Attached files:

Rate this post
0 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.

Author: aSma>> (Guest)
Posted on:

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

Author: André V. (Company: The IT Philosopher) (philosopher)
Posted on:

Rate this post
0 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?

Author: aSma>> (Guest)
Posted on:

Rate this post
0 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?

Author: André V. (Company: The IT Philosopher) (philosopher)
Posted on:

Rate this post
0 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.

Author: aSma>> (Guest)
Posted on:

Rate this post
0 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
When the refresh rate is 30fps,
cascade number are not less than 1024 points.

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

Author: André V. (Company: The IT Philosopher) (philosopher)
Posted on:

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

http://www.st.com/content/st_com/en/products/embed...

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.

Author: aSma>> (Guest)
Posted on:

Rate this post
0 useful
not useful
André V. wrote:
> 
http://www.st.com/content/st_com/en/products/embed...

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.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.