Reputation: 1
For TI Tiva Launchpad, I wrote a C code that takes two numbers from GPIO as inputs and then it adds the two numbers and outputs the result. Then, I connected an FPGA board to the Tiva launchpad and gave two numbers so that it multiplies them and outputs the result. I compute the time difference (propagation delay) between the output and the input with 4ns precision. Delay is in terms of microseconds so 4ns precision is good. However although I give the same input pattern at each test the resultant delay differs at each test. The code is something like that and surely accurately finding the results for all inputs.
int main(void) {
unsigned int z = 0;
unsigned char flag = 66, temp, select, num1, num2, res;
unsigned char num1Mem, num2Mem, num1MemOld, num2MemOld;
unsigned char resOld = 0;
unsigned int numOfOps = 0;
//Setup Clock, PORTC and RGB LEDs
SysCtlClockSet(SYSCTL_SYSDIV_8|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4); //Select input
GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7); //Inp 1 (num1)
GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); //Inp 2 (num2)
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); //LEDs
GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);//Out LS 4 bit
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);//Out MS 4 bit
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_4); //Push Buttons
GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
select = 0;
while(1){
num1 = (GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7) & 0xF0) >> 4;
num2 = (GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3) & 0x0F);
num1Mem = num1;
num2Mem = num2;
res = num1 * num2;
break;
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, res);
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7, res);
if(res == 0)
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x02);
else if(res < 16)
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x04);
else if(res > 15)
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x08);
}
return 0; }
For instance I change inputs from (0,0) to (3,5) and the resultant output changes from 0 to 15. I do that several times and each time the delay differs a little bit. I think all instructions that are executed at different instances must be perfectly the same, therefore the delay (i.e. number of cycles) must be the same but the actual case is different. Why? Is it possible or can I surely conclude that my delay results cannot be true?
Upvotes: 0
Views: 201
Reputation: 7057
It seems like you haven't done anything to synchronize the moment the inputs are changed with where the while loop is executing. If you change the inputs just before the while loop reads the inputs then the outputs will change relatively quickly. But if you change the inputs just after the while loop has read the inputs then the while loop has to finish the current iteration and loop back to the beginning and read the inputs again before you will see the output change. So the delay that you are measuring can vary by the amount of time it takes to execute the while loop once.
Upvotes: 1