Tachometer not working why?

Status
Not open for further replies.
Joined
Dec 4, 2012
Messages
4,280
Helped
822
Reputation
1,654
Reaction score
791
Trophy points
1,393
Location
Bangalore, India
Visit site
Activity points
0
Why this Tachometer code not working as expected? I have used the code from the book "Embedded C Programming and the Microchip PIC" page nos. 150 and 151.

mikroC PRO + Proteus files attached.
 

Attachments

  • Tachometer rev1.rar
    169.5 KB · Views: 58

The code has several weaknesses:

Most obviously
Code:
CCP1IE_bit = 1;
must be preceeded by
Code:
CCP1IF_bit = 0;

otherwise there's a good chance that the Interrupt triggers immediately although the flag has been already set during the lengthy LCD output.

Secondly, the long arithmetic during CCP interrupt produces a large likelihood to miss counter overflow interrupts. You should remove most of the calculations from the interrupt. There's no need to calculate a long starttime, instead count overflows from the start event.
 
I see two reasons for smalls "fluctuations":
- measure period is uncertain by 1 LSB due to asynchronous input frequency
- wrong overflow factor of 65535, should be 65536

Finally, there might be still missed overflow counts, although I didn't oberve it.

The interrupt code can be slightly reduced by adjusting variable lengths. Not to depend on delays in the main code, we would latch endtime and overflow count in the CCP interrupt.
 
The varying of value stopped. Now the value is stable but I see flickering in LCD. I have disabled WDT in code and also in Proteus. I am testing in hardware and also Proteus. I don't know what is causing the flickering of LCD.
 

Attachments

  • Tachometer rev4.rar
    119.8 KB · Views: 60

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…