Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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
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: 43

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 have fixed some issues. It is now better but still the value fluctuates. How to make the value stable?
 

Attachments

  • Tachometer rev2.rar
    124.4 KB · Views: 37

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: 46

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top