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 2011
    Posts
    453


    Did you find this post helpful? Yes | No

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

    IF PORTC.4=1
    or
    IF PORTC.4=0

    makes corresponding pin high or low?
    I highly doubt that. I don't know how you're testing it, but if that's the case things are seriously broken.

    You likely have some other issue.

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

    The IF statement per se should not and I'm pretty sure does not twiddle the pin but if what you you're doing is somehing like...
    Code:
    If PortC.4 = 0 THEN
       PortC.1 = 1
    ENDIF
    ...and there happens to be analog functions on the pins which you haven't disabled then the actual state of PortC.4 isn't read correctly and you're getting into the classic RMW issue where the "invalid" state of PortC.4 is being written back to PortC.4 when the write operation to PortC.1 occurs but without seeing the rest of the code it's hard to say for sure.

    /Henrik.

  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

    Here is the complete code:

    Code:
    Include "modedefs.bas"  ' Include serial modes
       TRISA = %11111111       ' Set PORTA to all input
           TRISC = %00000000	    ' Sets all PortB pins to output
       ADCON1 = %10000101      ' Set PORTA analog and right justify result
       ADCON0=%00000000
       low portc.4
       low portc.5
       
    X   VAR PORTC.4 
    
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 4 
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 1500
    DEFINE LCD_DATAUS 44
    DEFINE OSC 4
    
    lcdout "test 2"
    PAUSE 500
    
    LABEL VAR WORD
    DROEBITI VAR WORD
    
    
    taki:
    if portc.4=0 then
    COUNT PORTC.4, 60, LABEL
    endif
    if label=0 then
    goto taki
    endif
    LCDOUT $FE,$c0, DEC(LABEL), "          "
    GOTO TAKI
    I have source of signal (chip with name grinded off, but holtek logo is recognizable), which is connected directly to PORTC.4. Also, scope is connected to same pin.

    As long as I introduce the statement "if portc.4=0 then"
    If it is "=0" then pin is sunk to ground, so no pulses can be detected, and nothing can be seen on scope. If it is "=1", then pin gets driven high, and no pulses can be seen with scope or read too.

    Chip is 16F870.

  4. #4
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

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

    Code:
     TRISA = %11111111       ' Set PORTA to all input
       TRISC = %00000000	    ' Sets all PortB pins to output
       ADCON1 = %10000101      ' Set PORTA analog and right justify result
       ADCON0=%00000000
       low portc.4
       low portc.5
    Is there something strange here?
    Last edited by pedja089; - 8th July 2016 at 21:42.

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

    Easy! It’s giving you a wider pulse duration at the start to qualify the incoming data.
    From there you only need to sample 32 times at the correct interval.
    So look for that, then read it in with a 32 step loop.

    Code:
    bitcode var byte[32]
    count var byte
    pulseduration var byte
    
    pulseduration = time from peak to peak
    
    for count = 0 to 31
    bitcode[count] = inputpin
    pause pulseduration
    next count
    Of course, better ways than reading into a 32 byte array, but quickest.

  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

    You're omitting an important thing - MCU has own clock, wastes different time on program execution, but incoming data is sent async, so it can't wait for MCU to become ready, so my guess, how it all should work, is as follows:

    As pulse arrives, we start recording it as fast as possible, after pulse sequence finished, we just count numbers of 1's and 0's recorded, and based on that, decide what to do with decoded data. Considering total sequence duration and speed, I guess, external sram or eeprom might be needed?

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

    That depends. You didn’t display the duration.
    If it’s several uS duration pulses, the falling edge of the first longer pulse is the place to mark time,
    then waste half a pulse duration before the for-next loop. If you can roughly synchronise from the first pulse (which is what it’s for),
    it takes time for the two clocks to drift apart.

    If you were to sample bits as fast as you can, you’d still want to do that from the falling edge of the first pulse.

  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

    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

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

    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 ?

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

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

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

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

    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

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

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