Is it possible to interpret non-standard serial data with PicBasic (sample attached) - Page 2


Closed Thread
Page 2 of 2 FirstFirst 12
Results 41 to 61 of 61
  1. #41
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Post Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    Name:  Untitled.jpg
Views: 524
Size:  50.3 KB
    as close as I can get . it has a glitch after the last bit sent

    Code:
    '****************************************************************
    '*  Name    : MODULATOR.BAS                                     *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2016 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 5/29/2016                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                        *
    '*          : 16F1825                                           *
    '****************************************************************
      #CONFIG
                 __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_ON  &  _PWRTE_ON  &  _MCLRE_ON  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_OFF & _LVP_OFF            
    #ENDCONFIG
     
    OSCCON=$70 
    DEFINE OSC 8
     
    '                       PIC 16F1825
     
    TRISA     = %011111    ' 
    trisc     = %001111  ; 
    ANSELA=0     
    ANSELC=0
    MDSRC=    %00000000
    MDCARH   =%01000100
    MDCARL   =%00000000
    X VAR byte
    darta   VAR byte[4] 
    TIMER1     VAR WORD EXT
    clear
    modout var latc.4
    darta.0[14]=1 
    darta.0[15]=1  
    t2con=6
    pr2=158
    CCPR1L =318>>2
    ccp1con=12
    MDCON.0 = 0
    modout =1
    Main_Loop:
    lata.5=1 ; cro trigger
    while !pir1.1 :wend
    modout=0
    pauseus 9900
    modout =1
    pir1.1=0
    while !pir1.1 :wend
    pir1.1=0
    while !pir1.1 :wend
    MDCON=    %11000001
    pir1.1=0
    while !pir1.1 :wend
    for x = 0 to 31  
    if  darta.0[x]  then
    MDCON.0 = 0
    pir1.1=0
    while !pir1.1 :wend
    pir1.1=0
    while !pir1.1 :wend
    MDCON.0 = 1
    pir1.1=0
    while !pir1.1 :wend
    else
    MDCON.0 = 1
    pir1.1=0
    while !pir1.1  :wend
    endif
    next 
    modout = 1
    MDCON = 0
    
    lata.5=0
    PAUSE 200 
    goto Main_Loop
    end
    Warning I'm not a teacher

  2. #42
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    Thanks!

    I guess, your code can run on 16F1829 ?

  3. #43
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    I guess, your code can run on 16F1829 ?
    should do they are the same except for a few extra pins
    Warning I'm not a teacher

  4. #44
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    well the dsp module is interesting but for this project perhaps its easier to do it the old way


    Code:
    '****************************************************************
    '*  Name    : MODULATOR.BAS                                     *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2016 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 5/29/2016                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                        *
    '*          : 16F1825                                           *
    '****************************************************************
      #CONFIG
                 __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_ON  &  _PWRTE_ON  &  _MCLRE_ON  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_ON & _LVP_OFF            
    #ENDCONFIG
     
    OSCCON=$70
    DEFINE OSC 32
    
    
    
    '                       PIC 16F1825
    
    
    
    TRISA     = %001111	   ' Make some pins Input 
    trisc     = %001111  ;Make some pins Input   
    ANSELA=0     
    ANSELC=0
    
    
    
    X VAR byte
    darta   VAR byte[4] 
    
    
        clear
        
        modout var latc.4
        darta.0[14]=1 
        darta.0[15]=1 
    
       
        modout =1
        lata.5=0    ;cro triger
    Main_Loop:
        lata.5=1
        modout=0
        pauseus 9900
        modout =1
        pauseus 1880
        for x = 0 to 30 
            modout =0
            if  darta.0[x]  then    
                pauseus 2000
            else
                pauseus 780 
            endif
            modout =1
            pauseus  635 
        next
        modout =1
        lata.5=0
        PAUSE 200 
    
    goto Main_Loop
    end
    Warning I'm not a teacher

  5. #45
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    Did you try code I posted a month ago, or looked at it to determine it won’t work?
    It’s used in an IR remote receiver for a game controller (so has to be reliable)
    to interpret exactly the same pulse coded signal, with the timings being the only difference.

  6. #46
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    No, I haven't used it, because protocol is different from IR protocol.

  7. #47
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    Just tried Henrik's code, it gives error on:

    LSB VAR BitArray.LowWord

    "bad variable size modifier .lowword"

  8. #48
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    Corrected the errors, to level of my knowledge. Code compiles now, but it does not do anything. Here it is:

    Code:
    ;----[16F1829 Hardware Configuration]-------------------------------------------
    #IF __PROCESSOR__ = "16LF1829"
      #DEFINE MCU_FOUND 1
    #CONFIG
    cfg1 = _FOSC_INTOSC           ; INTOSC oscillator: I/O function on CLKIN pin
    cfg1&= _WDTE_OFF              ; WDT disabled
    cfg1&= _PWRTE_OFF             ; PWRT disabled
    cfg1&= _MCLRE_OFF             ; MCLR/VPP pin function is digital input
    cfg1&= _CP_OFF                ; Program memory code protection is disabled
    cfg1&= _CPD_OFF               ; Data memory code protection is disabled
    cfg1&= _BOREN_OFF             ; Brown-out Reset disabled
    cfg1&= _CLKOUTEN_OFF          ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
    cfg1&= _IESO_ON               ; Internal/External Switchover mode is enabled
    cfg1&= _FCMEN_OFF             ; Fail-Safe Clock Monitor is disabled
      __CONFIG _CONFIG1, cfg1
    cfg2 = _WRT_OFF               ; Write protection off
    cfg2&= _PLLEN_OFF             ; 4x PLL disabled
    cfg2&= _STVREN_ON             ; Stack Overflow or Underflow will cause a Reset
    cfg2&= _BORV_19               ; Brown-out Reset Voltage (Vbor), low trip point selected.
    cfg2&= _LVP_OFF               ; High-voltage on MCLR/VPP must be used for programming
      __CONFIG _CONFIG2, cfg2
    #ENDCONFIG
    #ENDIF
    ;----[Verify Configs have been specified for Selected Processor]----------------
    ;       Note: Only include this routine once, after all #CONFIG blocks
    #IFNDEF MCU_FOUND
      #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
    #ENDIF
    DEFINE OSC 16
    include "modedefs.bas"
    ANSELA = %00000000 ' Set PORTA pins to digital I/O
    ANSELB = %00000000 ' Set PORTB pins to digital I/O
    ANSELC = %00000000 ' Set PORTC pins to digital I/O
    WPUB = %00000000   'DISABLE WEAK PULL UP
    TRISB=%11110000 'SET PORTB TO OUTPUT
    TRISA=%00000000 'SET PORTA TO OUTPUT
    TRISC=%00000000 'SET PORTC TO OUTPUT
    OSCCON = %01111111 'SET INTOSC TO 16MHZ
    ' Set LCD Data port
    DEFINE LCD_DREG PORTC
    ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_DBIT 4
    ' Set LCD Register Select port
    DEFINE LCD_RSREG PORTA
    ' Set LCD Register Select bit
    DEFINE LCD_RSBIT 5
    ' Set LCD Enable port
    DEFINE LCD_EREG PORTA
    ' Set LCD Enable bit
    DEFINE LCD_EBIT 4
    ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_BITS 4
    ' Set number of lines on LCD
    DEFINE LCD_LINES 2
    ' Set command delay time in us
    DEFINE LCD_COMMANDUS 1500
    ' Set data delay time in us
    DEFINE LCD_DATAUS 44
    LCDOUT $FE, $C0, "TEST"
    HighTime  VAR WORD
    LowTime   VAR WORD
    BitArray  VAR WORD [2]
    LSB       VAR BitArray.lowbyte
    MSB       VAR BitArray.Highbyte
    Signal var PORTB.6
    i var word
    WaitForStartBit:
      GOSUB MeasureLow
      IF (LowTime < 9500) OR (LowTime > 10500) THEN WaitForStartBit    ' 9.5-10.5ms qualifies
      GOSUB MeasureHigh
      IF (HighTime < 1500) OR (HighTime > 2500) THEN WaitForStartBit    ' 1.5-2.5ms qualifies
     
    NextLevel:
    For i = 0 to 31
      GOSUB MeasureLow
      IF (LowTime > 400) AND (LowTime < 800) THEN BitArray.0[i] = 1     ' 500-700us qualifies as 1
      IF (LowTime > 1700) AND (LowTime < 2320) THEN BitArray.0[i] = 0   ' 1800-2200us qualifies as 0
    NEXT
    LCDOUT $FE,$01, "HighWord", DEC MSB
    LCDOUT $FE,$C0, "LowWord", DEC LSB
    Pause 1000
    Goto WaitForStartBit
    MeasureLow:
      LowTime = 0
      While Signal = 1 : WEND         ' Wait for low level
      While Signal = 0                ' Measure low level
        LowTime = LowTime + 100       ' Resolution is 100us, change if needed
        PauseUS 92                    ' Tweak to calibrate, depends on actual loop time
      WEND
    RETURN
    MeasureHigh:
      HighTime = 0
      While Signal = 0 : WEND   ' Wait for low  
        While Signal = 1              ' Measure high level
        HighTime = HighTime + 1       ' Resolution is 100us, change if needed
        PauseUS 92                    ' Tweal to calibrate, depends on actual loop time
      WEND
    RETURN

  9. #49
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    Modified measurelow subroutine, to show the value of LowTime:

    Code:
    MeasureLow:
      LowTime = 0
      While Signal = 1 : WEND         ' Wait for low level
      While Signal = 0                ' Measure low level
        LowTime = LowTime + 100       ' Resolution is 100us, change if needed
        PauseUS 92                    ' Tweak to calibrate, depends on actual loop time
      WEND
      LCDOUT $FE, $C0, "T:",DEC lowtime, "  "
    RETURN
    It returns 600.

  10. #50
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    This is quite strange, because I'm using 16F1829, running at 16mhz. DEFINE OSC is correct, I've launched series of pulses with 1ms duration, and checked by scope - all correct.

  11. #51
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    Modified HighTime routine too:

    Code:
    MeasureHigh:
      HighTime = 0
      While Signal = 0 : WEND	  ' Wait for low  
        While Signal = 1              ' Measure high level
        HighTime = HighTime + 1       ' Resolution is 100us, change if needed
        PauseUS 92                    ' Tweal to calibrate, depends on actual loop time
      WEND
      LCDOUT $FE,$c0, "T2:",DEC hightime, "  "
    RETURN
    it returns 9.

    Feels like MCU is operating very slow?

  12. #52
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    what are you expecting to see ?
    how many times do you think 100uS will divide into a shade less than 1mS ?
    Warning I'm not a teacher

  13. #53
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    Where it should returned something like 9000, it returns 600, is not this strange?

  14. #54
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    I've launched series of pulses with 1ms duration, and checked by scope - all correct
    the code is expecting 10 mS pulse
    Warning I'm not a teacher

  15. #55
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    I goofed there. Since the BitArray actually consists of two WORDs and you want the least and most significant WORD of that array the declaration should read
    Code:
    LSB VAR BitArray[0]
    MSB VAR BitArray[1]
    Where it should returned something like 9000, it returns 600, is not this strange?
    What should return 9000?
    You've changed the MeasureHigh routine so it only adds 1 each time thru a loop that (ideally) takes 100us to execute. A pulse lasting for 10ms will (ideally) cause that loop to execute 100 times, you end up with 100 in (instead of 10000) in HighTime.

    /Henrik.

  16. #56
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    I modified henriks code an tested it with my simulation , works fine
    Code:
    '****************************************************************
    '*  Name    : deMODULATOR.BAS                                   *
    '*  Author  : richard's modified version of henriks             *
    '*  Notice  :  2016                                             *
    '*          : All Rights Reserved                               *
    '*  Date    : 10/10/2016                                         *
    '*  Version : 1.0                                               *
    '*  Notes   : decodes missing pulse encoded data stream A.5     *
    '*          : 16F1825                                           *
    '****************************************************************
      #CONFIG
                 __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_ON  &  _PWRTE_ON  &  _MCLRE_ON  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_ON & _LVP_OFF            
    #ENDCONFIG
     
    OSCCON=$70 
    DEFINE OSC 32
    
    
    
    '                       PIC 16F1825
    
    
    
        TRISA     = %111110	 ' Make somepins Input 
        trisc     = %111100  ;Make some pins Input   
        ANSELA=0     
        ANSELC=0
        led var latc.0      ;DEBUG
        led2 var latc.1      ;DEBUG
        demod var porta.5     ;demod in
        X VAR byte
        darta   VAR byte[4] 
        counter var word
        dm_state   VAR byte
        lata.0=1             ;DEBUG
        clear
        led=0
        DEFINE DEBUG_REG PORTA
        DEFINE DEBUG_BIT 0       
        DEFINE DEBUG_BAUD 9600
        DEFINE DEBUG_MODE 0     
        pause 2000
        Debug "Start",13 ,10  
        DEFINE PULSIN_MAX 9000
    
    Code:
    HighTime  VAR WORD
    LowTime   VAR WORD
    
    
    
    WaitForStartBit:
        GOSUB MeasureLow
        
        IF (LowTime < 9500) OR (LowTime > 11000) THEN WaitForStartBit    ' 9.5-10.5ms qualifies
        led2=1
        GOSUB MeasureHigh
        IF (HighTime < 1500) OR (HighTime > 2500) THEN WaitForStartBit    ' 1.5-2.5ms qualifies
        led2=0
        NextLevel:
        For x = 0 to 31
            GOSUB MeasureLow
            IF     LowTime < 1000   then
                darta .0[x] = 0 
            else
                darta .0[x] = 1  
            endif
        NEXT
        led=1
        Debug 13 ,10 ,bin8 darta[3],bin8 darta[2],bin8 darta[1],bin8 darta[0]    ;DEBUG
        Pause 1000
        led=0
        Goto WaitForStartBit
    
    MeasureLow:
      LowTime = 0
      While demod = 1 : WEND         ' Wait for low level
      While demod = 0                ' Measure low level
        LowTime = LowTime + 100       ' Resolution is 100us, change if needed
        PauseUS 92                    ' Tweak to calibrate, depends on actual loop time
      WEND
    RETURN
    
    MeasureHigh:
      HighTime = 0
      While demod = 0 : WEND	  ' Wait for low  
        While demod = 1              ' Measure high level
        HighTime = HighTime + 100       ' Resolution is 100us, change if needed
        PauseUS 92                    ' Tweal to calibrate, depends on actual loop time
      WEND
    RETURN
    Last edited by richard; - 10th October 2016 at 10:27. Reason: d key dodgy
    Warning I'm not a teacher

  17. #57
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    for comparison I came up with this , oddly it uses mode code space

    Code:
    '****************************************************************
    '*  Name    : deMODULATOR.BAS                                   *
    '*  Author  : richard                                           *
    '*  Notice  : Copyright (c) 2016                                *
    '*          : All Rights Reserved                               *
    '*  Date    : 5/29/2016                                         *
    '*  Version : 1.0                                               *
    '*  Notes   : decodes missing pulse encoded data stream A.5     *
    '*          : 16F1825                                           *
    '****************************************************************
      #CONFIG
                 __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_ON  &  _PWRTE_ON  &  _MCLRE_ON  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_ON & _LVP_OFF            
    #ENDCONFIG
     
    OSCCON=$70 
    DEFINE OSC 32
    
    
    
    '                       PIC 16F1825
    
    
    
        TRISA     = %111110	 ' Make somepins Input 
        trisc     = %111100  ;Make some pins Input   
        ANSELA=0     
        ANSELC=0
        led var latc.0      ;DEBUG
        led2 var latc.1      ;DEBUG
        demod var porta.5     ;demod in
        X VAR byte
        darta   VAR byte[4] 
        counter var word
        dm_state   VAR byte
        lata.0=1             ;DEBUG
        clear
        led=0
        DEFINE DEBUG_REG PORTA
        DEFINE DEBUG_BIT 0       
        DEFINE DEBUG_BAUD 9600
        DEFINE DEBUG_MODE 0     
        pause 2000
        Debug "Start",13 ,10  
        DEFINE PULSIN_MAX 9000
    
    main:
        select case dm_state
            case 0
                PULSIN demod, 0, counter
                if counter > 7800  then
                    dm_state=1
                    x=0
                endif
            case 1
                pir1.1=0 
                tmr2=0
                t2con=7
                while demod : wend
                if   pir1.1 | (tmr2 < 220)   then
                   dm_state=0
                else
                    dm_state=2
                    tmr2=0
                endif
            case 2
                while !demod : wend
                t2con=0
                if   pir1.1 then 
                 dm_state=0
                 led=1 
                endif 
                if tmr2 < 150    then 
                    darta.0[x]=0
                else
                    darta.0[x]=1
                endif
                tmr2=0
                x=x+1
                if x >31 then 
                    dm_state=3
                else
                    while demod : wend
                    t2con=7    
                endif
            case 3
                led2=1     ;DEBUG
            '    Debug 13 ,10 ,hex2 darta[3] ,hex2 darta[2],hex2 darta[1],hex2 darta[0]    ;DEBUG
                Debug 13 ,10 ,bin8 darta[3],bin8 darta[2],bin8 darta[1],bin8 darta[0]    ;DEBUG
                pause 200
                led2=0             ;DEBUG
                dm_state=0
        end select
    
    goto main
    Last edited by richard; - 10th October 2016 at 10:38. Reason: left a line out
    Warning I'm not a teacher

  18. #58
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    the 1ms was just test, I used it to check MCU speed, whenever OSCCON and DEFINE OSC were correct, later it was removed.

    I have Henrik's code running, I connect it to actual hardware, and width of large pulse, which should be 9000us, measured only 600 ?

  19. #59
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    I've copied all code from post #35, including timings.

    http://www.picbasic.co.uk/forum/show...165#post138165

  20. #60
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    I have Henrik's code running, I connect it to actual hardware, and width of large pulse, which should be 9000us, measured only 600 ?
    then you are doing something wrong ,plus you said in previous posts the pulse was 9900uS it makes a difference . whats correct ?
    your looking more scatterlogical than my exwife
    Warning I'm not a teacher

  21. #61
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach

    haha, no, I'm not blond
    Just I'm multi-tasking very hard.

    9000, 9900, it was just typo, exact timings are given on the previous page. I don't know what I'm doing wrong, since code is Henrik's. As I said, I verified MCU speed and OSC settings, and they are all correct. Pulse timings are also correct, verified using two different scopes. this is only what I can do.

Similar Threads

  1. Is there an ICSP pinout standard???
    By OldMarty in forum General
    Replies: 12
    Last Post: - 21st September 2016, 12:29
  2. Interpret to Picbasic Code ¿?!!
    By Denner in forum PBP3
    Replies: 3
    Last Post: - 9th June 2015, 18:00
  3. sample code for AT45DB642D in Picbasic Pro
    By itsssyam in forum General
    Replies: 0
    Last Post: - 10th March 2010, 06:01
  4. Max/232 Bootloader problems - Schematic attached...
    By rossfree in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 4th May 2007, 15:54
  5. Replies: 0
    Last Post: - 30th November 2004, 02:18

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