Content originally posted in LPCWare by JSalisbury on Thu May 12 08:26:20 MST 2011
Hi,
I am useing a 16 bit counter to count incoming pulses and trigger interupt on count = match value. I would like to be able to change the match value within the ISR, what is the safe way of doing this.
I have tried the code shown but I do sometimes get errors such as
" Single stepping until exit from function __write,
which has no line number information. when single stepping"
Thanks
/******************************************************************************
** Function name: reset_timer
**
** Descriptions: Reset timer
**
** parameters: timer number: 0 or 1
** Returned value: None
**
******************************************************************************/
void reset_timer16(uint8_t timer_num)
{
uint32_t regVal;
if ( timer_num == 0 )
{
regVal = LPC_TMR16B0->TCR;
regVal |= 0x02;
LPC_TMR16B0->TCR = regVal;
}
else
{
regVal = LPC_TMR16B1->TCR;
regVal |= 0x02;
LPC_TMR16B1->TCR = regVal;
}
return;
}
void TIMER16_1_IRQHandler(void)
{
/*
* adc_data_buff 0=x 1=y 2=Z
*/
int i;
int curr_ch;
uint32_t local_v;
if ( LPC_TMR16B1->IR & 0x1 )
{
SSP_Receive( 1,debug_rx_buff_local, 3 ); //perform read regardless if the data is needed reduce jitter
switch (counter_control)
{
case reset_adc:
TESTPIN_1_ON;
SYNC_N_HIGH;
drdy_count = ADC_BURST_LIM;
counter_control=adc_drdy_wait;
MUX_0_LOW;
MUX_1_LOW;
LPC_TMR16B1->MR0 = DRDY_LONG ; // these lines can cause lockup
reset_timer16 (ADC_COUNTER); // these lines can cause lockup
LPC_TMR16B1->IR = 1;
break;
}
return;
}