PDA

View Full Version : Pic Speed / Instruction Speed etc



jamie_s
- 27th April 2010, 12:35
Hi all,

I've got some code im testing, basically to decode a trigger wheel, and output 3 pulses per rotation of the wheel which has 35 teeth.





CMCON = 7 ' set portA to digital
TRISA = %00100000 ' Port A all output but MCLR
TRISB = %00001000 ' Port B all output but 3 (CCP)
InPIN VAR PORTB.3 ' Define input pin
OutPIN VAR PORTB.5 ' Define output pin
LastState VAR BIT ' Last Pin State
PulseCount VAR BYTE ' Number of input pulses


PulseCount = 0
Low OutPin

MainLoop:
if InPIN <> LastState then ' If Input State Changed

LastState = InPIN

PulseCount = PulseCount + 1

Select Case PulseCount

Case 1
High OutPin
Case 4
Low Outpin

Case 12
High OutPin
Case 15
Low Outpin

Case 24
High Outpin
Case 27
Low Outpin

Case 35
PulseCount = 0
Low OutPin

Case is > 35
PulseCount = 0
Low OutPin

Case Else

End Select

endif
GOTO MainLoop



at maxium wheel rotation speed, the pic input frequency is approx 5khz,
now, at 4mhz, should the pic be able to keep up, or does anyone have any alternative code ideas to help improve the performance?

Acetronics2
- 27th April 2010, 13:51
Hi, Jamie

@ first ... there is a small thing I do not understand so well ...

you count the teeth ... oK ... but the way you use rising AND falling edges make 2 transitions per tooth ... or 70 transitions per turn ...:rolleyes:

the way the program is written - and taking 70 transitions into account ... I get a 13200 rpm counting limit @ 4 Mhz...:)

Alain

Bruce
- 27th April 2010, 19:13
Use a hardware counter like Timer0.

Here's one example; http://www.picbasic.co.uk/forum/showthread.php?t=10608

If you get 2 pulses per tooth just set a 1:2 prescaler for 35 counts per rev.

jamie_s
- 28th April 2010, 00:03
alain - yeah i found that out when i tested with the scope - i just doubled the numbers in the case statements and it worked fine. As the max speed is around 8500rpm, testing it seemed fine on the bench.

Acetronics2
- 28th April 2010, 09:11
Hi, Jamie

... having 3 pulses per turn and a 8500 rpm limit ... make me think of a somewhat "unusual" engine ... :p

could you tell me which engine it is ... may be I can be VERY interested in ...:rolleyes:

Alain

jamie_s
- 28th April 2010, 09:35
suzuki v6, and i want to decode a crank trigger to run an aftermarket tacho.
it probably will never see 8500rpm, but i want to ensure the pic is stable at least to 7000rpm

enauman
- 4th July 2012, 20:19
I know this is an old post but I made a tach adapter using a PIC 16F1824. It basiclly takes a single cylinder engine signal (1 pulse /720 degrees) and multiplies it by 4 to use a 4 cylinder tach. Works real well if you are interested, I can send you the code. It can be adapted to other situations as well. I also designed a real stable interface to the coil if you don't have a crank trigger.