NoahLD
- 29th July 2009, 03:05
I consider myself a newbie with PIC programming but have been using dmx devices for years. It's now time to try and build my own. I have done a few projects with microcontrollers but most of my projects have been stand alone PWM and ADC projects.
I've got my USITT /ESTA DMX info book and code that sort of works.
I'm just trying to receive the data and look at it on my serial display. For now, I'm just trying to receive channel one. I'll graduate up to counters and dip switches later.
When I receive the data, the numbers come in correct until I get to 3%, then it hangs up but recovers at 5%. Then it hangs up from 14% on up to 19. There are other places that it hangs up all the way up to 100.
I have tested my controller (A Swisson DMX tester) and looked at it on my scope.
It gets weirder. When I take channel two up to 4% (not 1,2,or 3, just 4 and some other numbers above that) the code works perfectly for channel one.
Timing issue?
Missing break detection?
Thanks for your help...........
Here's my code:
It's on a 16F876A
'************************************************* ***************
'* Name : DMX21LCD.BAS *
'* Author : Noah Davis *
'* Notice : Copyright (c) 2009 *
'* : All Rights Reserved *
'* Date : 7/28/2009 *
'* Version : 21.0 *
'* Notes : *
'* : *
'************************************************* ***************
init:
DEFINE OSC 20
Include "modedefs.bas"
DEFINE CHAR_PACING 1000
define HSER_TXSTA 24H
DEFINE HSER_BAUD 250000
DEFINE HSER_CLROERR 1
TXSTA.2 = 1 'brgh = 0 1= high speed
SPBRG = 4
Symbol DmxIn = PORTC.7
Symbol TestLed = PORTA.0
counter var byte
BreakDet var word
dummy var word
startcode var byte
newlevel1 var byte
ADCON1 =%00000111 'Turns the A/D converters to digital
main:
pulsin DmxIn,0,BreakDet 'measure the break
if breakdet < 40 then main 'if break is less than 80uS then try again
dummy = RCREG
dummy = RCREG
RCSTA.7 = 1 'sets SPEN
RCSTA.4 = 0 'Clear CREN
RCSTA.4 = 1 'Sets CREN
while PIR1.5 = 0 'wait for USART receive flag
wend
startcode = RCREG 'that lovely 0 start code
while PIR1.5 = 0 'wait for channel one
wend
newlevel1 = RCREG ' my data
RCSTA.7 = 0 'shut off the USART
RCSTA.4 = 0 'Clear CREN
Gosub SendCommand
goto main
SendCommand:
serout PORTC.6,T9600,[$FE,$01] ' clear the screen
Serout PORTC.6,T9600,[#newlevel1] 'send data to screen
return
I've got my USITT /ESTA DMX info book and code that sort of works.
I'm just trying to receive the data and look at it on my serial display. For now, I'm just trying to receive channel one. I'll graduate up to counters and dip switches later.
When I receive the data, the numbers come in correct until I get to 3%, then it hangs up but recovers at 5%. Then it hangs up from 14% on up to 19. There are other places that it hangs up all the way up to 100.
I have tested my controller (A Swisson DMX tester) and looked at it on my scope.
It gets weirder. When I take channel two up to 4% (not 1,2,or 3, just 4 and some other numbers above that) the code works perfectly for channel one.
Timing issue?
Missing break detection?
Thanks for your help...........
Here's my code:
It's on a 16F876A
'************************************************* ***************
'* Name : DMX21LCD.BAS *
'* Author : Noah Davis *
'* Notice : Copyright (c) 2009 *
'* : All Rights Reserved *
'* Date : 7/28/2009 *
'* Version : 21.0 *
'* Notes : *
'* : *
'************************************************* ***************
init:
DEFINE OSC 20
Include "modedefs.bas"
DEFINE CHAR_PACING 1000
define HSER_TXSTA 24H
DEFINE HSER_BAUD 250000
DEFINE HSER_CLROERR 1
TXSTA.2 = 1 'brgh = 0 1= high speed
SPBRG = 4
Symbol DmxIn = PORTC.7
Symbol TestLed = PORTA.0
counter var byte
BreakDet var word
dummy var word
startcode var byte
newlevel1 var byte
ADCON1 =%00000111 'Turns the A/D converters to digital
main:
pulsin DmxIn,0,BreakDet 'measure the break
if breakdet < 40 then main 'if break is less than 80uS then try again
dummy = RCREG
dummy = RCREG
RCSTA.7 = 1 'sets SPEN
RCSTA.4 = 0 'Clear CREN
RCSTA.4 = 1 'Sets CREN
while PIR1.5 = 0 'wait for USART receive flag
wend
startcode = RCREG 'that lovely 0 start code
while PIR1.5 = 0 'wait for channel one
wend
newlevel1 = RCREG ' my data
RCSTA.7 = 0 'shut off the USART
RCSTA.4 = 0 'Clear CREN
Gosub SendCommand
goto main
SendCommand:
serout PORTC.6,T9600,[$FE,$01] ' clear the screen
Serout PORTC.6,T9600,[#newlevel1] 'send data to screen
return