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

    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.

  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

    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?

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


    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

  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

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

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,632


    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

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    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.

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,632


    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

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