PDA

View Full Version : USART+PWM Problem



alex-x
- 11th May 2007, 20:16
Dear Friends im new in this forum , im a DJ and i interested with pic programming ,
İ want to make my own device for light intensty (PWM) controls at home but i have some problem on my programs i use pbp 2,47 and mcs2300 and PIC16F877

.Before i writte my problem i have looked this forum but couldt find it …

İ want to make a device to make control lights by the dmx512 signal , i found a code in this forum

But my device must have 4 chanel and 4 out ? i want to contlrol 4 lights intensty between
0-255 brightness…
and when it is 4 output it means that i cant use HPWM it must be normaly pwm between 0-255 .
Can you help me or if you have any example code like this to get dmx512 signals

This Code i have found in this forum…



DEFINE OSC 20
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 4 ' 25000 Baud @ 20MHz, 0,0%
DEFINE HSER_BAUD 250000
DEFINE HSER_CLROERR 1 ' Clear overflow automatically



counter VAR word ' Variable de travail WORD
idleflag VAR WORD
dummy VAR WORD
RCIF VAR byte
startcode VAR WORD
aminus VAR WORD
adresse_grada VAR WORD
x VAR WORD
newlevel1 VAR WORD
ADCON0=0
ADCON1=7
adresse_grada = 2


checkdmx:

counter = 1
pulsin portc.7,0,counter 'the break signal

if counter = 0 then
idleflag = 1 'either no dmx, or break was too long to count
'return
endif


if counter < 40 then checkdmx 'watching for 'break
'if you get here, an active low pulse was detected, but it was too short.

'probably just part of the datastream. So go back and look again.

'otherwise, a valid break was found and it's time to read the start code

dummy = RCREG 'clear out any garbage which may be in the USART
dummy = RCREG
SPBRG = 0
TXSTA.2 = 0 'brgh = 0
TXSTA.4 = 0
RCSTA.7 = 1
RCSTA.6 = 0 'setting 8 bit receive mode, no parity, etc
RCSTA.4 = 0 'check the datasheet to see what all these bits do
RCSTA.4 = 1 'now, the USART is on and ready to receive

while RCIF = 0:wend 'hover here after break, before start code

startcode = RCREG 'This is the first byte received after the break

if startcode <> 0 then checkdmx 'do your own stuff here on a non-zero code

aminus = adresse_grada - 1 'address1 is my target address

for x = 1 to aminus 'set up a loop to count almost to the address
while RCIF = 0:WEND 'sit here until a byte is received
dummy = RCREG 'stash the byte somewhere unimportant
next x

newlevel1 = RCREG 'This is your target channel data
pwm portc.2, newlevel1 ,100 'i want dimming a LED on PORTC.5
RCSTA.7 = 0 'turn off the USART

goto checkdmx
return

================================================== =====
============== AND OTHER CODE FOR INTERUPT I THİNK==========
================================================== =====

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

skimask
- 11th May 2007, 20:31
Dear Friends im new in this forum , im a DJ and i interested with pic programming ,İ want to make my own device for light intensty (PWM) controls at home but i have some problem on my programs i use pbp 2,47 and mcs2300 and PIC16F877

Sound familiar to anyone else? Same spelling mistakes...same basic format...different PIC...

alex-x
- 11th May 2007, 21:02
Yes ,
same problem with that friends but i use pic 16f877 and i see that they also still wait for help. but i think it is very difficult to make this device... cause i see many peoples here they look for this problem
it is impossible to learn everything by ourself if some friends will help us we can also learn how to make it.

Best Regards..

skimask
- 11th May 2007, 22:03
Yes ,
same problem with that friends but i use pic 16f877 and i see that they also still wait for help. but i think it is very difficult to make this device... cause i see many peoples here they look for this problem
it is impossible to learn everything by ourself if some friends will help us we can also learn how to make it.

Best Regards..

Be that as it may...
The first program has the ability (barely) to read one channel, if it weren't for a few fairly well hidden bugs.
The second chunk of code really isn't a program at all, it's just a chunk of code to receive the data (again, barely). It doesn't do anything with it after that. In car terms...what you've got is an engine...no body, no wheels.

How much PIC programming have you done in the past? Working with DMX is most definetely not a project for the beginner, not saying it can't be done, but you'll be shooting yourself in the foot in a few days.

alex-x
- 15th May 2007, 20:31
Thanks for your helping and gave me nice ADVICE :-))))
i dont think that it is big project for beginner and im not beginner too
i made many programs since years but not on DMX or some serial community .
i need help for programing like other friends . i look on internet and search it in all site but nobody knows how to make it i dont think that it is so big problem i need only how to decode more chanles there is some sample codes here but they are not working if somebody can help us to make this project we are so happy

skimask
- 15th May 2007, 20:39
i need help for programing like other friends . i look on internet and search it in all site but nobody knows how to make it i dont think that it is so big problem i need only how to decode more chanles there is some sample codes here but they are not working if somebody can help us to make this project we are so happy

Well, if nobody knew how to make it, then I guess DMX wouldn't be as big a standard and be as widely used as it is now would it? There are examples on this forum that seem to be working just fine, I say 'seem to be' as I have not tried them for myself, but the code looks good.

As I said before, in that program you posted above, there's a couple of fairly well hidden bugs in it that'll prevent it from doing anything...find those and you'll most likely have a working example to build from.

mister_e
- 15th May 2007, 20:52
5K$ (CAN Or even USD) is all you need to have a mine... IN PBP+ASM :D

Therečs a tons of working ASM, C, and maybe BASIC routines here and there, the key is to understand, test, the protocol itself.

I'm a DJ as well :D

skimask
- 15th May 2007, 21:04
5K$ (CAN Or even USD) is all you need to have a mine... IN PBP+ASM :D
Therečs a tons of working ASM, C, and maybe BASIC routines here and there, the key is to understand, test, the protocol itself.
I'm a DJ as well :D

I'll do it for 4K$ USD...none of that funny CAN stuff for me! :D

alex-x
- 15th May 2007, 21:05
it is ok friends i will work to make it bymyself and i wills end to this forum my code when it is ok

skimask
- 15th May 2007, 21:08
it is ok friends i will work to make it bymyself and i wills end to this forum my code when it is ok

I don't think anybody here is suggesting that you do it 'by yourself', but a bit of effort on your part wouldn't hurt the effort on anybody else's part...in other words...I can't speak for everybody, but, we'll help you as much as you help yourself...
So get writing some code...(and put away all the sharp objects within reach :) )

mister_e
- 15th May 2007, 21:09
...(and put away all the sharp objects within reach :) )

http://www.mister-e.org/Pics/ROFL Look who's talking :D

skimask
- 15th May 2007, 21:17
http://www.mister-e.org/Pics/ROFL Look who's talking :D

My lab is in rework right now (remember the water damage awhile back?)...
All I've got right now is some good smelling left over paint (wait 'till I post the pictures of the walls) and a bunch of wood that will become work benches...
I've got lots of sharp objects and power tools within reach...but no electronics to work on...

alex-x
- 15th May 2007, 22:05
@Mister_e
@Skimask

thanks for help me and look to my code please what is problem on it i have pic 16F877A and i use pbp 2,47 i have found this code int he forum and little designed it back for my Pic16F877A but it is not working i want to dim a led on portc1 (portc1and portc2 is pwm port on 877A pic) i want to dimming it but some probşlem on the code can you look and say what is my problem here?


'----------------------------------------------------------------------
INCLUDE "modedefs.bas"
@ DEVICE HS_OSC
@ DEVICE pic16F877A
@ DEVICE pic16F877A, WDT_OFF
@ DEVICE pic16F877A, PWRT_ON
@ DEVICE pic16F877A, PROTECT_OFF
@ DEVICE pic16F877A, BOD_OFF
'----------------------------------------------------------------------
DEFINE OSC 20
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 4
DEFINE HSER_BAUD 250000
DEFINE HSER_CLROERR 1
'----------------------------------------------------------------------
counter VAR word
idleflag VAR WORD
dummy VAR WORD
RCIF VAR byte
startcode VAR WORD
aminus VAR WORD
adresse_grada VAR WORD
x VAR WORD
newlevel1 VAR WORD
'----------------------------------------------------------------------
TRISB=0
TRISC=%10000000 ' portc.7 is RX input
ADCON0=0
ADCON1=7
adresse_grada=2


checkdmx:
counter = 1
pulsin portc.7,0,counter ' portc.7 is RX input
if counter = 0 then
idleflag = 1
endif
if counter < 40 then checkdmx

dummy = RCREG
dummy = RCREG
SPBRG = 0
TXSTA.2 = 0
TXSTA.4 = 0
RCSTA.7 = 1
RCSTA.6 = 0
RCSTA.4 = 0
RCSTA.4 = 1

while RCIF = 0:wend

startcode = RCREG

if startcode <> 0 then checkdmx

aminus = adresse_grada - 1 'address1 is my target address

for x = 1 to aminus
while RCIF = 0:WEND
dummy = RCREG
next x

newlevel1 = RCREG
pwm portc.1,newlevel1 ,100 'i want dimming a LED on PORTC.1
RCSTA.7 = 0 'turn off the USART
goto checkdmx
return

skimask
- 15th May 2007, 22:12
@Mister_e
@Skimask

thanks for help me and look to my code please what is problem on it i have pic 16F877A and i use pbp 2,47 i have found this code int he forum and little designed it back for my Pic16F877A but it is not working i want to dim a led on portc1 (portc1and portc2 is pwm port on 877A pic) i want to dimming it but some probşlem on the code can you look and say what is my problem here?

[code]
checkdmx:
.................................................. .........................
pwm portc.1,newlevel1 ,100 'i want dimming a LED on PORTC.1
.................................................. .........................
goto checkdmx
return

PWM doesn't run in the background... When you hit a PWM command, that's what you get, one shot, one pulse of PWM, then you loop back and start checking for more DMX data input, which you probably missed because you were trying to do PWM in the first place, and while you are waiting for some DMX data, your LED is off because the PIC isn't executing a PWM command. See how it all ties in together to make a seemingly non-working version of the code?
And what have you changed and/or tried to change in the code to make it work? Anything?
What you want is some interrupt driven code...interrupt driven serial input, interrupt driven PWM (or a hardware module, whichever works for you).
There's too much high speed stuff going on to be handled sequentially... Do a search for Instant Interrupts and Slow Speed Pulse Width Modulation. This code you've 'found' and keep copying probably isn't going to work for you in the end without knowing what's really going on in the first place and how to use interrupts.

JEC
- 15th May 2007, 23:41
Turns out that a few months ago, Microchip posted app notes for

* DMX512 transmission
* DMX512 reception
* Software-based 3 color PWM generation

Granted, it's all written in assembly. And it may not be quite as user-friendly to PBP newbies as DT's Instant Interrupts / SSPWM (very nice, BTW!).

But they can gather all 512 channels of dimmer data in 27 lines of .asm code. Pretty neat!

It's elegantly written, very compact and fairly easy to follow. Their write-up on DMX gives a nice overview of the various stages of the signal and what the processor needs to do during each.

Their trick for generating the break signal on the transmit side is nice, too.

Their DMX receive code is *not* interrupt based, but the PWM routine is.

Check out notes #1074 and #1076

Link:

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2048

Best,

JEC

alex-x
- 16th May 2007, 11:19
Dear JEC ;
i looked to that site but all codes are in asm i need in PBP if i can make it better for me .really i want to make it by myself since a week and i know it is not so good to want code from peoples but really i dont know anything about the this commination in picbasicpro

i read many documents and some code too but all in asm they explain everything in assembly language and when i want to make same thing in pbp then i have problem on interupts i think how can i solve it*?

i have seen your code in the forum and copyed it for my devices but couldnt make it yet your code was for "'F88 @ 16 MHz" but i have f877 and 20 mhz osc the code that what i posted here it is your code .do you have some example for me in picbasicpro only for beginner i need only led intensty
( PWM ) nothing more i tryed it like this small code too before but also problem (i look for adres on dipsw)


' PIC16F876 + 20 MHz
DEFINE OSC 20
@ DEVICE HS_OSC

DEFINE HSER_BITS 9
DEFINE HSER_RCSTA 208
DEFINE HSER_TXSTA 101
DEFINE HSER_BAUD 250000
DEFINE HSER_CLROERR 1

SYMBOL IN =PORTC.0
SYMBOL LED =PORTC.3 'LED

INPUT IN

TMP VAR WORD
TMP1 VAR WORD
VALORE VAR byte[8]
BREAK VAR WORD
NDMX VAR WORD
DATI VAR WORD
Clear

ADCON0=0
ADCON1=7

OPTION_REG.7=0
FOR TMP=0 TO 10
TOGGLE LED
PAUSE 200
NEXT TMP
LOW LED

MAIN:

NDMX=0
NDMX.0=PORTA.1
NDMX.1=PORTA.0
NDMX.2=PORTB.7
NDMX.3=PORTB.6
NDMX.4=PORTB.5
NDMX.5=PORTB.4
NDMX.6=PORTB.3
NDMX.7=PORTB.2
NDMX.8=PORTB.1
NDMX.9=PORTB.0

ndmx = ndmx ^ %0000001111111111
DATI=0
PULSIN in,0,break

IF BREAK>=44 THEN

HSERIN 2000,MAIN,[tmp,tmp1]
if tmp<>0 and tmp1<>0 then
goto main
endif

FOR TMP=1 TO ndmx
HSERIN 10,main,[tmp1]
NEXT TMP

FOR tmp=1 TO 64
hserin 10,EXIT,[VALORE[tmp]]
DATI=DATI+1
NEXT TMP

EXIT:
FOR TMP=1 TO DATI
VALORE[TMP]=VALORE[TMP]/4
NEXT TMP

'---------- here code that what i want to make for leds -----------------



ENDIF


GOTO MAIN

T.Jackson
- 16th May 2007, 11:55
Yeah - I think you're trying to bite off a bit more than you can chew. Better to start with something a bit simpler and gradually progress your skills along the way.

alex-x
- 16th May 2007, 12:09
:-) thanks

i have made many projects with pic but dmx is not like "led open or close"
it is different

i wait answer only who knows about the dmx and who can help me to solve this problem and if you want i pay too

skimask
- 16th May 2007, 14:15
:-) thanks

i have made many projects with pic but dmx is not like "led open or close"
it is different

i wait answer only who knows about the dmx and who can help me to solve this problem and if you want i pay too

It's not a matter of money...but if that's the way you want to go...so be it...
Do you know what a good software developer charges for those services these days? It's not cheap for a good, reliable, bug-free product...
(quite frankly neither do I...I've been paid for services before, but nothing with a contract, just a 'gentleman's agreement)
Looks like this is one that gets fed the corn and never learns to farm...

alex-x
- 16th May 2007, 16:11
it is ok friends , thanks for everything
i decided to buy a small device for me

DynamoBen
- 17th May 2007, 04:43
Jec, good find thanks for the info!

alex-x
- 17th May 2007, 17:57
@dynamoben

Can you explain to me this code for 1 chanel?

it was yours i have found it in the forum

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

skimask
- 17th May 2007, 18:13
DimmerCount VAR WORD ; Location in DMX string
.................................................. ....
End

That is the same code that you put in post #1.

As I explained before, that is only a code chunk, a small part of a much larger project. And quite frankly, if that code was the whole thing, it is fairly well commented and/or self-explanatory.

Do you know how DMX works? Do you know the basics of it's protocol?

DynamoBen
- 17th May 2007, 18:23
Skimask is correct. If you have a complete understanding of the DMX protocol the code I posted should make sense. The Microchip application note mentioned above has a document that talks about how to receive DMX. Their explanation and what I'm doing in my code match.

You have to have a complete understanding of DMX before you can write/understand any of this code. Once you have that its pretty simple, a short cut would be to use Microchips example code in your project. (see ASM command)

skimask
- 17th May 2007, 19:03
Their explanation and what I'm doing in my code match.
I got a question for you about this chunk of the code:

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

Does it just happen to work because the baud rate is fast enough that the loop almost can't keep up? How do you know that 'Dummy' always gets loaded with valid data (in this case the unwanted values) from RCREG instead of the same thing that was there last time around in the loop before the next byte actually arrives.
I would figure that the code would at least poll the RCIF flag and THEN get a new byte from RCREG.
Just curious...have no need to know, not building any projects anytime soon...(and this all ties back into my post #4 about the bugs...but you probably already figured that out...)

DynamoBen
- 17th May 2007, 19:14
Well the big thing that is missing here is the fact that this was snipped from an interrupt sub. All my code is interrupt based...to be honest I have actually since scaled back this code to make it a little simpler. I stripped out all the status checks and just bounce from one hserin command to another until I have the values I need.

skimask
- 17th May 2007, 19:23
Well the big thing that is missing here is the fact that this was snipped from an interrupt sub. All my code is interrupt based...to be honest I have actually since scaled back this code to make it a little simpler. I stripped out all the status checks and just bounce from one hserin command to another until I have the values I need.

Ok, makes sense...

I wonder if the O/P catches that part of your statement above...

DynamoBen
- 17th May 2007, 19:54
I wonder if the O/P catches that part of your statement above...

O/P, what is O/P??

skimask
- 17th May 2007, 20:46
O/P, what is O/P??

Original Poster

alex-x
- 18th May 2007, 23:52
This is the DMX recive code that does work.

It reads the first 8 byte of a DMX stream and sends the values to a RS232 output.

DEVICE = 16F648A
CONFIG HS_OSC, WDT_OFF, PWRTE_OFF, BODEN_OFF, LVP_OFF, CP_OFF
XTAL = 20
ALL_DIGITAL = TRUE

SYMBOL DmxIn = PORTB.1
SYMBOL RS232out = PORTB.4

DIM BreakDet AS WORD
DIM Ch AS WORD
DIM DMXdata[9] AS BYTE '8 DMX channel readout array
DIM Value AS BYTE

HSERIAL_CLEAR = ON

TXSTA.2 = 1 'bit BRGH; set USART in high speed mode
SPBRG = 4 'byte SPBRG; 250Kbaud@20MHz gives SPBRG=4
TXSTA.4 = 0 'bit SYNC; set asynchronous mode (=0) or synchronous mode (=1)
RCSTA.6 = 0 'bit RX9; setting 8bit(=0) or 9bit(=1) asynchronous receive mode

'--init--------------------------

Value = 0
Ch = 0
BreakDet = 0

DMXdata[1] = 0
DMXdata[2] = 0
DMXdata[3] = 0
DMXdata[4] = 0
DMXdata[5] = 0
DMXdata[6] = 0
DMXdata[7] = 0
DMXdata[8] = 0

'---main-------------------------

Main:
RCSTA.4=0 'bit CREN; disable serial reception
RCSTA.7=0 'bit SPEN; disable serial port input
CLEAR RCREG 'clear USART recieve register
'--------------------
REPEAT 'BREAK detection (88us)
BreakDet=PULSIN DmxIn,0
UNTIL BreakDet>=44
'--------------------
RCSTA.7=1 'bit SPEN; enable serial port input
RCSTA.4=1 'bit CREN; enable serial reception
CLEAR RCREG 'clear USART recieve register
'--------------------
REPEAT 'Skip 1st start byte
UNTIL PIR1.5=1 'bit RCIF; if reception is complete, RCIF=1
CLEAR RCREG 'clear USART recieve register
'--------------------
FOR Ch=1 TO 8 'readout first 8 channels
REPEAT
UNTIL PIR1.5=1 'bit RCIF; if reception is complete, RCIF=1
Value=RCREG 'read DMX data from USART recieve register
DMXdata[Ch]=Value
CLEAR RCREG 'clear USART recieve register
NEXT
GOSUB SendCommand 'send RS232 commands
GOTO Main
'----------------------------------
SendCommand:
SEROUT RS232out,84,[DEC DMXdata[1],"-",DEC DMXdata[2],"-",DEC DMXdata[3],"-",DEC DMXdata[4],"-",DEC DMXdata[5],"-",DEC DMXdata[6],"-",DEC DMXdata[7],"-",DEC DMXdata[8],13]
RETURN
'----------------------------------

alex-x
- 18th May 2007, 23:57
Device 16f877
xtal 20

HSERIAL_BAUD = 250000
HSERIAL_RCSTA = %10010000
HSERIAL_TXSTA = %00100000
HSERIAL_CLEAR = On

'CONFIG HS_OSC, WDT_OFF, PWRTE_OFF, BODEN_OFF, LVP_OFF, CP_OFF

ALL_DIGITAL = TRUE

Dim Sb As Byte
Dim Channel As Byte
Dim Var1[42] as byte' for (1-42) channels

delayms 100
RCSTA.7 = 1
RCSTA.6 = 0 'setting 8 bit receive mode, no parity, etc
RCSTA.4 = 0

Start:
RCSTA.4 = 0 'dis-enable serial

DMX_Break:

Sb=PulsIn portc.7,0 'measure a pulse

If Sb < = 44 Then DMX_Break '( test the pulse is greater than 88 us if not valid so return to DMX_Break and test again)

Clear RCREG 'clears rcreg twice as it can hold 2 bytes

RCSTA.4 = 1 'enable the serial to read value

For Channel = 1 To 42
Var1[Channel] = HRSin 'read value of dmx
Next Channel

goto start

alex-x
- 18th May 2007, 23:58
it is ok i solved my problem and made 4 chanel dmx512 decoder i have found some example code for proton and basic too you can see them

skimask
- 19th May 2007, 00:11
it is ok i solved my problem and made 4 chanel dmx512 decoder i have found some example code for proton and basic too you can see them

Proton Basic will never compile with PBP...
And it may work, but do you understand how it works so you can customize it to your needs...

alex-x
- 19th May 2007, 02:48
@skimask you are right this are in proton but can translate to pbp

Yes i understand how does it work , i know dmx since long time but not in pbp i made my project before in asm and it was easy to find example asm code to make dmx decoder and transmitter in microchip site also they give it in asm examples,

but when i want to make it in PBP i had some problem on interupts and to receive more chanel but now i understand how does it workin PBP too

alex-x
- 22nd May 2007, 19:01
Yes we canmake it so as a 1 chanel and workşng no problem but if i want to use it 4 or 8 chanel then i will need a pwm and pic has max 3 pwm no more how can we use and make other chanels pwm if i want to use 5 chanel dmx data for led inensty?Then i will need more pwm and i have to make it with code i think*

skimask
- 22nd May 2007, 20:06
Yes we canmake it so as a 1 chanel and workşng no problem but if i want to use it 4 or 8 chanel then i will need a pwm and pic has max 3 pwm no more how can we use and make other chanels pwm if i want to use 5 chanel dmx data for led inensty?Then i will need more pwm and i have to make it with code i think*

SSPWM...already been mentioned here...in this thread...

alex-x
- 23rd May 2007, 20:02
SSPWM ??

how is it?

skimask
- 23rd May 2007, 20:32
SSPWM ??

how is it?

Did you search for it yet?

mister_e
- 24th May 2007, 01:37
http://www.pbpgroup.com/modules/wfsection/article.php?articleid=12

alex-x
- 24th May 2007, 22:50
@mister_e thanks i will try it

dreamman
- 24th May 2007, 23:14
Hi , i tryed this code but it is not working as a pwm for led
where is the problem?

is it here ? How can we use newlevel1 as a pwm value?

"" pwm portc.2, newlevel1 ,100 'i want dimming a LED on PORTC.2"""




************************************************** *******
************************************************** *******

DEFINE OSC 20
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 4
DEFINE HSER_BAUD 250000
DEFINE HSER_CLROERR 1



counter VAR word
idleflag VAR WORD
dummy VAR WORD
RCIF VAR byte
startcode VAR WORD
aminus VAR WORD
adresse_grada VAR WORD
x VAR WORD
newlevel1 VAR WORD
ADCON0=0
ADCON1=7
adresse_grada = 2


checkdmx:

counter = 1
pulsin portc.7,0,counter
if counter = 0 then
idleflag = 1
endif


if counter < 40 then checkdmx

dummy = RCREG
dummy = RCREG
SPBRG = 0
TXSTA.2 = 0 'brgh = 0
TXSTA.4 = 0
RCSTA.7 = 1
RCSTA.6 = 0
RCSTA.4 = 0
RCSTA.4 = 1

while RCIF = 0:wend

startcode = RCREG

if startcode <> 0 then checkdmx

aminus = adresse_grada - 1

for x = 1 to aminus
while RCIF = 0:WEND
dummy = RCREG
next x

newlevel1 = RCREG
pwm portc.2, newlevel1 ,100 ' HERE PROBLEM I THINK
RCSTA.7 = 0

goto checkdmx
return

mister_e
- 24th May 2007, 23:19
Hi and welcome on the forum.

1. Those DEFINE's HSER_xxxx are not needed if you're not using HSERIN.

2. it look like another DMX routine to me ;)

What's working and what doesn't?

Do you understand the DMX protocol?

How about your schematic, configuration fuses, PIC#?

dreamman
- 25th May 2007, 00:01
Hi thanks yes im new in forum ,i was looking for dmx sample code in picbasicpro and came here
i have forund that code in the forum here (There is Same Code İn All thread ) :-) is it so difficult in PBP ?
and just tryed it but not working it is not real code ithink only sample

((( Schema is not so problem if you have any pic that which one has Usart (Rx) and (Hpwm) than it is ok and also u will need an for example SN75176A,SN75179B ( i use them in my controller ) i fu need more wpm chanels then u have to writte pwm code but if u need only 1 or 2 than you have to find a pic that which one has 2-3 hpwm ))) and 20 MHZ osc for 250kb baud rate

I know everything about the dmx512 protocol ,
http://www.dmx512-online.com/
http://www.usitt.org/standards/DMX512.html

it is 8n2 1 start 8 data and 2 stop , it is easy to receive it with usart config i know
What is it, how does it work and how can we receive it and i use it also in my projects and i dont have any problem i use pic assembly in my projects ,you can find example code in microchip website also for dmx512 transmitter and receiver master - slave

i just wanted to learn i have seen many code in forum about dmx512 and highspeed comm.. and some body said that has solved his dmx problem whit this code here in this adress in the forum
************************************************** *******
http://www.picbasic.co.uk/forum/showthread.php?t=1749&highlight=dmx%2A

************************************************** *******
Im not so good on the PicBasicPro i use assembly for my devices but when i look to code i didnt see any interupts and something also missing here
how is it possible to use it for pwm ?
did you make also any trying for dmx512 in pbp?
i just want to learn how is the interupts here cause when i use it in assembly i have some interupts routin in code and i i can make dmx512 receive in pbp too then it can be fine for me cause it takes more time to make projects in assembly pbp and c is better for time if you have big projects
When i look to exapmles also for rs485 they give it as a lowbaudrate(9400 and serin command to use) and PC to Pic not so high baudrate in examples what you found on the net..
************************************************** *******
Maybe SomeBody Can develop This code here and can teach us how to use "hserin" command to decode chanel and make interrupts code.
if anybody need in assembly i can help but here is pbp forum and when i look to forum many friends has problem in dmx512 protocol to decode it in pbp and also same code in everythread.

There is many site about the dmx512 protocol but they just tell the protocol not any code example or schema you can learn it in 20 min that what is it but the problem is how to use it in code ...

rlmack35
- 2nd December 2009, 09:45
SSPWM ??

how is it?

MiBAM is much smoother (personal opinion). You can dim 24 pins with very little processing power. Send the value and it retains it until you change it.