RPM Readout

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
MrMyhosh
Posts: 7
Joined: Fri Jul 27, 2012 1:12 pm
Has thanked: 12 times
Been thanked: 1 time
Contact:

RPM Readout

Post by MrMyhosh »

Hi all,

Does anyone have a working RPM counter, can i use it or look to the flowchart.

I'm doing a project where I use BLDC motor 24V. The motor has 3 wires for the hall sensors. I want to use 1 of those wires and so calculate the RPM. It gives 4 pulses per rotation. Max RPM is 4000. Maximum 16,000 pulses per minute. Minumum is + - 20 RPM. (80 pulses).

I have the frequency counter flowchart of BenJ tried. With a frequency generator sent pulses between 5 Hz and 500 Hz, but everytime I get a wrong value. The program reacts to the frequency change but the values ​​never match.

Also the 75 interrupts in TMR0 take much longer than 1 second. Sometimes it takes up to 40 seconds. Different clock speeds and also different crystals tried.
Can anyone give me advice or an example flowchart pls.

I am using PIC16F887 with an LCD. 20 * 4.
Pulses are read on input B0 as integer.

Kind regards

MrMyhosh from Netherlands

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: RPM Readout

Post by dazz »

Hi
have a look at this thread http://www.matrixmultimedia.com/mmforum ... xls#p15618 its a very good primer on timers and the xls file is brilliant, post your flowchart up as this will help others to see if there is a code issue
Regards
Dazz
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: RPM Readout

Post by Enamul »

HI,
I have used FC example frequency counter for measuring rpm for EC-FAN motor which works fine..If you are using the same program than it may be hardware issue..If you are not using that one..Please find that attached..Also you can post the program you are using..
Enamul
Attachments
5. Digital frequency counter.fcf
(13.5 KiB) Downloaded 516 times
Enamul
University of Nottingham
enamul4mm@gmail.com

MrMyhosh
Posts: 7
Joined: Fri Jul 27, 2012 1:12 pm
Has thanked: 12 times
Been thanked: 1 time
Contact:

Re: RPM Readout

Post by MrMyhosh »

Thanks for reply

I wil upload my flowchart at the weekend.

MrMyhosh
Posts: 7
Joined: Fri Jul 27, 2012 1:12 pm
Has thanked: 12 times
Been thanked: 1 time
Contact:

RPM Readout

Post by MrMyhosh »

Hi all

I'm new in this area and almost no experience and Sorry for my bad English.

Here is my flowchart. I send 2 flowcharts. 1 with RPM input. 1 without RPM input. I use the Frequency Counter flow chart that I've downloaded from here. (5. Digital Frequency Counter from BenJ).
The following changes I made ​​to the original FC:
16F88 has been changed to 16f887.
Read Input in my own FC (B0 integer) is changed to the original FC (A0 Byte).
After Desicion in MACRO Shaft_Encoder the connection point A is made so that the program returns to the MAIN MACRO.

During simulation of the program when the MACRO Shaft Encoder is called stops Timer0. After that, only the MACRO SHAFT_Encoder run without reaching the 75 interrupt.

FC Operation Program.
Home screen. (LCD_STARTUP) run a once only.
After a high level on input AN1 the program runs through.
THUMBWHEEL Module will be read.
Then the Vehicle_SPeed MACRO and CONTROL_Voltage Macro. These 3 data will be sent to the LCD.
Then MACRO SHAFT_Encoder called. During the process when the input AN1 becomes high NEW_VALUE MACRO is called and then again THUMBWHEEL MACRO.

Thanks for the help

MrMyhosh
Attachments
shaft encoder WITH RPM calculation.fcf
(50.41 KiB) Downloaded 466 times
shaft encoder WITHOUT RPM calculation.fcf
(39.13 KiB) Downloaded 415 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RPM Readout

Post by medelec35 »

I believe the way to go would be to use port interrupt for tacho detection.
Otherwise if not sitting in a tight loop, you could easily miss hall effect being triggered.
If that was the case RPM will be out

I Have moved this topic to Flowcode V5, where it is more relevant.

Martin
Martin

MrMyhosh
Posts: 7
Joined: Fri Jul 27, 2012 1:12 pm
Has thanked: 12 times
Been thanked: 1 time
Contact:

Re: RPM Readout

Post by MrMyhosh »

Hi medelec35

can you explain that to me in easy english pls.
Do you have a example of port interrupt.

Mrmyhosh

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: RPM Readout

Post by brandonb »

this is one that i did for a chevy, i changed the calculation to fit requirements, update rate is 2x
Attachments
rpm 4x crankshaft for matrix.fcf
(24.94 KiB) Downloaded 450 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RPM Readout

Post by medelec35 »

MrMyhosh wrote: can you explain that to me in easy english pls.
Sorry, I did rush a bit as I had to go out urgently hence did not fully check your flowchart or give a detailed answer.


The problem with your flowchart is within timer0 interrupt macro called TMR_INT.
What is suppose to happen is since timer interrupt frequency is 75Hz, count starts off at 0.
Then every 1/75 =13.333ms interrupt is triggered and TMR_INT macro is accessed, Count variable is incremented by 1.
When Count variable = 75 then 1 second as passed (75*13.333ms). At this point Count has to reset to 0.
Its the reset to 0 that's missing.

If you edit

Code: Select all

Display_Freq = freq 
calculation
to

Code: Select all

Display_Freq = freq
count = 0
Your program should work as expected.

What was happening is once Count reached 75 display was updated with frequency as normal.
However since count was not reset to 0, on next timer interrupt trigger 13.33ms later the display was updated again!
This is because the decision branch will always be true for every number greater or equal to 75
This will keep happening until Count rolls-over from 255 to 0 etc.

You also have got a couple of uninitialized variable warnings.
This is because the variable is being read before its written to.
To solve this:
just Select variable that has uninitialized warning in project explorer, click edit.
Enter 0 in the initial value field.

As for using interrupt for tacho detection:

Code: Select all

After adding count = 0
You hardware should work as expected since it is build around a tight loop (constantly keep reading A0 for state to change otherwise known as polling).
So an additional interrupt may not be required.
Let me know if you are still interested in learning about using interrupts to detect pulse, then I will explain more.

Hope this is more helpful.

Martin
Martin

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: RPM Readout

Post by Enamul »

Hi,
As Martin said, there was a problem in TMR_INT, I have noticed that just not count =0 is missing but also decision logic was also wrong ...
I have solved those issues..I am seen another issue of clock frequency..you select clock as 19.66MHz and use that in TMR_INT(I mean 75 interrupt freq is true for this freq) but in configuration you have selected INTERNAL clock...which should not be...I have corrected that and you have to put xtal of 19.66MHz in hardware between 13 and 14 pin.
I am attaching here the corrected code..
Enamul
Attachments
shaft encoder WITH RPM calculation_v1.fcf
(49.49 KiB) Downloaded 407 times
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: RPM Readout

Post by Enamul »

Hi,
I have tested the program in Real PIC simulator which gives result almost same as hardware and it works fine at least the frequency counter side...I don't know about the other portion of the program too much if you can describe a bit details I can have a look. of course if there is any problem still left..
I have attached here the screen shot of real pic...
Enamul
Attachments
shaft_encoder.png
(64.81 KiB) Downloaded 8690 times
Enamul
University of Nottingham
enamul4mm@gmail.com

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RPM Readout

Post by medelec35 »

Hi Enamul, thanks for the spot.
Configuration is one thing I normally check.
However since it was stated wrong frequency was displayed, I wrongly assumed configuration was ok otherwise there would be nothing at all on LCD display. I was being lazy I guess.
@Mrmyhosh. I Do agree with what Enamul has said.
Also I have posted and alternative Flowchart that uses falling edge of Int (port B0 instead of polling port A0) for detection
Since this is using interrupt to do frequency detection as well, then other tasks can be carried out simultaneously.
This has the improvement on using a tight loop for polling input.
If you would like to cut down on hardware, then you could connect switches to port B and use internal pull-up resistors (I can help you with that)
This would mean you do not have to use external pull-up resistors for switches or encoder.

Martin
Attachments
shaft encoder WITH RPM calculation_v2.fcf
(47.98 KiB) Downloaded 353 times
Martin

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: RPM Readout

Post by Enamul »

Hi,
Martin's change make the program more robust...I have put the Freq display portion back in your encoder macro...
I have added here the frequency counter using RB0 INt as for others reference...and picture of real pic...how cool it works!!
Enamul
Attachments
frequency_counter.png
(54.91 KiB) Downloaded 8678 times
shaft encoder WITH RPM calculation_v3.fcf
(48.08 KiB) Downloaded 329 times
Digital frequency counter.fcf
RB0/INT
(16 KiB) Downloaded 334 times
Enamul
University of Nottingham
enamul4mm@gmail.com

MrMyhosh
Posts: 7
Joined: Fri Jul 27, 2012 1:12 pm
Has thanked: 12 times
Been thanked: 1 time
Contact:

Re: RPM Readout

Post by MrMyhosh »

hi guys,

Thank you all for all the work.
Today I was working on the example of BrandoB to implement in my own flowchart. (thanks to brandonB for example).
I will also download and try the latest posts and examples.

I'm doing a final project that complete my study. I study for industrial automation where we learn a lot about choppers, inverters, motors, PLC technology and very little about IC and PIC programming. In my project I thought it would be easy to write a small program to display all information but I was wrong. Programming the tachometer was harder than expected. :(

Where can i download the Real Pic Simulator software?

Thankyou all for all the work guys.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: RPM Readout

Post by Enamul »

Hi,
It shouldn't be so tough..... :) Here is the link for real pic version...active for 30 days..
http://digitalelectrosoft.com/download-pic-simulator
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

MrMyhosh
Posts: 7
Joined: Fri Jul 27, 2012 1:12 pm
Has thanked: 12 times
Been thanked: 1 time
Contact:

Re: RPM Readout

Post by MrMyhosh »

Thanks Enamul,

Ik found it just after i post the message.
I am using now and i think i will buy it at the end of the trial period. It a verry good program. Thanks to you for print screens :D

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: RPM Readout

Post by Enamul »

Hi,
I am using now and i think i will buy it at the end of the trial period. It a verry good program
Same to me..I am almost at the end of trial period..I will buy..
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

MrMyhosh
Posts: 7
Joined: Fri Jul 27, 2012 1:12 pm
Has thanked: 12 times
Been thanked: 1 time
Contact:

Re: RPM Readout

Post by MrMyhosh »

Hi guys,

The readout of RPM is now very pretty successful. I use now the latest version of Medelec35. the 2nd version.
It is very small but effective. Now I understand how the port interrupt function work. :)

All who think about this issue "Thank you".

there where a few problems with calculating Vehicle Speed ​​but they resolved themselves.
He is now doing exactly what I wanted. :)

Thank you all and until next time

MrMyhosh
prnt scrn PIC SIM.doc
(125 KiB) Downloaded 310 times

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: RPM Readout

Post by Enamul »

Hi,
It's nice to see that you are at destination..Good work man :)
Did you bought the Real PIC Simulator? Mine one is just finished today...I will buy tomorrow.
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RPM Readout

Post by medelec35 »

I'm pleased you have got your flowchart working now.
It's great that you understand interrupts, they do come in handy.
A few things to remember is keep interrupts routines as short as possible.
While its in the interrupt routine, all there interrupts on 8bit chips are disabled until routine is exited.
So allow to exit normally at the bottom and do not place any calls to other macros within interrupt.
Do not use any components or routines within interrupt that is also used in other parts of flowchart.
E.g LCD commands, Mod functions same types of delays etc.

Martin
Martin

Post Reply