Counter to track engine crankshaft angle

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
BenOve
Posts: 40
Joined: 23 May 2016 07:26

Counter to track engine crankshaft angle

#1 Post by BenOve » 13 Aug 2016 08:04

An engine has an incremental rotary encoder.
It gives 1024 pulses and one reset pulse per revolution

A Counter is needed to track engine crankshaft angle

The best solution would probably be to use the internal counter in PIC
As an example: The processor 16F1937 has a 16 bit counter.

The idea is to dedicate one pin to count pulses and one pin to reset the counter for each engine revolution.
Then the counter works alone without taking any processor power
The executed program will look at the counter and generate pulses for ignition and injection when the counter has reached
specified angles,

Is this possible ? Is this the right approach?
How does the C-code look to initiate the counter and connect it to the two dedicated pins?
Is there a better choice than 16F1937 ?
I could even consider testing dsPIC or PIC32 as there will probably be many calculations and multiplications

Thanks and best regards
Bengt

diode_blade
Posts: 172
Joined: 24 Aug 2014 17:55
Location: Sheffield

Re: Counter to track engine crankshaft angle

#2 Post by diode_blade » 13 Aug 2016 11:01

Hi Ben,
I would suggest using a pic device with built in QEI module (MOTION FEEDBACK MODULE, I have used 18f4431 devices before (but there are some known issues with these although I have never had much of a problem with them with this module, some of the DSPICS also have the QEI module (quadrature encoder interface, motion feedback module), so I would certainly think of using a dspic with a in built qei module, with the 18f4431 3 of the PortA pins are used for this for a quad encoder, Chan A,Chan B and Index.
Once the module hardware is setup only software you are writing is the reading of the appropriate registers

Summary below of motion feedback module of 18f4431

TABLE 17-1: SUMMARY OF MOTION FEEDBACK MODULE FEATURES
Submodule Mode(s) Features Timer Function
IC (3x) • Synchronous
• Input Capture
• Flexible Input Capture modes
• Available Prescaler
• Selectable Time Base Reset
• Special Event Trigger for ADC
Sampling/Conversion or Optional
TMR5 Reset Feature (CAP1 only)
• Wake-up from Sleep function
• Selectable Interrupt Frequency
• Optional Noise Filter

QEI QEI • Detect Position
• Detect Direction of Rotation
• Large Bandwidth (F
CY/16)
• Optional Noise Filter


Velocity
Measurement
• 2x and 4x Update modes
• Velocity Event Postscaler
• Counter Overflow Flag for Low
Rotation Speed
• Utilizes Input Capture 1 Logic
(IC1)
• High and Low Velocity Support
TMR5 • 3x Input Capture (edge
capture, pulse width, period
measurement, capture on
change)
• Special Event Triggers the
A/D Conversion on the CAP1
Input
16-Bit
Position
Counter
• Position Measurement
• Direction of Rotation Status
TMR5 • Precise Velocity Measurement
• Direction of Rotation Status

Hope this can point you in the right direction.
Dave
"When the bugs strike it's no good bashing your head against a brick wall, you might damage the wall"

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

Re: Counter to track engine crankshaft angle

#3 Post by p.erasmus » 13 Aug 2016 12:05

As Dave has mentioned use a device that has an dedicated QEI interface for the Rotary encoder however you should in my opinion consider a dsPIC33EP as it has the processing power
for the needed engine calculations
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

BenOve
Posts: 40
Joined: 23 May 2016 07:26

Re: Counter to track engine crankshaft angle

#4 Post by BenOve » 13 Aug 2016 13:35

These are great ideas, thanks !

I have dsPIC33 EP 512 MU810 at home with experimental board,
This chip should be OK for development i guess,
and then downscale for production.

Where in the C code do I tell the compiler to dedicate 2 or 3 pins
for CountUp and Reset ? I have never done this before.

As it is a QEI interface it must be possible to use 2 CountUp signals with phase difference to tell direction = 3 pins .
(Makes everything better)

Thanks & Best regards
Bengt

Post Reply

Return to “mikroC PRO for PIC General”