Jump to content

Digital input impulse counter with interrupt


Recommended Posts

Hello

I'm using V700  with 18E3/4XB and trying to make impulse counter without using high-speed input

The problem is, input frequency is about 400Hz. Input pulse is always meander

So, the question is: is that possible to make it with 1.25ms interrupt + immediate read physical input? Just put positive transition contact with increment of some integer

I was thinking, that with 400hz/s i have circle time 2.5ms, with duty cycle 50% i react on every impulse.

So, frequency 400Hz is my maximum without errors

Is that possible to create and organize or am i missing something?

Link to comment
Share on other sites

  • MVP 2023

Typical standard input response time = 10ms ===> 100Hz.

Interrupt and immediate read used for make program read rate faster.

But maybe standard input response do not possible to do faster with this method.

You have two HSI (HSC) channel on board. Maybe rewire application to this input is possible. 

Link to comment
Share on other sites

18 hours ago, kratmel said:

Typical standard input response time = 10ms ===> 100Hz.

Interrupt and immediate read used for make program read rate faster.

But maybe standard input response do not possible to do faster with this method.

You have two HSI (HSC) channel on board. Maybe rewire application to this input is possible. 

Thank you for the answer

In manual for E4XB i've read, that responce time for I0-I3 is 10mSec, but for I4-I17 is 2mSec
Unfortunately, my inputs I0-I3 are busy with shaft encoders, i have some free inputs, so i decided not to add expansion module only for high-speed input and try to make it the way i described before

Link to comment
Share on other sites

  • MVP 2023

Pavel...same as louis elsewhere, I deleted all the repeated copies of the above post that you had done. 

You were likely thinking "Why didn't it come up?"  Well......all posts on this forum are subject to moderation.  This is mainly done by a few volunteers scattered around the globe, so sometimes it can take a few hours at least.

cheers, Aus

Link to comment
Share on other sites

2 hours ago, Ausman said:

Pavel...same as louis elsewhere, I deleted all the repeated copies of the above post that you had done. 

You were likely thinking "Why didn't it come up?"  Well......all posts on this forum are subject to moderation.  This is mainly done by a few volunteers scattered around the globe, so sometimes it can take a few hours at least.

cheers, Aus

Sorry, did not see i double-posted, just had issues with posting answer, refreshed page few times, did not see my reply and decided to post it, but forum decided to post it twice :)
Thanks

Link to comment
Share on other sites

  • MVP 2023
On 5/19/2020 at 5:12 AM, Pavel M said:

So, the question is: is that possible to make it with 1.25ms interrupt + immediate read physical input? Just put positive transition contact with increment of some integer

@Joe Tauser (I think?) posted something on this recently but I can't find it now. Perhaps he'll drop back in.

Link to comment
Share on other sites

  • MVP 2023

Pavel, I think lots of referencing is to my solution for something similar.  But I am not sure it will work ok given that you say " input frequency is about 400Hz. Input pulse is always meander".  The maths on this statement means that 1.25ms is going to be very close to the line on doing things accurately, especially if the pulse is not the same length.  If 400Hz is the absolute maximum you may get away with it.  The only true check would be trial and error.

Here is the link. I suggest that you also read the entire topic for background.

cheers, Aus

 

Link to comment
Share on other sites

14 hours ago, kratmel said:

Hi, Pavel M

What is needed in your application:

count  pulse or mesure frequency?

Hello, i need to count pulses, when i get the amount of pulses i need - i take some action, reset this counter value and probably, change my target counter, but the frequency with which these pulses are given is different, i mean, 400 pulses/s is maximum and it is not always 400, most part of time this frequency would be less, so i guess, i can handle that and even if i get some error, it won't be critical.

Thank you everyone for answers!

Link to comment
Share on other sites

  • MVP 2023
On 5/20/2020 at 9:28 AM, Flex727 said:

@Joe Tauser (I think?) posted something on this recently but I can't find it now. Perhaps he'll drop back in.

Where has the time gone....?  I haven't looked at the forum for a couple of days.  Must have been in some kind of CoronaComa.

Anyway, yes, you should be able to get near 400 Hz with the 1.25 ms interrupt routine.  Don't forget to put your counting logic in the routine as well, as just reading the input doesn't guarantee that the main program will see it.

My usual response- write some code and upload your program so we can see what you're doing.  This does NOT mean screenshots.

This thread has followed the usual path of wandering posts postulating about what may work.  Engineers and Programmers (often the same thing) these days seem to want to avoid the real solution to the problem - hook it up with the proper tools and see if it works.  The proper tool here is an oscilloscope monitoring the pulses while you look at it online, which will give you concrete information as far as pulse widths and frequencies.

General rant directed at the community--

"But my boss won't buy me a scope!"   This is a cop-out.  Invest in yourself - a USB scope with the bandwidth required for PLC work is less than $100 on Amazon.  What does that cell phone cost you?

Joe T.

 

Link to comment
Share on other sites

  • MVP 2023

I don't know, maybe  it will help ...
I would advise the author to turn his PLC into a test bench for a while.

1-step
Set a high-speed output (O0 or O1) with PWM function in the configuration and make it possible to change the parameters (Duty Cycle and Frequency)  of this output on the screen.  Also start-stop buton on screen and PWM run bit ladder logic needed. You can build automatic frequency increment with fixed step from 0 to the 1000Hz for example.

2-step
Use wires to send a signal from this output to the input that the author wants to turn into a counter.

Step 3 - Write the counter code with an interrupt with the result displayed on the screen and setup RESET button.

4-step
Add a standard high-speed input to the configuration. Connect it to the same PWM output via wire.

5- step

Add a code that will count the pulses via HSC and show their number on the screen (also frequency is possible to mesure via hardware HSI). RESET button needed also.

6-step
Reset both counters, start the output at the specified frequency and duty cycle or use automatic frequency increment .

Next, see at  the frequency and check  when the counter with an interrupt will not have time to count. It can be evaluated by stop output when  INTcount not equal HSCcount

Make some investigation with duty cycle parameter change also.

 

The last step - disconnect simulated by PLC signal and connect real signal.  Take a few different tests.

It is interesting to see the results in this topic.
Unfortunately, I do not have such a 18E3/4XB module at hand for experiments.

 

 

Link to comment
Share on other sites

Hello, so i tried to organize PWM on my output and put it on my digital input

Duty cycle is always constant - 500 (my meander)

So, with cycle time 8, i get +25 in my memory integer (50Hz)

With cycle time 4 i get +50 in my memory integer (100Hz)
When i change cycle time to 3 or less, i start to get errors (+50 all the time)
With cycle time 1 I get nothing at all
So, i guess, i'll need to buy expansion module with high-speed inputs

 

Interrupt.png

PWM_scan.png

Link to comment
Share on other sites

  • MVP 2023
6 hours ago, Pavel M said:

Hello, so i tried to organize PWM on my output and put it on my digital input

Please use hardware PWM out O0 or O1 configuration for test. Please delete PWM scan block from ladder. Using software PWM method gives incorrect results for your case.

Maybe ladder PWM generation is interrupted by immediate command.

PWM_hardware.jpg.aabb5f4d7830f108c942db787e38e614.jpg

Hardware PWM do not use CPU resorces for generation.

 

2 hours ago, Flex727 said:

Your V200-18-V3XB _HAS_ high-speed inputs.

It is used for shaft encoder in author project...  :(

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...