Interrupt stops while in SERIN2 "WAIT" state


+ Reply to Thread
Results 1 to 18 of 18
  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french part)
    Posts
    731

    Default Interrupt stops while in SERIN2 "WAIT" state

    Hi,

    I'm trying to understand how to handle interrupts while WAITing for serial data to come in.

    My project is about controlling servos with incoming serial data but right now, I'd like to see how to overcome the WAIT modifier blocking the Interrupt (as stated in the manual).

    Currently, when I launch my program, it will "hang" at the SERIN2 command.

    If, for test purpose, I comment the SERIN2 command, the Interrupt will work fine.

    So how do I make the WAIT modifier not stopping the Interrupt?

    Here's my testing code:
    Code:
    ' ====== FUSES =====================================================================================
    ' PIC 16F690 Fuses (MPASM)
    @ __config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_HS_OSC &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF
    
    ' ====== REGISTERS =================================================================================
    '             76543210
    OPTION_REG = %10000000 ' PORT A&B Pull-Ups disabled (see WPUA & WPUB)
    OSCCON     = %00000000 ' External RC
    ANSEL      = %00000000 ' Analog inputs Channels 0 to 7
    ANSELH     = %00000000 ' Analog inputs Channels 8 to 11
    ADCON0     = %00000000 ' A/D Module is OFF
    CM1CON0    = %00000000 ' Comparator1 Module is OFF
    CM2CON0    = %00000000 ' Comparator2 Module is OFF
    INTCON     = %11000000 ' INTerrupts CONtrol: GIE is ON, PEIE is ON 
    T1CON      = %00110001 ' <5:4> prescaler 1:8, <1> Timer1 enabled
    PIE1       = %00000001 ' <0> Enable TMR1IF interrupt
    PORTA      = %00000000 ' Ports High/Low (0 to 5)
    TRISA      = %00000100 ' Set Input/Output (0 to 5)
    PORTB      = %00000000 ' Ports High/Low (4 to 7)
    TRISB      = %00000000 ' Set Input/Output (4 to 7)
    PORTC      = %00000000 ' Ports High/Low (0 to 7)
    TRISC      = %00000000 ' Set Input/Output (0 to 7)
    
    ' ====== DEFINES ===================================================================================
    DEFINE OSC 4
    DEFINE NO_CLRWDT 1 ' Don't waste cycles clearing WDT  
    DEFINE HSER_CLROERR 1 
    
    ' ====== VARIABLES =================================================================================
    Serial_In   var PORTA.2
    LED         VAR PORTB.6
    Serial_Data VAR BYTE
    BdRate      var BYTE
    
    ' ====== INITIALIZE ================================================================================
    INIT:
    BdRate    = 188 '4800 DTN
    
    ' ====== PROGRAM ===================================================================================
    ON INTERRUPT GOTO ISR
    MAIN:
        SERIN2 Serial_In,BdRate,[WAIT("TEST"),Serial_Data] ' Receive serial date from TX
        goto MAIN:
    END
    
    '======= ISR (Interrupt Service Routine) ===========================================================
    DISABLE
    ISR:
        TOGGLE LED ' just for test with the oscillo
        PIR1.0 = 0 ' clear TMR1IF overflow flag
        TMR1H = %11110110 : TMR1L = %00111011 ' 20ms preset value
    RESUME
    ENABLE
    Roger

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,120

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    Rodger, Why not use the added TIMEOUT directive and label. something like:

    SERIN2 Serial_In,BdRate,50,continue,[WAIT("TEST"),Serial_Data] ' Receive serial date from TX (waits for 50 milliseconds then continues to "continue" label)
    continue:
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french part)
    Posts
    731

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    Hi Dave,

    I need the interrupt to "happen" every 20ms since I finally want to control a servo motor.

    So I tried with a timeout value less than 20(ms) and it still prevents the interrupt to happen.

    I read some examples, in particular this one http://melabs.com/samples/LABX1-16F877A/servosx.htm but I don't exactly get how it works and what it does

    Apparently, it isn't that simple to control servos with serial incoming data to handle - at least to me
    Roger

  4. #4
    Join Date
    Sep 2009
    Posts
    677

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    Use hardware to receive data. So you don't need to wait for data.
    Enable EUSART interrupt, than shouldn't be so hard...

  5. #5
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french part)
    Posts
    731

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    Quote Originally Posted by pedja089 View Post
    ...So you don't need to wait for data...
    Yes, I saw this...but I don't get it

    Could you explain a little, please?
    Roger

  6. #6
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french part)
    Posts
    731

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    Hum.....

    I just found something on the PROTON forum where the contributor suggests to use two PICs to fulfill the job I want to do:
    - one PIC to listen and receive the serial data
    - ...and a second PIC to "do the job" (= controlling the servo) when all serial data is sorted out.

    http://www.protonbasic.co.uk/showthr...l=1#post467816

    I omitted to say earlier that my final project will transmit data over RF which implies the use of the WAIT modifier in the serial incoming communication. And I'm not talking about the transmitter (or "Remote") here in this thread; just the "receiver".

    Maybe I'm wrong but if this job, the receiver's one, could be done with only one PIC, I think it would be a much "cleaner" solution....or not?
    Roger

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    1,508

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    Currently, when I launch my program, it will "hang" at the SERIN2 command.

    its not hanging , serin2 is a software timed bit-banging routine by its very nature it blocks until completed . if interrupted if would generate corrupted results.

    if you use the eusart , serial reception can be handled by the hardware module enabling the chip to maintain servo function glitch free

    you may get some ideas here for multiple servos. not really sure that a 690 is up to the task , especially if you want to run comms in the background

    http://support.melabs.com/forum/hard...istance-needed
    This is more entertaining than Free to Air TV

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    1,508

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    Maybe I'm wrong but if this job, the receiver's one, could be done with only one PIC, I think it would be a much "cleaner" solution....or not?
    the answer here is how long is a piece of string [how much data ,how fast , how often ,how many servos , how tolerant , how important]

    comms with a rfm69,or nrf24l01 or rs232 as a background task to a rc servo pgm is not an especially difficult task
    This is more entertaining than Free to Air TV

  9. #9
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,158

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    DT's instant interrupts work during "WAIT" state.

    At least timer interrupts worked for me; I am not sure how others would act.

    Bur for SERIN2, once you start receiving data, you need to disable timer interrupt.
    Otherwise, you would get garbage.
    Last edited by sayzer; - 4th December 2018 at 07:05.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  10. #10
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french part)
    Posts
    731

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    Thanks Richard,
    how long is a piece of string [how much data ,how fast , how often ,how many servos , how tolerant , how important]
    Answers are:
    - how much data: 1 Byte
    - how fast: less than every 20ms
    - how often: every 20ms or slightly less
    - how many servos: 2 servos
    - how tolerant: must be 100% accurate and reliable
    - how important: very - by any transmitted data error, the radio controlled unit will stop working (for security).
    Roger

  11. #11
    Join Date
    May 2013
    Location
    australia
    Posts
    1,508

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    - how much data: 1 Byte
    how can you control 2 servos with 1 byte ?

    I would expect 2x words as a minimum data and possibly a one word crc for security or use packet radio like rfm69
    might you need other data /commands telemetry?

    how fast: less than every 20ms
    I mean bits per second data transfer speed , it will be a compromise between speed range reliability

    how often: every 20ms or slightly less
    why would update servo that fast ? can they respond that quickly?
    do you need to regulate servo speed ?

    how tolerant: must be 100% accurate and reliable
    -
    - how important: very - by any transmitted data error, the radio controlled unit will stop working (for security).
    over what range , do packets need to be acked/nacked , acceptable loss of signal time till panic sets in ?

    you need to think it through
    This is more entertaining than Free to Air TV

  12. #12
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french part)
    Posts
    731

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    how can you control 2 servos with 1 byte ?
    My servos will each need only 7 positions (or "steps" or "angles") including the center position (three to the left, three to the right and center). This means I can do this with 3 bits for each servo. I've still 2 bits left I want to use as a RF transmission Watchdog to make sure the remote is always sending datas.


    I mean bits per second data transfer speed
    Sorry.... The RF modules I use are capable of transmitting around 4800bps.


    why would update servo that fast ?
    As far as I know, you have to continuously send pulses, every 20ms, to the servo to have it working properly. If you try to send only 1 pulse to the servo, it will move a little bit but mostly it will stop far away from the position you want it to be.


    over what range ?
    Maximum 3 meters. I'm motorizing and RC-controlling a wagon, like this one.
    Name:  K640_chariot.JPG
Views: 37
Size:  34.0 KB
    Last edited by flotulopex; - 4th December 2018 at 12:52. Reason: typo
    Roger

  13. #13
    Join Date
    May 2013
    Location
    australia
    Posts
    1,508

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    As far as I know, you have to continuously send pulses, every 20ms, to the servo to have it working properly. If you try to send only 1 pules to the servo, it will move a little bit but mostly it will stop far away from the position you want it to be.
    yes that's how rc servos work , I mean how often do you need to send new change of position data



    Sorry.... The RF modules I use are capable of transmitting around 4800bps.
    the more info you provide the better the suggestions you are likely to get

    how do the rf modules communicate to the pic ?

    so far with those modest requirements one 690 chip should cope with the task at hand with time to spare

    a 10mS isr to run both servos sequentially would leave 7 out of every 10 mS absolutely free to monitor comms and 90% of the other 3mS conditionally free with clever use of timers [like in link I posted], 4800bps in hardware would be a breeze
    This is more entertaining than Free to Air TV

  14. #14
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french part)
    Posts
    731

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    how often do you need to send new change of position data ?
    I haven't been able to try up to now but I guess I will send data between 5 and 10 times per second.


    how do the rf modules communicate to the pic ?
    The modules have a Data_Out pin (RX) and Data_In pin (TX) accordingly connected to your PICs and "go" for serial comm. Oooops: Manchester encoding...I had to use it in a previous project; I forgot that. I'll need 2 Bytes instead of 1


    with clever use of timers, 4800bps in hardware would be a breeze
    Well, I wish it was. But I'm still stuck with the incoming serial data I need to "sort". It is for sure a very simple project for you guys doing this every day.


    Now I feel I'm going to give it a try, on the receiver's side, with one PIC receiving serial data and a second one polling this data and controlling the servos avoiding (at least I hope so) any timing issue.
    Last edited by flotulopex; - 4th December 2018 at 13:38. Reason: missing word
    Roger

  15. #15
    Join Date
    May 2013
    Location
    australia
    Posts
    1,508

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    The modules have a Data_Out pin (RX) and Data_In pin (TX)
    433mhz am regen receiver?
    if I have it correctly those sort of modules are difficult to work with ,the rx pin needs virtually continuous monitoring to detect start of transmission and constant monitoring to decode data.
    I fed all mine into the rubbish. things like rfm69,nrf24l01 are better ,easier to use and cheap
    This is more entertaining than Free to Air TV

  16. #16
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french part)
    Posts
    731

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    433mhz am regen receiver? if I have it correctly those sort of modules are difficult to work with
    You're absolutely right. First time I used them, it was a nightmare and I couldn't make them work properly until I found Melanie's post explaining Manchester encoding (http://www.picbasic.co.uk/forum/show...&p=666#post666) in 2004.

    I've been using AUREL RF modules in previous projects but last time I was looking to buy some, couldn't find them (http://www.picbasic.co.uk/forum/show...587#post137587).

    But since I need only one-way comm this time, I'll use the modules I have in my drawer
    Name:  2018-12-04 14_25_52-G NIiceRF 50sets Wireless RF Module ASK RF Module Kit STX882+SRX882 433MHz T.jpg
Views: 36
Size:  76.3 KB
    Last edited by flotulopex; - 4th December 2018 at 14:32.
    Roger

  17. #17
    Join Date
    May 2013
    Location
    australia
    Posts
    1,508

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    in order to preserve sanity I would not attempt incorporating that type or receiver into a servo controller loop.
    This is more entertaining than Free to Air TV

  18. #18
    Join Date
    May 2013
    Location
    australia
    Posts
    1,508

    Default Re: Interrupt stops while in SERIN2 "WAIT" state

    here's an idea , send an analog data stream where the servo timing sync is followed by pulses representing the servo's pulse widths
    Attached Images Attached Images  
    This is more entertaining than Free to Air TV

Similar Threads

  1. Replies: 0
    Last Post: - 14th November 2013, 04:32
  2. Replies: 3
    Last Post: - 15th October 2012, 08:06
  3. Replies: 0
    Last Post: - 18th September 2012, 14:34
  4. SERIN2 - "Timeout" hangs if > 255
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 11th July 2010, 14:13
  5. Best way to determin "pin" state with +13.8 V
    By JDM160 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th March 2005, 05:54

Members who have read this thread : 16

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