Shorter wait time than OSTimeDly?
Posted: Tue Jan 10, 2012 5:00 pm
95% of this post is explanation that is not necessary to answer the question but it gives background as to why I have the question. If you want to skip it all, the question is in the last paragraph.
I have a 5270 that is connected to a rather simple circuit. The circuit takes a digital input to switch a low current circuit which, in turn, switches a high current circuit. The response time on each of these switches is in the range of nano-seconds but there is still a delay. The way this works is the 5270 switches this circuit on and, if the circuit is complete, a current detection pin on the 5270 detects the complete circuit. As a precautionary measure, I have the 5270 measure current without switching the circuit on to make sure it comes up low, signifying that there are no short circuits. Then it switches the circuit on and measures current to see that it is high, so there is a complete circuit. Then it switches the circuit back off, checks that the current detection pin is low to insure that the circuit is still in operating condition. If all three of these conditions are met, it returns a positive test result. To help explain this a little better, here's the code for a test function:
J2[13] is the current detections pin, J2[15] is the pin being switched on and off. a is the test result: 0 = fail, 1 = pass.
Each time the circuit is switched, on or off, I have to include the OSTimeDly(1) so the circuit has time to respond before Pin 13 takes a reading.
My current TICKS_PER_SECOND is set to 20 so each test takes about 3/20 of a second or 0.15 seconds. The circuit takes about 600 nanoseconds to respond or 0.0000006 Seconds. So this entire test process could be completed in 1800 nanoseconds as opposed to 0.15 seconds.
Normally this would be negligible but one single test procedure could test upwards of 4000 of these circuits. With the current test code I have, that's 10 minutes or more. When it could be as short as 0.008 seconds to test all 4000 of them, neglecting any external calls that need to be made to perform the test.
I've done the math and, if it's correct, a 147MHz processor (the one on the 5270) can wait about 80 cycles for this circuit to react before testing for current. So there should be a way to program a wait code in that is shorter than 1/20th of a second.
So this may be a pretty simple question, but is there a way to make a program on my 5270 wait for a shorter time period other than using OSTimeDly? Preferably code that would run off of the processor clock as opposed to an OS timer. I mean, I know I can change my TICKS_PER_SECOND, though I'd rather not because it is handy in other parts of my code as 20 per second. So short of doing that or creating a function that has the processor add 1+1 100 times, is there an easier way to create a shorter delay?
I have a 5270 that is connected to a rather simple circuit. The circuit takes a digital input to switch a low current circuit which, in turn, switches a high current circuit. The response time on each of these switches is in the range of nano-seconds but there is still a delay. The way this works is the 5270 switches this circuit on and, if the circuit is complete, a current detection pin on the 5270 detects the complete circuit. As a precautionary measure, I have the 5270 measure current without switching the circuit on to make sure it comes up low, signifying that there are no short circuits. Then it switches the circuit on and measures current to see that it is high, so there is a complete circuit. Then it switches the circuit back off, checks that the current detection pin is low to insure that the circuit is still in operating condition. If all three of these conditions are met, it returns a positive test result. To help explain this a little better, here's the code for a test function:
Code: Select all
int Test_01(int a){
a = 0;
J2[15].clr();
OSTimeDly(1);
if(!J2[13]){
J2[15].set();
OSTimeDly(1);
if(J2[13]){
J2[15].clr();
OSTimeDly(1);
if(!J2[13]){
a++;
}
}
}
J2[15].clr();
return a;
}
Each time the circuit is switched, on or off, I have to include the OSTimeDly(1) so the circuit has time to respond before Pin 13 takes a reading.
My current TICKS_PER_SECOND is set to 20 so each test takes about 3/20 of a second or 0.15 seconds. The circuit takes about 600 nanoseconds to respond or 0.0000006 Seconds. So this entire test process could be completed in 1800 nanoseconds as opposed to 0.15 seconds.
Normally this would be negligible but one single test procedure could test upwards of 4000 of these circuits. With the current test code I have, that's 10 minutes or more. When it could be as short as 0.008 seconds to test all 4000 of them, neglecting any external calls that need to be made to perform the test.
I've done the math and, if it's correct, a 147MHz processor (the one on the 5270) can wait about 80 cycles for this circuit to react before testing for current. So there should be a way to program a wait code in that is shorter than 1/20th of a second.
So this may be a pretty simple question, but is there a way to make a program on my 5270 wait for a shorter time period other than using OSTimeDly? Preferably code that would run off of the processor clock as opposed to an OS timer. I mean, I know I can change my TICKS_PER_SECOND, though I'd rather not because it is handy in other parts of my code as 20 per second. So short of doing that or creating a function that has the processor add 1+1 100 times, is there an easier way to create a shorter delay?