• AVR Freaks

Helpful ReplyHot!Measure frequency less than 1Hz ( 0.1 to 5 Hz)

Page: < 12 Showing page 2 of 2
Author
ric
Super Member
  • Total Posts : 24581
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Measure frequency less than 1Hz ( 0.1 to 5 Hz) 2019/11/07 12:23:54 (permalink)
5 (1)
g.ravi
Hi Mysil,
 
Do we need to clear IC2Buff value upon IC2 interrupt though the values are directly fetched from 32 bit timer.

No.
I don't understand what you want to clear. The whole point is that you do NOT clear the timers, just calculate how far they have advanced since the previous interrupt.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#21
g.ravi
Senior Member
  • Total Posts : 170
  • Reward points : 0
  • Joined: 2005/12/19 02:14:26
  • Location: India
  • Status: offline
Re: Measure frequency less than 1Hz ( 0.1 to 5 Hz) 2019/11/08 03:02:09 (permalink)
0
ric
g.ravi
Hi Mysil,
 
Do we need to clear IC2Buff value upon IC2 interrupt though the values are directly fetched from 32 bit timer.

No.
I don't understand what you want to clear. The whole point is that you do NOT clear the timers, just calculate how far they have advanced since the previous interrupt.




Hi Ric,
 
 
Input Capture Overflow (ICOV):  (Quick reference from datasheet)
The ICOV read only Status bit (ICxCON<4>) will be set when the capture buffer overflows. In the
event that buffer is full with four capture events and a fifth capture event occurs prior to a read of
the buffer, an overrun condition will occur, the ICOV (ICxCON<4>) bit will be set to a logic ‘1’ and
the respective capture event interrupt will not be generated. In addition, the fifth capture event is
not recorded and all subsequent capture events will not alter the current buffer contents.
To clear the overrun condition, the capture buffer must be read four times. Upon the fourth read,
the ICOV (ICxCON<4>) status flag will be cleared and the capture channel will resume normal
operation.
 
 Though there is no effect of reading or avoiding ICxBUF values for now, I am capturing ICxBUF value to an dummy variable to avoid malfunction.
 
Warm Regards,
Ravi.
#22
g.ravi
Senior Member
  • Total Posts : 170
  • Reward points : 0
  • Joined: 2005/12/19 02:14:26
  • Location: India
  • Status: offline
Re: Measure frequency less than 1Hz ( 0.1 to 5 Hz) 2019/11/08 03:35:33 (permalink)
0
Finally I can see consistent output, Thankyou Mysil, Ric and Pcbbc.
 

void __attribute__((__interrupt__,no_auto_psv)) _IC2Interrupt(void)
{
 temp_ICCBuff = TMR2; // Capture ""LSW to temporary variable"
 IFS0bits.IC2IF = 0; // Clear bit IC1IF (IFS<2>) ICC Interrupt
 previous_value = current_value; // Copy timer value during previous interrupt
 current_value = TMR3HLD; // "MSW" is captured in Current Value
 current_value = current_value << 16; // Shift "LSW" to "MSW"
 current_value = current_value + temp_ICCBuff; // MSW + LSW to form 32 bit value

 timePeriod = current_value - previous_value;
  temp_ICCBuff = IC2BUF; // Clear ICC Buff value though it has no effect on program to avoid ICBUF overflow error
// printf("PV = %ld , CV = %ld , Tp = %ld ,Fcy = %f Hz\n\r", previous_value, current_value, timePeriod, cap_freq1 );
}

 
 
Warm Regards,
Ravi
#23
ric
Super Member
  • Total Posts : 24581
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Measure frequency less than 1Hz ( 0.1 to 5 Hz) 2019/11/08 03:47:15 (permalink)
4 (1)
Can't you reduce
 current_value = TMR3HLD; // "MSW" is captured in Current Value
 current_value = current_value << 16; // Shift "LSW" to "MSW"
 current_value = current_value + temp_ICCBuff; // MSW + LSW to form 32 bit value

to
current_value = (TMR3HLD << 16) + temp_ICCBuff;

 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#24
Page: < 12 Showing page 2 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5