Chat freely about anything...

User avatar
By hasinvadi48
#89873 Hi guys I want to do fast multiplexing with PWM using 74HC595 shift registers and ESP8266. I pretty much want to run 6-digit 7-segment display with every single segment individually dimmable. I managed to run it at around ~60hz with Ticker library (software) with 5 levels of brightness. This is acceptable but I would like to run it faster and full 255 level pwm. I tried HW interrupt timer with SPI transfer inside which is a big no-no apparently :D It works perfectly and is super fast in a simple testing sketch but once wifi is added, it instantly crashes into boot loop. I will be happy for any ideas.
User avatar
By eriksl
#90081 I think it can be done. I have an PWM implementation that can drive 1 to 16 GPIO's at
18 bit: 15 Hz
17 bit: 30 Hz
16 bit: 60 Hz
15 bit: 120 Hz
14 bit: 240 Hz
etc.

I think that is fast enough to do what you want. Also I think you will be able to do SPI in parallel without problems. Are you talking of an SPI master or slave? For an SPI master you don't really need interrupts. For a slave it's another story of course, I don't have experience with the SPI slave on the ESP8266.

The trick is:
- prepare anything possible before starting the PWM
- don't do "anything" in the ISR
- use the timer2 interrupt
- for short delays, the timer will already have fired before you leave the ISR, so don't leave the ISR for those short intervals
- use the NMI