yes i now it.
but i want to know how to use "hsein" command to receive for dmxsginal
is everything true here in the code?can i use it for dimming a led ?
yes i now it.
but i want to know how to use "hsein" command to receive for dmxsginal
is everything true here in the code?can i use it for dimming a led ?
Last edited by syscoder; - 5th March 2007 at 15:45. Reason: missing
Heh...
That's my code snipped from a year or so ago.
It does work, and it's dead stable. But you need to understand that it's only a subroutine, called from the main program loop. You get to write the main loop.
The reason for not using HSERIN is that I found there was a slight startup delay when using the command. Using PULSIN to find the break, then calling HSERIN took too long and I was losing data. As you may know, the make-after-break signal can in some cases only be a few microseconds long.
At 20 MHz, you get 5 assembly instructions per microsecond, which may not be enough.
When I first wrote the code I didn't dig too deeply in PBP's internals to see what exactly was happening when HSERIN was invoked. But it seemed like an overhead issue within the command.
And note that the 'skip' function which can be used as part of HSERIN is only byte sized. So 'skip 254' works but 'skip 257' doesn't.
It was easier to access the registers directly and be assured that everything was being received properly.
Note that there's absolutely no guarantee that each and every packet coming down the wire is exclusively dimmer data.
JEC
Like most things there is more than one way to accomplish a task. Last year I saw the post from JEC about DMX. While it was nice to hear that DMX was possible with PICBasic I really wanted something that was interrupt based.
After doing some research I found that all you need to do is look for a framing error, after which should be the start code (there may be several framing errors in a row). Over the last few days I have created the interrupt code snip below. While I haven't tested it exhaustively it seems to work.
Code:DimmerCount VAR WORD ; Location in DMX string DMXStartAddr VAR WORD ; DMX start address DMXStartCode VAR BYTE ; DMX Start code (Dimmer=0) Dummy VAR BYTE DMX_State VAR BYTE ; Stage of DMX reception Valid_Break CON 1 Valid_SC CON 2 Valid_Data CON 3 Disable INTERRUPT_SUB: IF OERR Then CREN = 0 CREN = 1 ; Clear Overrun Errors High Err_LED ; Notify user of overrun error DMX_State=0 EndIF IF FERR Then FERR = 0 DMX_State=Valid_Break Else GoSub RX_DMX_Data EndIF Dummy=RCREG ; Empty UART of junk data Resume RX_DMX_Data: IF DMX_State=Valid_Break Then HSerin 20,NoData,[DMXStartCode] ; Start code of 0 = dimmer data IF DMXStartCode=0 Then DMX_State=Valid_SC Else High Err_LED ; Notify user of Error in Start Code DMX_State=0 EndIF EndIF IF DMX_State=Valid_SC Then For DimmerCount=0 TO DMXStartAddr; Count incoming data bytes (frames) Dummy=RCREG ; Read unwanted values Next DimmerCount DMX_State=Valid_Data EndIF IF DMX_State=Valid_Data Then HSerin 20,NoData,[STR DataBuffer\Number_Of_Channels] DMX_State=0 EndIF IF DMX_State=0 Then Resume EndIF GoTo RX_DMX_Data NoData: DMX_State=0 Resume Enable End
Last edited by DynamoBen; - 8th March 2007 at 05:17.
Well, I can see some potential problems with that program.
So be ready for some more questions from programmer07, oops, I mean syscoder.
<br>
DT
Assuming it's a snip and a ISR... first observation, something like a L?CALL have to be changebut it's a first & fast observation.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks