Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Racing Shift Light

Status
Not open for further replies.

matt_hau

New Member
Ok guys I have been burning out my brain for the last 3 weeks trying to understand microcontrollers and I am now officialy obsessed.:eek:

I built a pic programmer from an altronics kit which I am happy to report works. I have been searching high and low for a basic or C code file or project for my specific task and can only find projects for LCD display or seven segment tacho's.

All I want is to illuminate a cluster of 7 leds at a predefined RPM.
I have been trying to find tutorials on C code with little results. I did find some basic code tutorials but am unsure as to the quality of the lesson.

I have been studying the datasheet for the PIC16F84 and I am more confused than when I started. I am getting a basic knowledge of the file registers and the banks and bits but still cant put it all together into a working pic.

My main issue is to understand the way the chip calculates the frequency and how to define the triggering RPM or frequency.

Could someone please offer some code that can count frequency up to 1000hz and how to trigger the leds at the predefined frequency?

I understand that most of the gurus on this site want to help guys like me to solve the problems ourselves and trust me it is not through lack of trying. Can someone steer me in the right direction? If anyone knows of frewuwncy counting specific tutorials I would be eternally grateful.
:confused:
 
There have been several threads about tachs on this site. Search for them.

If you can program it is a simple matter to light LEDs when any given RPM is reached or exceeded.

See the sticky on getting started at the start of the microcontroller forum.
Sticky: Newcomers, please read! (PIC regarded) Upd. 0xD
 
3v0 said:
There have been several threads about tachs on this site. Search for them.

If you can program it is a simple matter to light LEDs when any given RPM is reached or exceeded.

See the sticky on getting started at the start of the microcontroller forum.
Sticky: Newcomers, please read! (PIC regarded) Upd. 0xD

Gee who would have thought to search this site for Tacho threads :mad:

As I have stated when I started the thread I have searched high and low and for specific tutorials on writing code for frequency counting with an output at a certain frequency.
I have read the sticky on getting started.

3vO this is not directed at you but a general observation, it is something I noticed the first time I started searching this site for info.

It was my impression that these type of forums were to help people understand and answer electronics questions. If you want to have a place where only experienced electronic people can come and "talk shop" then perhaps you should vet any new members into the forums. I am not about to go and sign up to become and electronics engineer to satisfy my desire to do hobby electronics. I am trying to learn but you could say that there is often too much information out there.

I am a member of numerous motorcycle forums and have never seen this type of elitism before. If you want to promote your passion of electronics can I suggest you actually foster new members interests.

I am sorry if you think this is sour grapes but honestly you should consider my comments as constructive criticism.

All the best
 
Point taken.

If you were to post a circuit and/or code many of us would be happy to help you get it working. Even suggest a better circuit if yours did not pass muster.

Many/most/maybe all plans for tachs are written in assembler for old chips like the 16F84. If you want to do one in C you have my interest. But I would like to see it display RPM too.

The PIC16F84 is obsolete. If you want to program in C and do not own a compiler look at using one of the 18F series chips because microchip has a free C compiler for use with them. The 18 pin 18F1320 should work. It is a lot of processor for the task. Pay an extra buck for the chip and get a free compiler, what a deal.

My main issue is to understand the way the chip calculates the frequency and how to define the triggering RPM or frequency.

You can either count the pulses over time (frequency), or the time between pulses (period). Most PICs have counters that can be used for either.

Have the program watch the RPM and when it falls withing a given range turn on the shift LEDs.
 
Last edited:
See the code I have extrapolated from other builds. I am sure there is some key stuff missing but I have simulated on Proton IDE and it seems to have the desired effect.

Am I on the right track?

XTAL 4
main:
Symbol LED = PORTD 'makes the symbol LED = portd
TRISD = 0 'sets portd as output
Symbol Pin = PORTA.0 'makes symbol pin = Porta bit 0

Input Pin 'sets pin as input


Dim VAR1 As Word 'Not sure here, makes Var1 the measured frequency?
Loop:
VAR1 = PulsIn PORTA.0 , 1
If VAR1 = 367 Then LED = 1 'Want to activate LED when freq hits 367hz
GoTo Loop 'pretty straight forward I think




End
 
What language is this. It sort of looks like MBASIC as used by the stamp and atom but then again maybe not. If it is MBASIC the syntax changes should help else not. The big thing here is the measurement.
Code:
XTAL 4
main: 
   Symbol LED = PORTD 'makes the symbol LED = portd 
   TRISD = 0 'sets all 8 bits of portd as output
   Symbol Pin = PORTA.0 'makes symbol pin = Porta bit 0 
   Input Pin 'sets pin as input
   VAR1 var Word 'makes Var1 the measured period

Loop: 
   PulsIn Pin, 1, VAR1 
   If VAR1 = 367 Then LED = 0xFF 'Want to activate LED when freq hits 367hz
   GoTo Loop 'pretty straight forward I think

MBASIC shows the PULSIN use as
PULSIN pin, state, {TimeoutLabel,TimeoutMultiple,} Var
so that would be
PulsIn Pin, 1, VAR1

This will return the duration of the high portion of a period. Unless you have some specs you will need to look at the signal on a scope to see what it looks like. Or just try 0 and 1 to see which returns the longer time.

I am not sure where 367hz come from. VAR1 will be some number of counts which are units of time. This value is more like the period then the frequency of the signal.

If you have a regular tach I would use it to set the engine to the required RPM and then have the PIC capture the value of VAR1 when you hit a button or some such setup.

For the output you set LED to mean all of PORTD. If you want all 8 bits of port D to activate you should set it to 0xFF rather then 1.

On the input side you define " Symbol Pin = PORTA.0" then use PORTA.0 instead of Pin.

Think about when you want the shift light to go and and off. You only covered the on part.
 
Does this code look better?
I have changed the counting to another formula i found on Proton IDE. 367hz is the frequency of the coil pulses at 11,000 RPM which works out to be about 37 pulses per 100uS. It is not possible to set that rpm and take a measurement as it is too damaging to free rev that high and too hard to capture at the right time under load (first gear 11,000 rpm is around 100MPH)

I tested it on the ISIS simulator emulating WRD as a high value then a low value and it had the desired effect.

The Proton package that I found last night has been the easiest to understand by far and the visual simulator is very helpful.
Apologies for being blunt before but I did not think that I was going to get anywhere with this.:eek:

Device 16F877

XTAL 4
main:
TRISD.0 = 0
Input PORTA.0
Dim WRD As Word
PORTD.0 = 1
DelayMS 1000
PORTD.0 = 0
DelayMS 5000
Loop:
WRD = Counter PORTA.0 , 100 counts pulse per 100uS

If WRD >36 Then PORTD.0 = 1 if pulses exceed 36 per 100uS then light comes on

If WRD <=36 Then PORTD.0 = 0 If pulses less than equal or less than 36, light off

GoTo Loop





End
 
matt_hau said:
Does this code look better?
367hz is the frequency of the coil pulses at 11,000 RPM which works out to be about 37 pulses per 100uS.

No it's not.

367 Hz is the frequency of coil pulses at 11,000 rpm on a 4 cylinder, 4 stroke engine.

However, 367 Hz is 37 pulses in 100 ms, not 100 :mu:s

The programmes to measure frequency are quite a lot more involved than what you have written.

You need to count time and pulses simultaneously.

A PIC running at 4 MHz executes 1,000,000 steps per second, but it is almost impossible to use that fact if you are writing in C because you have no idea how many steps the compiler makes out of each line you write.

All PICs have timers, and that is what is used to count time, while the program counts the pulses.

The program needs to set a timer running. You then have a loop that checks if a new pulse has arrived, and if so increments a counter. The loop then checks if the timer has finished. If not, the program goes back to seeing if a pulse has arrived.

When the timer has finished, the counter value divided by the timer period is the frequency. If you arrange the timer scaling correctly, the counter value can be the answer you want directly.

The code then does whatever it needs with the counter value, like turn on the lights.

Then the counter is reset, then go back to where the timer is set running.

That is one method. It is possible to use either hardware timers or software for both pulses and time.

**broken link removed**
That uses a timer to count the pulses and the code to count the time

http://www.taylorriver.com/content/view/131/25/
That uses two timers, one to count pulses and the other to count time.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top