USART+PWM Problem


Closed Thread
Results 1 to 40 of 44

Hybrid View

  1. #1
    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

  2. #2
    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?

  3. #3
    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.

  4. #4
    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...)

  5. #5
    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.

  6. #6
    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...

  7. #7
    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??

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

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