HserIn and Interrupts


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2005
    Posts
    74

    Question HserIn and Interrupts

    I'm using Darrell Taylor's code "Elapsed.bas" (Thanks Darrell!!!)
    It's an interrupt that fires every so often and increments a seconds counter.

    Basically, I've written a communications watchdog. If I do not get a good RX string in on HserIn in 300 seconds I cycle a relay causing the Host to reboot.

    It's been working really good for extended times, until I slowed down the Serial portion. I'm wondering if the interrupts are causing me an issue.

    My Specifics...
    16F88 @ 20 MHZ
    Using the USART and HSerin
    9600 BPS

    @ DEVICE pic16F88, HS_OSC
    @ DEVICE pic16F88, WDT_ON
    @ DEVICE pic16F88, PWRT_ON

    DEFINE LOADER_USED 1
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50


    Here are my serial defines.
    DEFINE HSER_CLROERR 1
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h '20h for slow bit rate and 24h for high speed
    'I tried 20 and 24h here....

    DEFINE HSER_BAUD 9600
    DEFINE OSC 20 'Set Clock Speed for 20 mhz crystal

    TRISA = %11111111 'Set PORTA to all inputs

    OPTION_REG.7 = 1 'Pullups OFF
    CMCON = %00000111 'Disable analog comparators
    ANSEL = %00001111 'Set PORTA.2 .3 to analog input, others to digital
    ADCON0 = %00000001 'Configure and turn on A/D Module.
    ADCON1 = $82 'configure VDD as Vref, and analog channels



    Basics,
    A PC sends a serial string to the Pic and awaits for a response. If I set the PC up to send the request every 100ms to 1000ms the pic responds fine with no errors. If I slow the PC down to send a request every 2000ms or more, I start having random issues where the Pic doesn't always send back a reply. (Timesout)

    I can't paste all the code here, but I will paste the main portion of the loop which is pretty simple....


    GetAnalog:
    ADCIN 0,AdcVal0
    ADCIN 1,ADCVal1
    ADCIN 2,AdcVal2
    ADCIN 3,ADCVal3
    Return





    Main Loop - Waits on incoming traffic on serial port
    Receive:
    GOSUB Getanalog //Grab 4 analog readings

    'Clear the buffers before anything
    For i = 0 to 7
    BufRx[i] = 0
    BufTX[i] = 0
    Next i

    NBR = 8 'Expect 8 bytes
    HSerIn 50,Receive,[STR BufRX\NBR] 'Serial In, Wait for 8 Bytes

    'I do some really quick stuff right here like check the string
    'I actually fill the BufTx with Data (Analogs),
    ' set the num of bytes NBR = xx and then send it back

    For i = 0 to NBR 'Send all the bytes back....
    HSerout [BufTX[i]]
    Next i

    Goto Receive

  2. #2
    Join Date
    Oct 2005
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    I did a little tweaking and I will test and see if it's better or not. The Interrupts don't seem to make much difference.

    DEFINE HSER_TXSTA 24h
    DEFINE HSER_BAUD 9615 <- This is weird but I'll try it

    HSerIn Timeout reduced from 50ms to 10ms

  3. #3
    Join Date
    Oct 2005
    Posts
    74


    Did you find this post helpful? Yes | No

    Default Fixed

    I'm pretty sure a Found it. I had a floating input pin. This input puts the program into a different subroutine instead of sending data back. Since I pulled it up, it appears to be back to working good again.

    Time will tell.

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


    Did you find this post helpful? Yes | No

    Default

    Sure it could be the problem!

    I'll suggest you to use interrupt for your serial comm. Once in the ISR, do your HSERIN stuff and get out of there. The timeout may work, or not. At least the Usart have a handy 2Bytes buffer...
    Steve

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

  5. #5
    Join Date
    Oct 2005
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    Mister-E, Thanks for the response.

    Yes, it's been working flawless since then. My development board as pull ups and downs configurable by a jumper and somehow I changed it (removed the jumper) and caused all this greif.

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


    Did you find this post helpful? Yes | No

    Default

    Good!

    wich development board? I guess it's MikroElektronika? If so they're really nice for the price and included hardware... the only problem.. the on-board programmer.. sometimes it fails, the RS-232.. there's no free DTR line for the bootloader... but an on-board reset, there's no easy way to change/disable the on-board crystal capacitors.

    EasyPIC 4 KIT:
    Pricing vs what you get 10/10
    Documentation 9/10
    Assembly 8/10
    Electronic design 7/10

    Overall 8/10.

    Good stuff from the 10F to 18Fs, from 8 dip pins to 40Dip pins. By far, the best PIC development board on the market.
    Last edited by mister_e; - 4th December 2006 at 23:01.
    Steve

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

  7. #7
    Join Date
    Oct 2005
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    Good!
    wich development board? I guess it's MikroElektronika? .
    Yep, EasyPic3. Overall I love it. It has a few flukes, but your right, it's one of the best values around. They most likely sell that board for cost in order to get the name / compiler out there for folks to try.

    Right now, I'm using a ZTT-20mhz with the built in caps, and the onboard caps are still there as well but so far it hasn't caused any issues.

    While we're talking about it, I really like using the 3 pin ZTT's but I heard going with a crystal and seperate caps is much more reliable as far as wide temperature swings. I honestly figured the 1 package with the caps encapsulated would be better for less drift due to wide temp. swings.

    Any experience here, which do you prefer?

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


    Did you find this post helpful? Yes | No

    Default

    You're right. If it's really timing critical i'll use crystal. unless, i'll use resonator. Resonator are good so far, so don't worry.

    I heard that some resonator may have a shorter lifetime... i can't confirm, i never replaced any since i use them.
    Steve

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

Similar Threads

  1. Hserin with Instant Interrupts.
    By ronjodu in forum Serial
    Replies: 17
    Last Post: - 30th December 2014, 20:17
  2. DT interrupts and Pause
    By Luckyborg in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 18th February 2009, 22:47
  3. Instant Interrupts and HSERIN
    By Rob in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 31st January 2009, 05:13
  4. TMR0 interrupt and HSERIN
    By boban in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd September 2008, 11:48
  5. Usbin and hserin
    By mpardinho in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 27th October 2007, 15:26

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