Hi guys,
Was exploring PIC18F controllers timing specification. Unable to understand a couple of things in time generation sequence for based on the same.
Breadboard arrangement:
MUC:PIC18f46k22
Fosc = (XTAL) = 16MHz (with 22pf decoupling)
Fcpu = Fosc/4 = 4Mhz,
Tcpu = 1/4000000 = 0.25us = 250ns
Based on my observations I have noticed the following (pls. refer to attached images):
Case 1:
while(1){
LATDbits.LATD2 = 0; //turn off led exec#0
LATDbits.LATD2 = 1; //turn on led exec#1
LATDbits.LATD2 = 0; //turn off led exec#2
LATDbits.LATD2 = 1; //turn on led exec#3
}
Observations:
Noted for exec#0 and exec#2 Time period = 500ns
After which the pin stays high for exec#3 Time period 750ns and low for exec#0 time period 240ns.
In my opinion every 8-bit instruction is getting executed every 250ns in this case, the rest of the period where the signal is high the MCU is still awaiting instructions to fullfill 4MIPS.
https://drive.google.com/open?id=0B1ujJMA_1UnySUdKMi1JeVhMUWM
Case2: (Using ternary operator)
while(1){
LATDbits.LATD2 = LATDbits.LATD2 ? 0:1;
}
Observations:
from case2 ON-OFF time period = 3.3us
https://drive.google.com/open?id=0B1ujJMA_1UnydzhQVzRwMTZONWc
Case3:
while(1){
LATDbits.LATD2 = ~ LATDbits.LATD2; //toggle bit
}
Observations:
from case3 ON-OFF time period = 3.9us
https://drive.google.com/open?id=0B1ujJMA_1UnyaXEtX3BLZDNKLTQ
Case4: (Using macros)
while(1)
{
LED_OFF();
LED_ON();
LED_OFF();
LED_ON();
}
Observations:
Time period = 500ns
same as case1.
https://drive.google.com/open?id=0B1ujJMA_1UnySUdKMi1JeVhMUWM
Please correct me if i am wrong..