Author Topic: Need RTOS for POV display + playing wav file?  (Read 1346 times)

0 Members and 1 Guest are viewing this topic.

Offline CamachoTopic starter

  • Newbie
  • Posts: 7
  • Country: us
Need RTOS for POV display + playing wav file?
« on: January 30, 2024, 02:11:08 am »
Hello,

I've never done any microcontroller programming, but I know my way around kicad and I did take C programming in college (back in the middle ages). For a project I wish to write some code that drives a persistence of vision display as well as plays some low-quality wave files from a flash IC. 

My question is will I need to run an RTOS to do this? Or can I do without, eg using interrupts to turn the LEDs on/off while a wav file is playing?

Also, can anyone suggest a rough minimum IC to do this? I was thinking I would order some sort of STM32 from LCSC.

Thanks!
 

Online peter-h

  • Super Contributor
  • ***
  • Posts: 3698
  • Country: gb
  • Doing electronics since the 1960s...
Re: Need RTOS for POV display + playing wav file?
« Reply #1 on: January 30, 2024, 12:03:24 pm »
This is a vast topic but in general an RTOS makes life a lot easier. I use FreeRTOS.

OTOH if you can reasonably structure your project as a loop, plus a timer interrupt (say 1kHz) plus I/O interrupts (say for a UART, SPI, etc) then that will take less time to implement.

In your case, if I get your drift, you are reading 16 bit values out of an SPI FLASH chip, at a fixed rate say 48kHz, stuffing them into two DACs, and you want to generate one of those funny spectrum analyser patterns on an LCD. The 48kHz code is best run off a timer interrupt, and then a timer interrupt running at say 10-100Hz will pick up some recent values (you put some of the DAC samples somewhere), process them and update the LCD. That would be the simple way. The RTOS way would still use a 48kHz interrupt to do the first bit (you have to do that because audio playback must be done at exact sample timing) and you could use an RTOS task for the LCD stuff but it is hardly worth it.

If I was doing it I would use my RTOS stuff because I already have it.

Can't guess what CPU power you need. Is it .wav (which is lossless encoded and easy) or is it .mp3 (which needs decoding)?

Sorry I said LCD but you are using LEDs...

I don't think you need an RTOS.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 
The following users thanked this post: 5U4GB

Offline CamachoTopic starter

  • Newbie
  • Posts: 7
  • Country: us
Re: Need RTOS for POV display + playing wav file?
« Reply #2 on: January 30, 2024, 09:48:38 pm »
Peter, thanks for the reply.

To answer your question about the audio file type, I'm imagining 8KHz 8-bit WAV files or something like that.

Maybe I wasn't clear, but I just want to make a spinning persistence of vision display, not unlike the one in the attached image. It would be a clock that also speaks the time (not very original, I know). The display will be approximately 7x100 pixels in a circular pattern. I think that means if the motor is spinning 1000 RPM the leds would need to fire at around 100Khz.

So I assume this means there could be a 100KHz interrupt timer that runs the routine that draws 7 pixels per cycle? Or every few degrees of arm (propeller?) movement?

My concern is this routine would disrupt the audio playing, as there needs to be many pixel drawing routines executed while each audio file is played. But if there is a buffer, and the dac renders the audio independently, maybe this isn't an issue? Please forgive my naivete.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: Need RTOS for POV display + playing wav file?
« Reply #3 on: January 30, 2024, 10:01:28 pm »
Cheap stm32G030, circular DMA will handle this like nothing with barely any cpu effort.
Any other stm32 with OTG USB will also work while making file/data handling much easier.

1K rpm is 16.6 revolutions per second. Let's say there're 20 leds.
100KHz/(16.6*20) will give about 300 pixel resolution, much higher than seen in that picture.

DMA can get this done much faster, easily in the MHz range.
« Last Edit: January 30, 2024, 10:11:23 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline CamachoTopic starter

  • Newbie
  • Posts: 7
  • Country: us
Re: Need RTOS for POV display + playing wav file?
« Reply #4 on: January 31, 2024, 06:53:14 am »
Cheap stm32G030, circular DMA will handle this like nothing with barely any cpu effort.
Any other stm32 with OTG USB will also work while making file/data handling much easier.

1K rpm is 16.6 revolutions per second. Let's say there're 20 leds.
100KHz/(16.6*20) will give about 300 pixel resolution, much higher than seen in that picture.

DMA can get this done much faster, easily in the MHz range.

David, thank you, your mention of DMA was what I was looking for.

Regarding the IC, I had assumed the STM32 was overpowered for this application. I was looking at the STM32F051 clones as they are cheap ob LCSC (although not as cheap as G030) and have a built in DAC. I also saw ATTINY1616 with DAC, which is cheaper, but no DMA. And I don't really want to get started with Arduino anyway.

Regarding the frequency, I forgot to divide by 60, so it would be more like 1.67KHz, not 100KHz. But that's neither here nor there.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: Need RTOS for POV display + playing wav file?
« Reply #5 on: January 31, 2024, 07:59:11 am »
The g030 can be found in AliExpress for 35 cents or so,
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline Berni

  • Super Contributor
  • ***
  • Posts: 4957
  • Country: si
Re: Need RTOS for POV display + playing wav file?
« Reply #6 on: January 31, 2024, 08:26:55 am »
You better not take on a RTOS before you already know a fair bit of programming. They add complexity and might train you into some bad programing habits if you don't know how RTOSes actually work.

You can always use interrupts on MCUs to get simple multitasking functionality. This is especially effective on simpler smaller MCUs because they are not heavily pipelined and have a small number of CPU registers, this means they can jump into a interrupt handler and back out very quickly with cycle perfect precision.

Alternatively you can indeed use a DMA to move data into IO pins, but that tends to be quite complex to set up, also not all DMA controllers are made equal, some are much more smart and flexible than others.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: Need RTOS for POV display + playing wav file?
« Reply #7 on: January 31, 2024, 09:43:02 am »
DMA in stm32g0 series is very simple and easy!
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Online peter-h

  • Super Contributor
  • ***
  • Posts: 3698
  • Country: gb
  • Doing electronics since the 1960s...
Re: Need RTOS for POV display + playing wav file?
« Reply #8 on: January 31, 2024, 11:50:32 am »
DMA is usable only if the FLASH memory is memory-mapped, not the more common SPI type.

What kind of display is used? LED matrix, or LCD?

OK so this is low quality audio.

In any case, the common 180MHz CPUs (like my 32F417) can do a 100kHz interrupt easily, reading FLASH (parallel or SPI) and loading a DAC.

I agree, an RTOS is unnecessary work.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26907
  • Country: nl
    • NCT Developments
Re: Need RTOS for POV display + playing wav file?
« Reply #9 on: January 31, 2024, 12:09:58 pm »
The worst thing to do is try to find the cheapest parts. Just get a big microcontroller with lots of IO, memory and processing speed. Also look at NXP's LPC range of ARM microcontrollers. I like these much better compared to what ST is offering. Good documentation and straightforward to use.

Playing sound is something which can be nicely done using DMA (streaming chunks of data out of an SPI flash). A built-in DAC makes life a lot easier but PWM will work just as good.

DMA is usable only if the FLASH memory is memory-mapped, not the more common SPI type.
But you can do DMA on the SPI interface. I think I have done that a long time ago.
« Last Edit: January 31, 2024, 12:11:33 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: Need RTOS for POV display + playing wav file?
« Reply #10 on: January 31, 2024, 12:33:26 pm »
It's usable anyways without ant mapping, join sdi with sdo and led buffer input, send read cmd, enable led buffer, tell the DMA to read n bytes, the SPI flash output will go straight to the leds.
I've done this to send video from SPI nand to a LCD, making a cheap video player.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline selcuk

  • Regular Contributor
  • *
  • Posts: 123
  • Country: tr
Re: Need RTOS for POV display + playing wav file?
« Reply #11 on: January 31, 2024, 01:10:56 pm »
Operation systems for small embedded systems are not that complicated. There are many functions to learn but you can still use interrupts to turn on leds on timely basis. OS may reserve first timer interrupt then you can use the second one, etc. So there is no hard isolation between hardware and application.

Additionally, I can recommend ESP32 family of MCUs. Their IDF framework includes FreeRTOS, hardware drivers and software libraries. You may find similar projects on the internet. Check out this one for example:

https://github.com/parabuzzle/esp-idf-simple-audio-player/tree/main
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14481
  • Country: fr
Re: Need RTOS for POV display + playing wav file?
« Reply #12 on: January 31, 2024, 07:47:44 pm »
The worst thing to do is try to find the cheapest parts. Just get a big microcontroller with lots of IO, memory and processing speed. Also look at NXP's LPC range of ARM microcontrollers. I like these much better compared to what ST is offering. Good documentation and straightforward to use.

Playing sound is something which can be nicely done using DMA (streaming chunks of data out of an SPI flash). A built-in DAC makes life a lot easier but PWM will work just as good.

DMA is usable only if the FLASH memory is memory-mapped, not the more common SPI type.
But you can do DMA on the SPI interface. I think I have done that a long time ago.

Yes, of course you can. That's just a bit more work as you need to handle the commands yourself, while QSPI controller or internal flash will do that transparently. But that's not rocket science.
The OP could also just use a QSPI flash otherwise.

Still the whole project looks a bit ambitious for someone who has never done any embedded development. The OP should probably start with something simpler. But having a motivating goal is still a good thing.
As to an appropriate MCU, there are many out there. Something cheap with ample resources for this would be the RP2040.
« Last Edit: January 31, 2024, 07:49:51 pm by SiliconWizard »
 

Offline CamachoTopic starter

  • Newbie
  • Posts: 7
  • Country: us
Re: Need RTOS for POV display + playing wav file?
« Reply #13 on: January 31, 2024, 08:55:19 pm »
Ok, thanks everyone for the replies. I agree with Siliconwizard - this is a bit ambitious, but I will be definitely writing some simpler programs first - probably as part of a series of tutorials or online course.

NCTNICO, thanks, using PWM sounds interesting and that would allow the use of the inexpensive STM32G030 suggested by David.

It sounds like I should just try this first with interrupts and skip the DMA if possible. And definitely no RTOS.


 

Online peter-h

  • Super Contributor
  • ***
  • Posts: 3698
  • Country: gb
  • Doing electronics since the 1960s...
Re: Need RTOS for POV display + playing wav file?
« Reply #14 on: February 01, 2024, 11:24:06 am »
You can do SPI via DMA but SPI FLASH devices need commands to set up the starting address etc. Also the chunks which can be sequentially read are of limited length - not usually IIRC the full device. A while since I did this...

In this case the OP is probably storing audio fragments and they can be stored in the CPU FLASH which can be read easily with DMA. It can even be reprogrammed if you make clever use of the block based erase/program options.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: Need RTOS for POV display + playing wav file?
« Reply #15 on: February 01, 2024, 11:41:35 am »
Both SPI not and nand memories can be read sequentially.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: nctnico

Offline agehall

  • Frequent Contributor
  • **
  • Posts: 383
  • Country: se
Re: Need RTOS for POV display + playing wav file?
« Reply #16 on: February 01, 2024, 06:05:33 pm »
This reminds me of the PC demo scene back in the early 90s. We did a lot more back then with a lot less hardware than what you find in a pretty bog standard MCU these days. I don’t think there is anything that is very complicated in what you are looking to do here nor does it require an RTOS.
 

Offline CamachoTopic starter

  • Newbie
  • Posts: 7
  • Country: us
Re: Need RTOS for POV display + playing wav file?
« Reply #17 on: February 01, 2024, 09:47:30 pm »
Both SPI not and nand memories can be read sequentially.

Thanks David. I'm planning to use external 16Mbit NOR flash memory.
 

Offline CamachoTopic starter

  • Newbie
  • Posts: 7
  • Country: us
Re: Need RTOS for POV display + playing wav file?
« Reply #18 on: February 01, 2024, 09:48:22 pm »
This reminds me of the PC demo scene back in the early 90s. We did a lot more back then with a lot less hardware than what you find in a pretty bog standard MCU these days. I don’t think there is anything that is very complicated in what you are looking to do here nor does it require an RTOS.

Thanks, I will definitely skip the RTOS.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14481
  • Country: fr
Re: Need RTOS for POV display + playing wav file?
« Reply #19 on: February 01, 2024, 09:55:33 pm »
Both SPI not and nand memories can be read sequentially.

Thanks David. I'm planning to use external 16Mbit NOR flash memory.

If you pick a MCU with a QSPI controller, I suggest using a flash chip with a QSPI interface. These are ubiquitous now, so easy to source. The upside is that it'll allow to use the flash chip memory-mapped, and reads will be much faster. (The downside is that you'll have to set up the QSPI controller.)
 

Offline CamachoTopic starter

  • Newbie
  • Posts: 7
  • Country: us
Re: Need RTOS for POV display + playing wav file?
« Reply #20 on: February 01, 2024, 10:03:35 pm »
Both SPI not and nand memories can be read sequentially.

Thanks David. I'm planning to use external 16Mbit NOR flash memory.

If you pick a MCU with a QSPI controller, I suggest using a flash chip with a QSPI interface. These are ubiquitous now, so easy to source. The upside is that it'll allow to use the flash chip memory-mapped, and reads will be much faster. (The downside is that you'll have to set up the QSPI controller.)

Thanks, the flash chips I was looking at are "dual and quad serial" which I assume is QSPI
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf