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
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

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

    Here's one idea:
    Code:
    HighTime  VAR WORD
    LowTime   VAR WORD
    BitArray  VAR WORD [2]
    LSB       VAR BitArray.LowWord
    MSB       VAR BitArrat.HighWord
    
    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 LCB
    
    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
      WhileSignal = 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
    I can't compile this let alone test it but it serves to show the genereal idea of a software only solution.

  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

    Thanks, will give it a try tomorrow.

    My oscilloscope can record in .csv format, is it possible in some emulator to "play back" this recording, and feed it to virtual chip? So I can test and debug without using original hardware, which generates these pulses.

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

    the waveform is simple to simulate like this is you have a chip with a dsp module.
    note the timings are estimated since the curious one's info is lacking most of the meaningful detail

    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     = %111111    ' Make all pins Input 
    trisc     = %101111  ;Make all pins Input   
    ANSELA=0     
    ANSELC=0
    MDSRC=    %00000000
    MDCARH   =%11000100
    MDCARL   =%00000000
    X VAR byte
    darta   VAR byte[4] 
    TIMER1     VAR WORD EXT
    clear
    modout var latc.4
    darta.0[15]=1 
    hpwm 1,128,1600
    MDCON.0 = 0
    modout =0
    Main_Loop:
    modout=1
    pauseus 8000
    modout =0
    while tmr2 :wend
    MDCON=    %11000000
    for x = 0 to 31
    while tmr2 :wend
    MDCON.0 = !  darta.0[x]
    next  
    modout=1
    MDCON=    0
    pauseus 600
    modout = 0
    PAUSE 200 
    goto Main_Loop
    end
    Last edited by richard; - 7th October 2016 at 04:50.
    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