PDA

View Full Version : HserIn and Interrupts



rwskinner
- 4th December 2006, 06:20
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

rwskinner
- 4th December 2006, 16:37
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

rwskinner
- 4th December 2006, 17:25
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.

mister_e
- 4th December 2006, 21:23
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... ;)

rwskinner
- 4th December 2006, 22:31
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.

mister_e
- 4th December 2006, 22:53
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.

rwskinner
- 5th December 2006, 00:29
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?

mister_e
- 5th December 2006, 07:15
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.