-2

I am new to the forum. I am recording the RPM, and show it on 4x seven segments with CCP2. It actually works quite well from about 3.81Hz to about 166Hz, which is enough upwards. I measure the frequency based on each rising edge (waiting for a rising edge), thereby calculating the frequency. I do not use an external interrupt. I use Timer1 with Fosc/4 = 2MHz and prescale 8. What gives me problems are the lower frequencies so lower than the 3.81Hz. I tried to count the overruns and determine the correct RPM from that, but unfortunately it doesn't work.

period = ov_cnt * 65536 + Second_Edge - First_Edge

Is there a possibility to increase the Timer1 from 16bit or 19bit or 24bit?

Or is there another possibility to measure and display the lower frequencies?

Or am I doing something wrong?

I work with: MPLAB X IDE v5.50 XC8 v2.32 compiler PIC18F45K22 Pickit3 Programmer/Debugger

I hope you can help me.

Thanks a lot and best regards

anatolyg
  • 26,506
  • 9
  • 60
  • 134
  • You might want to clarify "it doesn't work": How do you know it doesn't work? How do you expect it to work? Explaining that might make 50% way to the answer (though I admit I can't answer). You can [edit] your question to clarify it. – anatolyg Feb 22 '22 at 15:31
  • Welcome to Stack Overflow. Please read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly please learn how to create a [mre], and how to [edit] your questions to improve them. – Some programmer dude Feb 22 '22 at 15:34
  • I guess, the answer from Gnqz is the way to go, but if you tell us how you try to count the overruns, we might find out why it "doesn't work". – Gerhardh Feb 22 '22 at 16:17
  • Thank you for the contributions. I measure the time of each rising edge (waiting for the rising edge), through this I calculated the period and the frequency. This works between 3.81Hz and 166Hz, that signal I generated with a signal generator, then I may assume that it works. The overflows I have measured and integrated into the calculation. Unfortunately it does not give the correct result. I have checked it with the fed signal *60 so that I have the revolutions per minute. For counting I use the Timer1 in 16bit mode. It could be that I am also doing the calculations wrong? – programming_C Feb 22 '22 at 17:47

1 Answers1

1

I would suggest that you can just increment an 8 bit variable and use it as the MSByte of a 24 bit count with Timer1 register as the lower 16 bits. This is the extending of the timer you asked about (sort of). Other option would be to set set timer interrupts and I/O interrupt on raising edge of the impulses and reset both variables on each second.

Gnqz
  • 3,292
  • 3
  • 25
  • 35
  • Thanks for the quick reply. Can you please explain me more about 24bit extension. Thank you and best regards – programming_C Feb 22 '22 at 17:54
  • Since your timer is 16 bit, you could just define a 32 bit variable and compose it with bit masks to compose the with lower 2 bytes being your timer register value and the higher 2 bytes will be cleared MSB + the variable storing your overflow count. – Gnqz Feb 23 '22 at 15:52