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
Bookmarks