Hello,
The controller should check a digital signal input (GPIO40) at least 40 microseconds after a digital signal output (GPIO44) is set.
During run time most of the time it works fine, that is, GPIO40 is tested 40 microseconds after GPIO44 was set. However, there was one time where GPIO40 was tested only about 8 microseconds after GPIO44 was set. I'm trying to understand why did it happen and fix that problem.
Code structure:
The code is loaded to flash and run from RAM.
CPU timer1 is used as time base of 20 microseconds and its overflow flag is polled to advance relevant counters.
One question that may be related:
There is one occurrence where Timer1 is reloaded (same period of 20 microseconds) but it is not stopped prior to reloading command. Could that be related to the problem? If timer overflow flag was going to be set (Timer reach zero) exactly at the time (clock) of instructing the timer to reload (CpuTimer1Regs.TCR.all = 0x8C20;), could the overflow flag remain set?
A very simplified and reduced code to demonstrate the location where the problem occurs is attached.
Your assistance would be very appreciated.
Dvir.
#include "F28x_Project.h"
//====================================================================
// Functions prototypes
//====================================================================
void ConfigGpio(void);
void Timer1_counters_increment(void);
void function1(void);
//====================================================================
// Variables
//====================================================================
Uint32 Counter;
Uint32 Flag;
//====================================================================
// main()
//====================================================================
void main(void)
{
InitSysCtrl();
DINT;
InitPieCtrl();
InitGpio();
ConfigGpio();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
InitCpuTimers();
EINT;
ERTM;
ConfigCpuTimer(&CpuTimer1, 150, 20u); // Timer1 serves as 20 microseconds time base
CpuTimer1Regs.TCR.all = 0x8C00;
GpioDataRegs.GPACLEAR.bit.GPIO0 = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO44 = 1;
while(1)
{
function1();
}
} // END of main()
//====================================================================
// Functions definitions
//====================================================================
void ConfigGpio(void)
{
EALLOW;
GpioCtrlRegs.GPAGMUX1.all &= ~0xf0f3cfff;
GpioCtrlRegs.GPAMUX1.all &= ~0xf0f3cfff;
GpioCtrlRegs.GPBGMUX1.all &= ~0x0f0fffff;
GpioCtrlRegs.GPBMUX1.all &= ~0x0f0fffff;
GpioCtrlRegs.GPAGMUX1.all |= 0x00000000;
GpioCtrlRegs.GPAMUX1.all |= 0x00000500;
GpioCtrlRegs.GPBGMUX1.all |= 0x00000000;
GpioCtrlRegs.GPBMUX1.all |= 0x00000005;
GpioCtrlRegs.GPAPUD.all = 0xC4FF0D3F;
GpioCtrlRegs.GPBPUD.all = 0x00003C84;
GpioCtrlRegs.GPACTRL.all = 0x1E004B4B;
GpioCtrlRegs.GPBCTRL.all = 0x1E1E1E1E;
GpioCtrlRegs.GPAQSEL1.all = 0xA0008000;
GpioCtrlRegs.GPBQSEL1.all = 0x000A2A8F;
GpioDataRegs.GPADAT.all = 0x00000000;
GpioDataRegs.GPBDAT.all = 0x00000000;
GpioCtrlRegs.GPAODR.all = 0x00000000;
GpioCtrlRegs.GPBODR.all = 0x00000003;
GpioCtrlRegs.GPADIR.all = 0xC4FF0D0F;
GpioCtrlRegs.GPBDIR.all = 0x00003084;
EDIS;
}
void Timer1_counters_increment(void)
{
CpuTimer1Regs.TCR.all = 0x8C00; // Resets CPU-Timer 1 overflow flag. Timer runs free
Counter++;
}
void function1(void)
{
if(Flag == 0)
{
GpioDataRegs.GPBSET.bit.GPIO44 = 1;
CpuTimer1Regs.TCR.all = 0x8C20; //Clear timer interrupt flag and reload timer
Counter = 0; //Reset counter
while (Counter < 2) // count 40 microseconds after GPIO44 is set
{
if (CpuTimer1Regs.TCR.bit.TIF)
{
Timer1_counters_increment();
}
}
Flag = 1; // Flag that 40 microseconds were counted
if (GpioDataRegs.GPBDAT.bit.GPIO40) // After 40 microseconds GPIO40 is tested
{
GpioDataRegs.GPASET.bit.GPIO0 = 1; // Set GPIO0 to indicate that GPIO44 is high
}
}
}




