USART+PWM Problem


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 44
  1. #1
    Join Date
    May 2007
    Posts
    16

    Default USART+PWM Problem

    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

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by alex-x View Post
    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...

  3. #3
    Join Date
    May 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Sİgnal

    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..
    Last edited by alex-x; - 11th May 2007 at 21:04. Reason: mistake

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by alex-x View Post
    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.

  5. #5
    Join Date
    May 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default usart

    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

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by alex-x View Post
    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.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    5K$ (CAN Or even USD) is all you need to have a mine... IN PBP+ASM

    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
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    5K$ (CAN Or even USD) is all you need to have a mine... IN PBP+ASM
    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
    I'll do it for 4K$ USD...none of that funny CAN stuff for me!

  9. #9
    Join Date
    May 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default ok

    it is ok friends i will work to make it bymyself and i wills end to this forum my code when it is ok

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by alex-x View Post
    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 )

  11. #11
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    ...(and put away all the sharp objects within reach )
    Look who's talking
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Look who's talking
    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...

  13. #13
    Join Date
    May 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default usart

    @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

  14. #14
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by alex-x View Post
    @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.

  15. #15
    Join Date
    Nov 2004
    Posts
    61


    Did you find this post helpful? Yes | No

    Default DMX512 Source Code

    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/id...GE&nodeId=2048

    Best,

    JEC

  16. #16
    Join Date
    May 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default dmx

    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

  17. #17
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    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.

  18. #18
    Join Date
    May 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Smile dmx

    :-) 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

  19. #19
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by alex-x View Post
    :-) 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...
    Last edited by skimask; - 16th May 2007 at 14:18.

  20. #20
    Join Date
    May 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default dmx

    it is ok friends , thanks for everything
    i decided to buy a small device for me
    Last edited by alex-x; - 16th May 2007 at 19:03. Reason: x

  21. #21
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    Jec, good find thanks for the info!

  22. #22
    Join Date
    May 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default 512

    @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

  23. #23
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by alex-x View Post
    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?

  24. #24
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    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)
    Last edited by DynamoBen; - 17th May 2007 at 18:26.

  25. #25
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by DynamoBen View Post
    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...)

  26. #26
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    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.

  27. #27
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by DynamoBen View Post
    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...

  28. #28
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    I wonder if the O/P catches that part of your statement above...
    O/P, what is O/P??

  29. #29
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by DynamoBen View Post
    O/P, what is O/P??
    Original Poster

  30. #30
    Join Date
    May 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default dmx

    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
    '----------------------------------

  31. #31
    Join Date
    May 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default dmx

    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

  32. #32
    Join Date
    May 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default it is ok

    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

  33. #33
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by alex-x View Post
    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...

  34. #34
    Join Date
    May 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default dmx

    @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

  35. #35
    Join Date
    May 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default usart

    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*

  36. #36
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by alex-x View Post
    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...

  37. #37
    Join Date
    May 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default usart

    SSPWM ??

    how is it?

  38. #38
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by alex-x View Post
    SSPWM ??

    how is it?
    Did you search for it yet?

  39. #39
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  40. #40
    Join Date
    May 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default usart

    @mister_e thanks i will try it

Similar Threads

  1. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  2. byte Tx w/ USART 16f876a problem
    By GargamelDigi in forum mel PIC BASIC
    Replies: 2
    Last Post: - 15th July 2008, 05:50
  3. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  4. problem with USART
    By leemin in forum Serial
    Replies: 4
    Last Post: - 11th December 2006, 17:56
  5. PWM problem CCP2 port
    By NL2TTL in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 19th September 2006, 23:34

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts