Bit Angle Modulation (BAM) in a PIC


Closed Thread
Results 1 to 40 of 151

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by talatsahim View Post
    will work mibam with hserin on 16F828?
    Yes it will.
    DT

  2. #2
    Join Date
    Nov 2009
    Posts
    14


    Did you find this post helpful? Yes | No

    Question thanks

    Quote Originally Posted by Darrel Taylor View Post
    Yes it will.
    Sorry, my very poor english.
    Im new pbp user.
    can you help me why not work my code?
    Device 16F628





    Code:
    DEFINE OSC 20
    CLEAR
    
    ;_________________________Interrupt Context save locations]_________________
    
    wsave       var byte    $20     SYSTEM      ' location for W if in bank0
    wsave1      VAR BYTE    $A0     SYSTEM      ' location for W if in bank1
    wsave2      VAR BYTE    $120    SYSTEM      ' location for W if in bank2
    ssave       VAR BYTE    BANK0   SYSTEM      ' location for STATUS register
    psave       VAR BYTE    BANK0   SYSTEM      ' location for PCLATH register
    ;----[ MIBAM Setup ]--------------------------------------------------------
    BAM_COUNT CON 3                     ; How many BAM Pins are used?
    INCLUDE "MIBAM.pbp"                 ; Mirror Image BAM module
    
    BAM_FREQ    CON 100
    DEFINE BAM_INFO 1  
    DEFINE HSER_BAUD 250000
    DEFINE HSER_CLROERR 1
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h 
    
    
    
    KANAL       CON 3   
    BREAKTIME   VAR BYTE
    DMXFLAG     VAR BIT
    STARTBYTE   VAR BYTE
    ADR         VAR BYTE
    RVAL        VAR BYTE
    GVAL        VAR BYTE
    BVAL        VAR BYTE
    YVAL        VAR BYTE
    X           VAR BYTE
    DUMMY       VAR BYTE
    i           VAR BYTE
    
    '*****************  MIBAM  ***************************************************
    RED         VAR BYTE
    GREEN       VAR BYTE
    BLUE        VAR BYTE
    
    ASM
    BAM_LIST  macro                     ; Define PIN's to use for BAM
         BAM_PIN (PORTB,5, RED)         ;   and the associated Duty variables
         BAM_PIN (PORTB,6, GREEN)
         BAM_PIN (PORTB,7, BLUE)
      endm
      BAM_INIT  BAM_LIST                ; Initialize the Pins
    ENDASM
    '*****************************************************************************
    TRISA=%00111001
    TRISB=%00000010 
    
    ScopeSync   VAR     PORTB.2   
    RXT         VAR     PORTB.1
    ERR         VAR     PORTB.4
    
    CMCON=7        
    VRCON=0 
    OPTION_REG.7 =0
    INTCON =%11000000  
    
    
    
    START:
    PAUSE 100
    DUMMY=0
    ADR = KANAL-1
    RED=50
    GREEN=100
    BLUE=180
    ERR=0
    GOTO LOOP
    '--------->>>>>>>>
    
    DMXBAK:
    i=i+1
    IF i> 200 THEN RETURN
    BREAKTIME =1:DMXFLAG = 0
    pulsin  RXT,0,BREAKTIME 
    
    if BREAKTIME = 0 then return  
    if BREAKTIME < 30 then DMXBAK 
    
    PIE1.5=1 
    RCREG = dummy 
    RCREG = dummy '
    SPBRG = 0 
    TXSTA.2 = 0 
    TXSTA.4 = 0 
    RCSTA.7 = 1 
    RCSTA.6 = 0  
    RCSTA.4 = 0 
    RCSTA.4 = 1 
    
    while RCIF = 0:wend 
    STARTBYTE = RCREG
    if STARTBYTE = 0 then 
         
        for x = 1 to ADR
        while RCIF = 0:WEND 
        dummy = RCREG 
        next x
        
        DATAAL:
        RVAL= RCREG 
        RCREG = 0 
        RCREG = 0 
        GVAL= RCREG 
        RCREG = 0 
        RCREG = 0 
        BVAL= RCREG 
    ENDIF
    RCSTA.7 = 0 
    DMXFLAG=1
    return
    
    
    LOOP:
        IF DMXFLAG=1 THEN
            RED= RVAL
            GREEN=GVAL
            BLUE=BVAL
        ENDIF
    GOSUB DMXBAK
        IF i>200 THEN 
            ERR=0
            ELSE
            ERR=1
        ENDIF
    i=0
    DUMMY=0
    
    GOTO LOOP
    
    END

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by talatsahim View Post
    can you help me why not work my code?
    Yes I can ...
    1. HSER defines only work with HSERIN/HSEROUT. If you are reading RCREG manually, the baud rate will not have been set by PBP and you will have to do that manually as well.<br><br>
    2. pulsin RXT,0,BREAKTIME, PULSIN does not work with interrupts. The timing will be wrong and you'll almost never see a Break pulse that way. Fortunately, the USART does it for you. Look for an FERR flag (framing error) which happens on every Break.<br><br>
    3. INTCON =%11000000, interrupts are controlled by the MIBAM routines. Don't change any interrupt registers.<br><br>
    4. PIE1.5=1, you've enabled the USART receive Interrupt ... don't do that.<br><br>
    5. RCREG = dummy, RCREG is a Read-Only register. Don't know what you were trying to do there.<br><br>
    6. SPBRG = 0, it's unlikely that you would want to put SPBRG (Baud Rate Generator Register) to 0 for any reason.<br><br>
    7. TXSTA.2 = 0, It's unlikely that you would want to put the USART in Low Speed mode when running at 250Kbaud.<br><br>
    8. TXSTA.4 = 0, OK, it's not synchronous mode .... but what is it?<br><br>
    9. I have no idea what you are trying to do here. RCREG is read-only, and you're reading 3-bytes from a maximum 2-byte buffer, without checking to see if anything is there.
      Code:
      DATAAL:
      RVAL= RCREG 
      RCREG = 0 
      RCREG = 0 
      GVAL= RCREG 
      RCREG = 0 
      RCREG = 0 
      BVAL= RCREG 
      ENDIF
      RCSTA.7 = 0 
      DMXFLAG=1
      return

    Back to the Drawing Board.
    DT

  4. #4
    Join Date
    Nov 2009
    Posts
    14


    Did you find this post helpful? Yes | No

    Red face thanks again

    "RCREG=DUMMY" was copy-paste from a sample code
    how can I set receive port with correct commands?
    and how sense break signal with FERR ?


    [QUOTE=Darrel Taylor;80570]Yes I can ...


    1. DEFINE OSC 20
      CLEAR
      ;_________________________Interrupt Context save locations]_________________

      wsave var byte $20 SYSTEM ' location for W if in bank0
      wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
      wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2
      ssave VAR BYTE BANK0 SYSTEM ' location for STATUS register
      psave VAR BYTE BANK0 SYSTEM ' location for PCLATH register
      ;----[ MIBAM Setup ]--------------------------------------------------------
      BAM_COUNT CON 3 ; How many BAM Pins are used?
      INCLUDE "MIBAM.pbp" ; Mirror Image BAM module

      BAM_FREQ CON 100
      DEFINE BAM_INFO 1
      ' MUST BE HERE DEFINE USART PARAMETER?

      KANAL CON 3 'my dmx adress, 3.byte red, 4. byte green, 5. byte blue
      BREAKTIME VAR BYTE
      DMXFLAG VAR BIT
      STARTBYTE VAR BYTE
      ADR VAR BYTE
      RVAL VAR BYTE
      GVAL VAR BYTE
      BVAL VAR BYTE
      YVAL VAR BYTE
      X VAR BYTE
      DUMMY VAR BYTE
      i VAR BYTE

      '***************** MIBAM ************************************************** *
      RED VAR BYTE
      GREEN VAR BYTE
      BLUE VAR BYTE

      ASM
      BAM_LIST macro ; Define PIN's to use for BAM
      BAM_PIN (PORTB,5, RED) ; and the associated Duty variables
      BAM_PIN (PORTB,6, GREEN)
      BAM_PIN (PORTB,7, BLUE)
      endm
      BAM_INIT BAM_LIST ; Initialize the Pins
      ENDASM
      '************************************************* ****************************
      TRISA=%00111001
      TRISB=%00000010

      ScopeSync VAR PORTB.2
      RXT VAR PORTB.1
      ERR VAR PORTB.4

      CMCON=7
      VRCON=0
      OPTION_REG.7 =0


      START:
      PAUSE 100
      DUMMY=0
      ADR = KANAL-1
      RED=50
      GREEN=100
      BLUE=180
      ERR=0
      GOTO LOOP
      '--------->>>>>>>>

      DMXBAK:
      i=i+1
      IF i> 200 THEN RETURN
      BREAKTIME =1MXFLAG = 0
      pulsin RXT,0,BREAKTIME ' I DONT KNOW HOW USE FERR THIS POINT

      if BREAKTIME = 0 then return
      if BREAKTIME < 30 then DMXBAK

      BRGH=1 ' 250000 BAUD ?
      SPBRG = 4 ' 250000 BAUD ?
      'AND HOW CAN I "DEFINE HSER_CLROERR 1" WITHOUT DEFINE?


      RCSTA.7 = 1
      RCSTA.6 = 0
      RCSTA.4 = 0
      RCSTA.4 = 1

      while RCIF = 0:wend
      STARTBYTE = RCREG
      if STARTBYTE = 0 then

      for x = 1 to ADR 'MY ADRESS 3, SKIP 2 BYTE
      while RCIF = 0:WEND
      dummy = RCREG
      next x

      DATAAL:
      RVAL= RCREG ' 3.BYTE, START OF MY DATA STREAM, RED VALUE
      GVAL= RCREG '4 BYTE.. GREEN VALUE
      BVAL= RCREG '5. BYTA BLUE VALUE
      ENDIF
      RCSTA.7 = 0
      DMXFLAG=1
      return

      LOOP:
      IF DMXFLAG=1 THEN
      RED= RVAL
      GREEN=GVAL
      BLUE=BVAL
      ENDIF
      GOSUB DMXBAK
      IF i>200 THEN
      ERR=0
      ELSE
      ERR=1
      ENDIF
      i=0
      GOTO LOOP

      END
    Last edited by talatsahim; - 9th November 2009 at 02:06. Reason: careless

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Sorry talatsahim,

    This little bit of code I made, has already turned into several commercial products.
    I have no problem with that, and everyone is free to do so if they wish.

    But, some things you just have to do on your own.
    If you can come up with the rest, that's great.

    Best regards,
    DT

  6. #6
    Join Date
    Nov 2009
    Posts
    14


    Did you find this post helpful? Yes | No

    Unhappy is 250000 baudrate code secret????

    thanks all



    Quote Originally Posted by Darrel Taylor View Post
    Sorry talatsahim,

    This little bit of code I made, has already turned into several commercial products.
    I have no problem with that, and everyone is free to do so if they wish.

    But, some things you just have to do on your own.
    If you can come up with the rest, that's great.

    Best regards,

Similar Threads

  1. decoding quadrature encoders
    By ice in forum mel PIC BASIC Pro
    Replies: 93
    Last Post: - 28th February 2017, 09:02
  2. Cordic trig assembly code for PIC18f
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 54
    Last Post: - 8th September 2015, 05:36
  3. AT/PS2 Keybord - PIC Interface?
    By Kamikaze47 in forum Code Examples
    Replies: 73
    Last Post: - 9th August 2009, 16:10
  4. MIBAM - (Mirror Imaged Bit Angle Modulation)
    By Darrel Taylor in forum Code Examples
    Replies: 2
    Last Post: - 15th February 2009, 16:02
  5. Bit Angle Modulation
    By BH_epuk in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th November 2008, 07:01

Members who have read this thread : 2

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