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

    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.

  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

    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?

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

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

    Does your hardware have the LCD that is in your code?

  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

    That should get the 32 bits straight into a four byte array.

    Code:
    '
    main:
    @ clrwdt
    '
    if portc.4 = 1 then	‘ count initial pulse duration
    leadcnt = leadcnt + 1
    else
    leadcnt = 0
    endif
    '
    '
    if leadcnt > expectedduration then' qualify initial pulse duration
    burst:			' sync to initial pulse falling edge
    if portc.4 = 1 then
    @ clrwdt
    goto burst
    endif
    '
    for rotcnta = 0 to 3	' shift data into 32 bit buffer
    databuffer = 0
    for rotcntb = 0 to 7	‘ shift data to each byte
    databuffer.bit0 = portc.4
    databuffer = databuffer << 1
    dataarray[rotcnta] = databuffer
    pauseus peaktopeakduration
    next rotcntb
    next rotcnta
    ‘
    leadcnt = 0
    endif
    '
    goto main
    ‘
    Last edited by Art; - 9th July 2016 at 15:34.

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

    surely a candidate for timer1 and gate control
    Warning I'm not a teacher

  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

    Currently I have LCD connected, for debugging purposes, but in final device, I will have no LCD.

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

    So this is how initial things should work, as I see it:

    1. We sent interrupt on rising edge of PORTC.4
    2. As PORTC.4 gets high, timer is started, and counts to predefined value (width of 1st pulse)
    3. While timer is running, PORTC.4 is still being continuously checked, to determine, whenever it is still high. It should be high while timer is counting, if it gets low, while timer is on, this means, this is not proper pulse, so we should reset and start everything over.
    4. If timer counting ended, and PORTC.4 was high all that time, this means that sync pulse was captured correctly, and we're ready for the next step.

    This appears quite simple in words, but all Greek for me, in code , so far, my practical experience with timers and pwm is light dimming, and playing polyphonic tunes via it

  9. #9
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

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

    Or Timer1 and Interrupt on Change or even better Interrupt on PortB.0 and use of Option_reg.6 to select which edge is expected to arrive and trigger the interrupt.

    Needs a bit of work in the interrupt routine...

    Ioannis

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