Rising edge counting with an HSC ACC in every 100 pulse in the MicroLogix 1400

Asefakaratas

Member
Join Date
Jan 2019
Location
Istanbul
Posts
28
Hi everyone first of all.
This is first question in the forum. I am using HSC application. I'm reading A and B pulse count.
1 round of the motor : 36000 pulse
And, I want to read a sample from the sensor in every 100 pulses. That means 360 samples in 36000 pulse. But I have a problem. When I use a comparator, I can't keep up with the speed of the Accumulator.
Example; Counter is 72000. So 720 sample. When HSC start I need 720 rising edge. But not fast. What can I ? Does interrupt work ? If yes How ?
 
Hi everyone first of all.
This is first question in the forum. I am using HSC application. I'm reading A and B pulse count.
1 round of the motor : 36000 pulse
And, I want to read a sample from the sensor in every 100 pulses. That means 360 samples in 36000 pulse. But I have a problem. When I use a comparator, I can't keep up with the speed of the Accumulator.
Example; Counter is 72000. So 720 sample. When HSC start I need 720 rising edge. But not fast. What can I ? Does interrupt work ? If yes How ?

I have not used the HSC, but I remember a description of an OUTPUT from the HSC that you can program for every so many counts. But I think you need to reset the counter from your program, which would make your interrupt not be every 100 counts.

The Output could be used to trigger the interrupt, I think.

I think what you are asking is possible, but I don't have any hardware or any recent knowledge (last time I used a high speed counter was on a PLC5)
 
You should be able to set the High Preset to the number of accumulator counts at which you want to trigger the interrupt program to run. You would set the HSCx.PFN to the Program File Number and when the ACC reaches the high preset, that program will run. This also depends on having the HPM (high preset mask) set to "1".

If you need this to happen every 72000 counts, you may also want to set the overflow to that same value. If you need the pulse count to also accumulate to some other higher value that your sample rate, then you may need to use the interrupt program to recalculate the high preset so that you can leave the overflow value where you want to ultimately roll over and still do your sample processing at the correct intervals in between.
 
You should be able to set the High Preset to the number of accumulator counts at which you want to trigger the interrupt program to run. You would set the HSCx.PFN to the Program File Number and when the ACC reaches the high preset, that program will run. This also depends on having the HPM (high preset mask) set to "1".

If you need this to happen every 72000 counts, you may also want to set the overflow to that same value. If you need the pulse count to also accumulate to some other higher value that your sample rate, then you may need to use the interrupt program to recalculate the high preset so that you can leave the overflow value where you want to ultimately roll over and still do your sample processing at the correct intervals in between.

Thanks for answers thingstodo and OkiePC.
I have not problem about HSC. I need 360 shot rising for 1 round pulse value. You said interrupt. How can I use interrupt ? I'd appreciate it if you could help.

Equal function not fast. In the picture below

OvNP25.jpg
 
The interrupt is all done in the HSC subsystem. You must "fill in the blanks" by populating the HSC:0.PFN with the file number (ladder logic file number) that you want to be called when any of the HSC triggered interrupts are true. You then put the code you want to execute in that ladder file. Be aware that it will only scan once per interrupt, so code it accordingly.

You will also enter the values you need to trigger the interrupts like: HSC:0.HIP (high preset), HSC:0.LOP (low preset), HSC:0.OVF (Overflow), HSC:0.UVF (Underflow). and set their associated mask bits for those you wish to trigger the interrupt.

You will also need to set the HSC:0.CE and HSC:0.UIE bits to enable counting and enable the user interrupt respectively.

After changing any of these values, you will need to set the HSC:0.SP (set parameters) bit so that the PLC will update the HSC subsystem with the new values.

The only working examples I have are simple flowmeter pulse counters (Mode 0) and I haven't used the interrupt feature, so my HSC.PFN file is an empty routine. The Micrologix 1400 Instruction Set Reference should cover all of this pretty thoroughly, but there is nothing better than a real life trial to help you get a firm handle on it.

HSC.png
 
The interrupt is all done in the HSC subsystem. You must "fill in the blanks" by populating the HSC:0.PFN with the file number (ladder logic file number) that you want to be called when any of the HSC triggered interrupts are true. You then put the code you want to execute in that ladder file. Be aware that it will only scan once per interrupt, so code it accordingly.

You will also enter the values you need to trigger the interrupts like: HSC:0.HIP (high preset), HSC:0.LOP (low preset), HSC:0.OVF (Overflow), HSC:0.UVF (Underflow). and set their associated mask bits for those you wish to trigger the interrupt.

You will also need to set the HSC:0.CE and HSC:0.UIE bits to enable counting and enable the user interrupt respectively.

After changing any of these values, you will need to set the HSC:0.SP (set parameters) bit so that the PLC will update the HSC subsystem with the new values.

The only working examples I have are simple flowmeter pulse counters (Mode 0) and I haven't used the interrupt feature, so my HSC.PFN file is an empty routine. The Micrologix 1400 Instruction Set Reference should cover all of this pretty thoroughly, but there is nothing better than a real life trial to help you get a firm handle on it.

Thank you for your answer and your interest.

I tried the application I mentioned. I tried the got sample a in every 400 pulse. So 90 samples are in 36000 pulse (1 round)
But, I got sample 88 pieces. When accumulator started the count, if equal the every 400 pulse, accumulator is reset. (HIP : 400) If HIP value is equal to or greater than accumulator, HPR bit is get 1 . So, 90 shot rising for 36000 pulse. But, Missing 2 samples.


 
Okay, you have a JSR in the MAIN ladder file that is calling the same routine (file 3) that you have set up for interrupts assigned to HSC1. Remove that JSR. The HSC subsystme will call file 3 each time one of the interrupt conditions occurs as long as its corresponding mask bit is set.

You also have configured LAD 4 as STI file with a 10ms interval. LAD 4 will run every ten milliseconds. You also have a JSR to file 4 in your main program. You do not need that JSR. It will cause file 4 to run additional times.

There is no code in LAD 3 to process the "sample". I think that you have the code in file 4. You should put the logic you need to run in file 3. I don't think you need the STI routine at all. You want to perform an action based on the encoder position, and the HSC interrupt (file 3) will do that.
 
Okay, you have a JSR in the MAIN ladder file that is calling the same routine (file 3) that you have set up for interrupts assigned to HSC1. Remove that JSR. The HSC subsystme will call file 3 each time one of the interrupt conditions occurs as long as its corresponding mask bit is set.

You also have configured LAD 4 as STI file with a 10ms interval. LAD 4 will run every ten milliseconds. You also have a JSR to file 4 in your main program. You do not need that JSR. It will cause file 4 to run additional times.

There is no code in LAD 3 to process the "sample". I think that you have the code in file 4. You should put the logic you need to run in file 3. I don't think you need the STI routine at all. You want to perform an action based on the encoder position, and the HSC interrupt (file 3) will do that.

Thanks for your answer. I will inform you when I try in the office.
 
I worked on it for you

Have a look at the attached file. I took some liberty with how you are doing the indirect addressing to store the results. My changes might not match up with your goals, so that might need to be corrected.

I moved the stuff out of the STI file. I put things I didn't know what to do with in LAD 5.

I did away with your writes to the HSC1.acc. You shouldn't do that. It is better to let the counter roll over naturally. If you don't care about a long term pulse count, then set the overflow to your pulse interval and mask in the overflow to trigger the call to ladder 3. Writing to the acc runs the risk of causing it to miss pulses and is almost never necessary.

The way I rewrote it, recalculates a fresh HIPreset value each time the routine is called and deals with rollover if it should end up higher than the Overflow.

One thing I just thought of, is that the acc may go negative if the underflow value is still at the default of negative 2 billion something. I didn't look at that. It would be best to set the overflow to an even multiple of your sample interval (in pulses) and set the underflow to zero.

I added some comments and logic to the first rung in the main.

My comments are in English, so if there is confusion, let me know.

Hope this helps.
 
Last edited:
Just a few thoughts that may help you
You sais that you are using an encoder
1 round of the motor : 36000 pulse
If I understand it your encoder delivers 36,000 pulse per motor rev.
Just how fast are you running the motor
36,000 ppr on any encoder is a lot I have seen 10,000 but I have never heard of 36,000 ppr.
You say you are using channel A and Cannel B for you inputs
There are many possible configurations for the counter but using 2 channel you have A + B and Quad
With A+B the number of ppr is 2 X 36,000 = 72,000 the counter counts the leading edge of both Channel and Channel B
With Quad input number is 4 X 36,000 = 144,000 the counter counts both the leading and the trailing edge of each channel both A and B
If you are using a standard 4 pole motor at base speed you have 36,000 X 1,800 = 64,800,000 ppm /60 sec = 1,080,000 HZ and that’s without 2 or 4 multiplier that you appear to be using.
The built in High Speed counter is only rated for 100,000 HZ at most. Form what I see you are not even counting all the encoder pulses to start with and there is just no way to count them with what you have.
Depending on the motor speed you could try to use just channel A and count up only but even at that you still would neo be able to count all the pulses if the motor runs at near base speed.
That’s only half the problem
You still need to run the subprogram.
On the 1400’s the programs execute one at a time the main program calls subprograms but while the subprograms are running the main program is on pause ( Stopped ). The total execution time of the all programs will depend on the actual time required to complete the main program and all subprograms called during that task. From what I can see you have a lot of subprograms in program tree. They will take a long time to complete all tasks before you can restart at the beginning.
Even if you added a HSC expansion module you still may not be able to do what you want
The HSC expansion module is still only good for 1m HZ max so even with your encoder and a base speed of 1800 rpm you would not be able to count all the pulses on just channel A.

If you figure out how to accurately read the pulses from the encoder. The way to set up the counter to use one of the internal outputs set the preset to the 100 counts you want . Then use that counter output to trigger an interrupt the interrupt will call the subprogram to need to use move you data.
Just remember you can use the interrupt multiple times but each time you run the subprogram you add to the total scan time of the processor. You may not be able to executer the program fast enough to do the job.
You should consider moving this project from the 1400 to a compact logic processor their processors run much faster and can handle multiple tasks at a time.
Sorry about the length of the post but there is a lot to cover.
 
Have a look at the attached file. I took some liberty with how you are doing the indirect addressing to store the results. My changes might not match up with your goals, so that might need to be corrected.

I moved the stuff out of the STI file. I put things I didn't know what to do with in LAD 5.

I did away with your writes to the HSC1.acc. You shouldn't do that. It is better to let the counter roll over naturally. If you don't care about a long term pulse count, then set the overflow to your pulse interval and mask in the overflow to trigger the call to ladder 3. Writing to the acc runs the risk of causing it to miss pulses and is almost never necessary.

The way I rewrote it, recalculates a fresh HIPreset value each time the routine is called and deals with rollover if it should end up higher than the Overflow.

One thing I just thought of, is that the acc may go negative if the underflow value is still at the default of negative 2 billion something. I didn't look at that. It would be best to set the overflow to an even multiple of your sample interval (in pulses) and set the underflow to zero.

I added some comments and logic to the first rung in the main.

My comments are in English, so if there is confusion, let me know.

Hope this helps.

Dear OKiePC and GaryS
Thanks for answers !

I will not use HSC:ACC. You said It is better to let the counter roll over naturally. You are right. I guess that was my fault.
But How can I get sample a in every 400 pulse. ? (90 sample and 90 rising edge for 36000 pulse)If I get 90 rising edge when accumulator count started. Enough for me (for 36000 pulse)


It is 1:36 reductor in the system.
36 round : 36000 pulse read ( Speed for 36 round of the motor (second) : 3.5 s )
I need to read for 36 round. I'm reading 335 sample, when I read in a every 100 pulse. Missing 25 samples

I guess, It has problem due to speed read.
 

Similar Topics

I have a FX3U clone that I am failing to get a simple Structured Text example working on and would really appreciate some help. I created a...
Replies
30
Views
928
Hi all, Does any body know what the rising edge code is for GX Works in structured text. I have several manuals but can't find anything relating...
Replies
9
Views
2,559
Hi All, Does anyone of you know what is the function of rising and falling edges? I essentially want to trigger a timer once the state of a coil...
Replies
8
Views
4,744
i need to capture the time between the rising edge of 1 pulse and the rising edge of the next pulse after it. i have a flow meter that gives a...
Replies
16
Views
5,095
Hi! Anyone can share example of GE Proficy Rising Edge Structured Text? I have found text as below InstanceOfR_TRIG( CLK := inBool, Q =>...
Replies
6
Views
2,943
Back
Top Bottom