how to control the incoming data?


+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2009
    Posts
    15

    Default how to control the incoming data?

    How can I control when data is incoming? I have a pcb with Max232 and it sends/receive data, this is a portion of the code:

    Code:
    'Waits 200ms until 129 is received, then store next byte in I, if timeout jump to M2
               SERIN SERIAL_IN,BPS,200,M2,[129],I
    This works ok but I loose 200ms waiting for data and that PCB needs to control more things, so it becomes slooooooooow. If I change it to 100ms it loose commands, if I use 500ms it works perfect, but then the rest of the code has no time to do its job.

    I can't use interrupts because the PCB uses PORTB.7 for SERIAL_IN.

    I've tried a "stupid way" (and obviosly it does not works):

    Code:
         if SERIAL_IN=0 then       'something is changin in the RX PORT
    'Waits 200ms until 129 is received, then store next byte in I, if timeout jump to M2
               SERIN SERIAL_IN,BPS,200,M2,[129],I
        endif
    but the data received usually is corrupted. Then I've tried to repeat the commands from the PC (129-22-129-22) but also does not works ok.

    Any idea of how can I make this works better?

    Regards

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,964

    Default

    Yes there is an excellent way and is called DT-Instant Interrupts!

    Ioannis

  3. #3
    Join Date
    Apr 2009
    Posts
    15

    Default

    Quote Originally Posted by Ioannis View Post
    Yes there is an excellent way and is called DT-Instant Interrupts!

    Ioannis
    But that way is intended to use the INT port. I'm using a PCB with 16F628A, INT=RB0, and the port I must observe is RB7, so I can not see how to use Darrel's way

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,964

    Default

    It seems you do not read, or not read carefully.

    Your PIC has USART.

    USART has Interrupt that has nothing to do with PORTB.0 INT interrupt.

    Darrels Interrupts cover all possible Interrupt sources of a PIC. You just have to enable th appropriate interrupt.

    Example follows. On a terminal press key "1" to see the effect. (Not tested...)

    Code:
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
    	INT_Handler   RX_INT,	 _Get_char,	 PBP,  yes
    endm
    INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::       
    
    @ INT_ENABLE  RX_INT	   ; enable UART RX interrupt
    
    
    loop:
    if mybyte="1" then
        hserout "I got it!"
        mybyte=0
    endif
    goto loop
    
    
    '---[USART RX Interrupt handler]----------------------------------------------------
    Get_char:
    	hserin 100,noreceived,[mybyte]	'Get byte
    noreceived:                         'or if timeout return
    @ INT_RETURN
    Ioannis

    P.S. As a homework do set the USART parameters with DEFINE's to 9600

  5. #5
    Join Date
    Apr 2009
    Posts
    15

    Default

    Quote Originally Posted by Ioannis View Post
    It seems you do not read, or not read carefully.

    Your PIC has USART.

    USART has Interrupt that has nothing to do with PORTB.0 INT interrupt.

    Darrels Interrupts cover all possible Interrupt sources of a PIC. You just have to enable th appropriate interrupt.
    I'm not english spoken, but USART is on RB.1 (RX), I can not use that PIN, just RB.6 for incoming data, and RB.6 as far as I know, can not be managed with interrupts.

    It's a finished PCB and I'm trying to add some features, but can't change the hardware, otherwise this problem will be very easy to solve, still don't know hoy can DT-Interrupts can be applied here

    Regards

  6. #6
    Join Date
    Feb 2009
    Location
    Southern California
    Posts
    86

    Cool

    i don' know if your application will allow for it, but you can try adding polling throughout your code to have smaller wait times during the check and look for and use the wait command in serin2

    Code:
    main:
    ... normal stuff
    gosub get_data
    ... more normal stuff
    gosub get_data
    ...
     more normal stuff
    goto main
    
    get_data:
    
    serin2 Serial_IN, 84, 50, nodata, [wait (129), x]
    nodata:
    return
    If you can adjust your transmitting device add a bunch of dummy spaces before the transmission so if you miss 1 or 2 no big deal, you weren't going to use them anyway. I''ve used something similar in the past.

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,964

    Default

    If it is one off then I suggest to re-design your PCB. You won't have satisfactory results whatever you do besides the Interrupts generated by the USART.

    There may be plenty of ideas, but will not respond fast enough.

    Ioannis

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    RB6 can use Interrupt on change, so yes you can use it.

    It show one problem though, it will detect the Start-Bit... so there's big chance that SERIN/DEBUGIN/SERIN2 will not work as expected. But you could roll your own serial routine which will ignore the start-bit. This will work or not depending of your Baudrate and if you go on a ASM or PBP interrupt + home made serial routine. When using Darrel's instant interrupt with PBP type, it need some time to save/restore PBP systems var. Have a look at the following
    http://darreltaylor.com/DT_INTS-14/kudos.html

    If you create your own PC software, OR if you create your own transmitter with another PIC... then it open a few other possibilities.

    But yeah, when at all possible, I prefer the USART interrupt as well.
    Last edited by mister_e; - 29th April 2009 at 18:09.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Using Nokia LCD
    By BobP in forum mel PIC BASIC Pro
    Replies: 300
    Last Post: - 3rd May 2018, 04:47
  2. Nokia 3310 display text
    By chai98a in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 26th August 2007, 03:39
  3. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 02:21
  4. LCD + bar graph
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 5th October 2005, 14:50
  5. Sinus calculating !
    By Don Mario in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 28th November 2004, 23:56

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts