I wanted to capture the duty cycle of a low speed input, it's called capture and it's about 500HZ my system clock is 50MHz, I have used chip scope to see the FRQ_BUF0(0) value, but it seems it does not capture the data correctly, I will get the FRQ_BUF0(0) some odd values like 0,2,3, 361 etc...
what's wrong with my code, I have done it in an NXP LPC timer and the code is similar to the C implementation in there.
my C code for the LPC looks like this and it works perfectly.
void TIMER2_IRQHandler(void)
{
LPC_TIMER2->IR=0XF0;//Clear all sources
CaptureValue[0][1]=LPC_TIMER2->CR0;
if(CaptureValue[0][1]>CaptureValue[0][0])
{
freq[0] = CaptureValue[0][1] - CaptureValue[0][0];
}
else
{
freq[0] = ((uint64_t)CaptureValue[0][1]+ 0x100000000) - (uint64_t)CaptureValue[0][0];
}
CaptureValue[0][0]=CaptureValue[0][1];
}