Hi,
I could sure use some help. I'm need my board to trigger pulses based on position and I also need to set varying pulse widths. My code for starting the pulses works fine.
I'm trying to use the timer1 interrupt to set my pulse widths. That is, my code sets a pin high, sets the new T1PR according to the desired pulse width, clears the T1 counter, and the timer1 isr should set the pin low.
What's happening is my pulse widths aren't being set correctly. Although the timer seems to be setup properly, (if I let it free run using the period registers I define below, it runs correctly). However, when I try and use the timer to set my pin low, I get pulse widths that are constant at about 2us.
Here's where I set up the timer:
void Init_eva_timer1(void)
{
//NFE defined as 0x0034, 10us
//FED defined as 0x00D0 , 40us
//FEU defined as 0x016D, 70us
// Initialize EVA Timer 1:
// Setup Timer 1 Registers (EV A)
EvaRegs.GPTCONA.all = 0;
// Set the Period for the GP timer 1; ** hspclk = sysclk/2 = 83.3325MHz
EvaRegs.T1PR = NFE; //default 10us
EvaRegs.T1CMPR = 0; //
// Enable Period interrupt bits for GP timer 1
EvaRegs.EVAIMRA.bit.T1PINT = 1;
EvaRegs.EVAIFRA.bit.T1PINT = 1;
// Clear the counter for GP timer 1
EvaRegs.T1CNT = 0x0000;
//prescaler equal hspclk/16,
//cont up count,
//use own TENABLE bit,
//internal hspclk source,
//enable timer compare operation,
//use own period register,
//reload timer compare register when counter = 0
EvaRegs.T1CON.all = 0x1442;
}
Here's the code that sets my pin high:
void handle_pulse()
{
//set up appropriate pulse width
if(pulseindex==ifeu) EvaRegs.T1PR = FEU;
else if(pulseindex==ifed) EvaRegs.T1PR = FED;
else EvaRegs.T1PR = NFE;
//Trigger the pulse
//Clear the counter for GP timer 1 and enable the interrupt
EvaRegs.EVAIMRA.bit.T1PINT = 1;
EvaRegs.T1CNT = 0x0000;
GpioDataRegs.GPDSET.bit.GPIOD1 = 1; //transceiver transmit pin
}
Here's the ISR that should set the pin low at the appropriate pulse width:
interrupt void PulseTimer(void)
{
GpioDataRegs.GPDCLEAR.bit.GPIOD1 = 1; //transceiver transmit pin
// Enable more interrupts from this timer
EvaRegs.EVAIMRA.bit.T1PINT = 1;
// Note: To be safe, use a mask value to write to the entire
// EVAIFRA register. Writing to one bit will cause a read-modify-write
// operation that may have the result of writing 1's to clear
// bits other then those intended.
EvaRegs.EVAIFRA.all = BIT7;
// Acknowledge interrupt to receive more interrupts from PIE group 2
PieCtrlRegs.PIEACK.all = PIEACK_GROUP2;
}
Any suggestions would be greatly appreciated.
Thanks!
Jason