shounenbat

Hi, Im the one who posted the question Control DC Motor using VB Expres 2005 . I have another question, how can I create a counter using LDR as an input I want my program to count the rpm(rev/min) of the dc motor using LDR. Is it possible to use a timer Thanks.

Re: Visual Basic Express Edition Counter question

ReneeC

LDR




Re: Visual Basic Express Edition Counter question

Steve2222

Here is the general process.

Declare a global integer to store your count.

Let your incoming signal trigger an event which increments the counter.

Insert a timer with a suitable interval, say 1000ms

On the timer tick event, calculate and display the rpm, reset the counter to zero.

You will have to work out how you are going to get the LDR to trigger and event.




Re: Visual Basic Express Edition Counter question

Carsten Kanstrup

I presume that LDR stands for Light Dependent Resistor and SCR is a thyristor (Silicon Controlled Rectifier). Don't use shortenings like this in a software forum.

You can use the modem signals of the serial port to generate the events. If the maximum speed is 3000 RPM, this corresponds to 50 Hz, which the event system should be able to handle.

If you have a higher pulse frequency up to 5 KHz or even higher (40 KHz max), you can use the receiver FIFO in the UART to count the pulses (by means of Break). Ask again if this is the case and I will explain in details.





Re: Visual Basic Express Edition Counter question

Omar Abid

This is a counter that add 1 each second

First add a timer (timer1) to your project

'This is the handler that begin counting : put it where you want to start

Public X as integer

Private Sub locked_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

AddHandler Timer1 .Tick , AddressOf addone

timer1.interval = 100

timer1.start()

End Sub

Private Sub Addone()

x +=1 'Same as x = x + 1

End sub

' use this timer1.stop to stop the counter






Re: Visual Basic Express Edition Counter question

shounenbat

thanks for the code but still it doest work.
how can my timer interact with my input device like ldr and display its rpm hope you can help me because im a beginner. thanks a lot.





Re: Visual Basic Express Edition Counter question

shounenbat

im still confused so to make it easier for me to understand lets say i have a button.
by clicking the button how will i compute and display the no of times i clicked it per minute or per second




Re: Visual Basic Express Edition Counter question

Omar Abid

I do not know a lot on those things (LDR,RPM..)

But the counter can calculate in function of time

For example add n to x in each second

You have to make calculatino then use it






Re: Visual Basic Express Edition Counter question

Carsten Kanstrup

Before you can make the revolution counter you must consider and answer the following questions:

1) How many readings do you need per second For a display, 2-4 readings are usually preferred, but if you are going to make a control loop, you need many more.

2) What is the maximum pulse frequency

3) What accuracy do you need For high accuracy at low frequencies you may need to make a reciprocal counter, which measure the time between a number of pulses instead of counting the number of pulses within a given time.

4) How much jitter can you accept The timer system is rather inaccurate. The timer expired message (WM_TIMER), which gets posted to the message queue, has lower priority than all other messages except for WM_QUIT and WM_PAINT, so the timer value you select may easily be 50-100 mS longer than expected on one timer tick, but will then be shorter on the next one (continuous timer operation - no start/stop). This will create some jitter on the readings, which you may need to filter out by means of a digital filter.

5) How fast must the readings settle This is relevant in case you need a digital filter to keep the jitter at an acceptable level.

It is very important that you are realistic and do not set higher demands than absolutely necessary. You may very well find yourself in a situation where it cannot be done without hardware assistance!





Re: Visual Basic Express Edition Counter question

shounenbat

thanx for replies and im all considering your suggestions. im working out on it and hopefully i can make it with the hardware by tomorrow. I'll update you guys sooner. thanks again.




Re: Visual Basic Express Edition Counter question

shounenbat

hi, i have a problem with the program i made, it is working but still the output of my program is really not that accurate. i think i have a problem with my boolean. what do you think guys do you have any suggestions.

the program must display the rpm of the motor.

127 is the input coming from parallel when ldr sense that the motor is running

95 when it is off

would someone revise my program pls...

public y as boolean

public x as integer

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Label4.Text = Inp(889)

If Label4.Text = "127" Then

X = X + 1

y = True

ElseIf Label4.Text = "95" Then

y = False

End If

End Sub

Private Sub Timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer2.Tick

Label2.Text = X * (60)

X = 0

End Sub





Re: Visual Basic Express Edition Counter question

Carsten Kanstrup

You need to explain much better how this is intended to work!

It is obvious that you use bit 5 on the parallel port as a signal, which tells if the motor is running - 1111111 binary versus 1011111 binary, but:

1) Why do you convert the byte to text instead of just:

If (Inp(889) And 32) Then

2) How do you intend to count the number of edges You read the parallel port when Timer1 ticks, but this will not give you any frequency. You need to count the number of pulses within a given time - for example the display refresh time you select, but you need an event to do that if you are not going to burn almost 100% CPU time polling the signal, and even if you do that you may easily miss a lot of edges when .NET runs other jobs.

3) Why do you use an extra timer to convert to RPM It is much easier just to set Timer1 equal to the refresh time you need and then calculate a new RPM value for each tick.

Maybe it is anyway a good idea to answer my five questions in my previous post. You cannot program and expect a usable result if you don't know what the program shall do and has not found a usable software structure.





Re: Visual Basic Express Edition Counter question

shounenbat

i used two timers because

1. the 1st timer serve as look out to the pulse and it has an interval of 1ms

2. while the 2nd timer has an interval of 1000ms








Re: Visual Basic Express Edition Counter question

Carsten Kanstrup

As I told you, timer ticks (WM_TIMER message) have very low priority, so a timer tick may easily be delayed 50-100 mS. When this happenes, you will read the input state many times immediately after each other and may loose many edges. You will never get a good accuracy that way. That's why I suggested you to use one of the serial port inputs instead, which can raise an event each time the signal changes state. In this way, you will not loose any edges and will not boost the CPU load close to 100%.

Since you have not answered my basic five questions and don't read what I write, it is quite obvious that you don't want to play it my way, so I will leave you now.

Good luck with the project.





Re: Visual Basic Express Edition Counter question

shounenbat

there are no specific readings per second. the goal of our project is to read only the rpm of the motor.