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


Closed Thread
Results 1 to 40 of 61

Hybrid View

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

  2. #2
    Join Date
    Feb 2013
    Posts
    1,124


    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.

  3. #3
    Join Date
    Feb 2013
    Posts
    1,124


    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"

  4. #4
    Join Date
    Feb 2013
    Posts
    1,124


    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

  5. #5
    Join Date
    Feb 2013
    Posts
    1,124


    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.

  6. #6
    Join Date
    Feb 2013
    Posts
    1,124


    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.

  7. #7
    Join Date
    Feb 2013
    Posts
    1,124


    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?

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,644


    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

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