I have the very simplest circuit imaginable. A PIC16F877a with a 12MHz crystal and one LED connecting port RB0 via a 330Ohm resistor to ground.
I run the following programme:
#define _XTAL_FREQ 12000000
#include <xc.h>
// BEGIN CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
//END CONFIG
int main()
{
TRISB0 = 0; //RB0 as Output PIN
while(1)
{
RB0 = 1; // LED ON
__delay_ms(500); // 1 Second Delay
RB0 = 0; // LED OFF
__delay_ms(500); // 1 Second Delay
}
return 0;
}
and get the LED flash as per trace "500_500" attached. It looked to me that each alternate "on" was longer than the one before. So, I change the timings to:
500 on, 1000 off
and got trace "500_1000" attached. Though the "off" time has roughly doubled, as expected, there is now a completely mental pattern!
Then, for good measure, I made it:
2000 on, 500 off
and got trace "2000_500". I would have expected the "on" time to quadruple (it did) and the "off" time to be the same. However, the "off" time is less than half what I expected.
What on earth is happening? I realise that these delay times are not super accurate and probably not hugely consistent but this is outrageous!
Could you please point me in the right direction understanding.
Cheers.