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

    Code that works - It differentiates "0" from any other command:

    Code:
    UIDEDA:
    
    if pulsi=0 then
    FOR N=0 TO 300     'main loop duration
    IF PULSI=0 THEN
    A=A+c                                 'count positive edges
    c=0   'stop increasing  1 after first loop
    d=1    'set increase for 0
    ELSE
    B=B+d         'count 0 volt
    d=0     'stop increasing 0 after first loop
    c=1      'set increase for 1
    ENDIF
    NEXT
    IF A<>0 AND B<>0 THEN
    lcdout $FE,2, "A=",#A, "    "
    lcdout $FE,$C0,"B=",#B, "    "
    ENDIF
    if a=7 and b=8 then high natura    'on
    if a=6 and b=7 then low natura   'off
    A=0
    B=0
    endif
    GOTO UIDEDA

  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

    Now I want to ad an array, where, when "1" occurs, value of N variable will be stored, which later can be counted, and position of "1" s and "0" -s detected.

  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

    Going totally crazy, can't figure out what to do and how

  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

    Logically, code should look like this:

    WAIT FOR LOW LEVEL AND MEASURE IT'S DURATION
    IF LOW LEVEL LENGTH=10MS THEN MEASURE HIGH LEVEL DURATION AFTER IT
    IF HIGH LEVEL DURATION WAS 2MS, THEN GO TO NEXT STEP, ELSE, LOOP THIS CYCLE AGAIN
    NEXT LEVEL:
    CONSIDER 600US LOW LEVEL AS 1, AND 2MS LOW LEVEL AS 0, WRITE THEM SEQUENTALY TO 32 BIT ARRAY, UNTIL 32 BITS WRITTEN
    EXTRACT MSB AND LSB FROM ARRAY
    CONVERT TO WORD

  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

    Or, more "programmer" approach. Assuming "A" is the input pin:

    START COUNTING
    A=0, B=0
    WHILE A=1, B=B+1
    WHILE A=0, C=C+1
    IF B=500 AND C=100 THEN CONTINUE, ELSE, START OVER
    B=0 C=0
    FOR N=1 TO 32
    WHILE A=1, B=B+1
    WHILE A=0, C=C+1
    IF B=50 AND C=50 THEN CONTENTS[N]=1
    IF B=50 AND C=150 THEN CONTENTS[N]=0
    A=0, B=0
    NEXT N


    Name:  HUMANBASIC.jpg
Views: 2534
Size:  31.0 KB

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

  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

    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.

  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

    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