MikeEllis-personal / DMXfire

A DMX-controlled fire flicker effect using the Pico and WS2812 led arrays
4 stars 4 forks source link

Working out of the box? #2

Closed bdyetton closed 1 year ago

bdyetton commented 1 year ago

Hi Mike, Thanks for this project. Looks awesome! I'm trying to get it working on my Rpi Pico W. I'm struggling to run the test.py to see DMX channel information being received. I wanted to check this code should work without any modifications? Do you have a schematic you can share?

I assume a MAX485 is needed to change the PIO to the right voltage level for DMX, so i've got that hooked up as R0 <--> PIO28 (Pin 34). I know i'm sending DMX frames (my daisy chained light is flashing) but i'm not 100% i'm getting them through the MAX485 (i dont have an oscope to check). So the issue is either: a) wiring of MAX485 chip (i've checked this a bunch!) b) The code here c) The ENTTEC Pro not sending the DMX protocol with the correct timing

Any thoughs? Thanks!

bdyetton commented 1 year ago

Hi Mike, Thanks for the reply on the other thread. Glad to hear its working well! I think i'm very close myself. Thanks for the well documented code, its been easy to debug (and fun to learn about DMA, PIO and a little assembly) Using a scope i have been able to confirm:

However, my channel data is all zeros, and the DMA data that is copied from the SM registers to the channel bytearray is always the same.

My hunch is the hard coding of PIO4 TX comments i see in the code. I am unable to use State Machine 4 due to the pico system chosing it (for something unknown?), so i'm trying to use State Machine 1. What i'm guessing is happening (and i am a complete novice here) is that the DMA is copying blank data from the wrong State Machine (4), whereas it should be configured to copy from State Machine 1. Here is the output from SetChannelData():

Setup... Read: 0x50300023 Write: 0x2001b1a0 Count: 513
Readback Read: 0x50300023 Write: 0x2001b1a0 Count: 513
Triggered with CTRL word 0x00260823
Data from 0x50300023:  103  247  188  108  126  231  207  250

My hunch is that read address needs to be updated given i'm using state machine 1 and PIO28. Does that make sense? I'm not sure to update the hard coded lines in the code to deal with a different state machine/pin.

For example:

Any help would be much appreciated!

MikeEllis-personal commented 1 year ago

Great to hear you're making progress. I am also using an ENTtec Pro and it does send data very fast indeed - in spec, but very fast. A lot of my problems were caused by the start of the next frame arriving before the processor had responded to the PIO interrupt and reset the DMA. This was because, unless you count bytes, the only way to detect the end of a DMX frame is to detect the BREAK, and if this is minimum length, the processor is still resetting the DMA controller when the MAB appears. I fixed this by actually counting 512 DMX bytes received and pre-empting the BREAK in the receiver. It still goes wrong if you receive a short frame though... more work needed here.

On the shift from PIO4 to PIO1, I think you have identified the root of the problem, but you've not quite got the solution. You are right to shift from TREQ_PIO4_RX to TREQ_PIO1_RX, but the key (I think - I haven't tried this) is in the hard-coded value 0x50300023 in lines 208 and 247. If you look at the RP2040 datasheet, page 366, section 3.7 (PIO List of Registers), you'll see that 0x50300023 is made up from

To shift from PIO4 to PIO1, I think you need to: (a) use the PIO 0-3 base address (0x50200000) (b) the RXF1 offset (0x024) - i.e PIO-base+1 = PIO0+1 = PIO1 (c) retain the 0x03 for the correct byte within the word.

If I'm right, replace both occurrences of 0x50300023 with 0x50200027 (=0x50200000 + 0x24 + 0x3) and it should start to work.

Definitely something I need to build into the code in a more elegant way - thank goodness I commented it!

Good luck with your project...

bdyetton commented 1 year ago

Whoohooo!!! That worked a treat :)

I'm glad I was in the right dirrection there. Thanks for the detailed explanation, Mike!

Very excited to hook this up to my DJ setup now. I plan to add a strobe and potentially a few lasers to the pico too. I'll post a few pics/videos if it ends up looking cool :)

Thanks again for the code!