Thanks for your reply.
1. Changing to portb =128 doesn't have an impact on anything.
2. I don't seem to have the file "Device Reference". I'm running version 5.0.0.5 compiler version 3.0.7.4. I can't find that file on the disk either.
3. When I change to "define OSC 8" instead of "OSC 20" then the timing works correctly. This would imply the pic is running on its internal 8MHz clock and is ignoring the OSCCON's setting to use the external crystal. It's as if the configuration "fuses" are just that, fuses. Once set they can't be reset. Or maybe the pic is defective.
4. I tried a new pic but it gave the same results.
5. MPLAB shows the correct configuration bits. HS oscillator is indeed selected.
6. I changed OSCCON to 01101110 to set the internal oscillator to 4 MHz. It did indeed change the clock to 4 MHz as observed on the scope. Bit 0 of OSCCON is supposed to select the external clock source but it is not.
7. On the off chance bit 0 of OSCCON should be a 1 to select the external crystal I changed it to a 1 but the result is the same. It's as if that bit is being ignored.
This is what I have at the beginning of the code:
#CONFIG
__config _CONFIG1, _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOR_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF & _DEBUG_OFF
__config _CONFIG2, _BOR40V & _WRT_OFF
#ENDCONFIG
OSCCON = %01101110 'runs at 20 MHz set in configuration bits
DEFINE OSC 20 '20 MHz CLOCK FREQUENCY
define HSER_RCSTA 90h 'enable the serial port receiver
define HSER_TXSTA 24h 'set up the serial port, enable transmit for fast clock. TXSTA 00100100
define HSER_BAUD 19200 'select the baud rate, run fast
define HSER_CLROERR 1 'automatically clear the buffer overrun error
define ADC_BITS 10 '10 bits
define ADC_SAMPLEUS 50 '50usec sampling time
DEFINE ADC_CLOCK 3 'set clock source to RC
volts var word 'power supply volts
amps var word 'power supply amps
tempr var word 'temperature
ticks var word 'radiation ticks, made up of timer 1's counter bytes
command var byte 'the command byte
action var byte 'the action byte, what to do
stattus var byte 'contains the power supply status information
dungate var byte 'status flag to indicate the count has been recorded & counter cleared
GATE var portb.4 'label for the gate input
TRIG var portc.0 'label for the ticks input
TEMPRP VAR portc.1 'temperature pulsewidth input
ONOFF var portc.3 'dc/dc on/off bit. On = 1
beat var portb.7 'heartbeat monitor
ADCON0 = %11000000 'set ADC clock to RC
ADCON1 = %10000000 'right justify the result in ARESH:ADRESL registers. Vref=Vdd
ANSEL = %00000011 'set AN0 and AN1 as analog
ANSELH = %00000000 'set AN8 and higher to digital
TRISA = %11111111 'set up port A as all inputs
TRISB = %01111111 'set up port B as all inputs except for RB7 which is a heartbeat monitor output
TRISC = %10110111 'set up port C where 1 = input
Bookmarks