Help COUNTing delay /w BS2 and 555 timer
Justin_C
Posts: 9
Quick project abstract: I am using some BS2s, a PLC, some CTs, and other misc equipment to function as a digital overcurrent relay for a simulated grid.
In order to confirm the experimental accuracy of the inverse-time characteristic (closely modeled after a CO-8 relay), I need to be able to see how much time has elapsed between the time a fault is detected and the time the circuit breaker is ordered to open.
A HIGH signal will be sent out from the first BS2 saying that a fault is detected. A second BS2 will then count pulses from a 555 timer in astable mode as long as that initial signal remains HIGH (that is, the delay is complete and the command to open the circuit breaker is being issued).
The problem is that the COUNT command needs a specific duration to count for. In my situation, the duration will be different depending on how much/little the fault condition is. My current work-around for this problem is to invoke the COUNT command in 100mS increments, then check to see if the signal from the first BS2 is still set to HIGH. If it is still set to HIGH, go back and invoke the COUNT for another 100mS and keep a running total. If the signal is NOT set to HIGH, convert the pulses into time and display it.
I am running the 555 timer in astable configuration with a frequency of around 1kHz and a duty cycle of about 60%. For some reason, I am not able to count the pulses. I had the program working at one time with a frequency of about 40 Hz but that will not be fast enough. I am beyond the HIGH state duration that the COUNT command needs and well below the maximum allowed frequency. Also, I have verified the frequency/duty cycle of the 555 timer with an oscilloscope so I know thats not the problem. Any suggestions? Thanks in advance!
CODE ATTACHED
In order to confirm the experimental accuracy of the inverse-time characteristic (closely modeled after a CO-8 relay), I need to be able to see how much time has elapsed between the time a fault is detected and the time the circuit breaker is ordered to open.
A HIGH signal will be sent out from the first BS2 saying that a fault is detected. A second BS2 will then count pulses from a 555 timer in astable mode as long as that initial signal remains HIGH (that is, the delay is complete and the command to open the circuit breaker is being issued).
The problem is that the COUNT command needs a specific duration to count for. In my situation, the duration will be different depending on how much/little the fault condition is. My current work-around for this problem is to invoke the COUNT command in 100mS increments, then check to see if the signal from the first BS2 is still set to HIGH. If it is still set to HIGH, go back and invoke the COUNT for another 100mS and keep a running total. If the signal is NOT set to HIGH, convert the pulses into time and display it.
I am running the 555 timer in astable configuration with a frequency of around 1kHz and a duty cycle of about 60%. For some reason, I am not able to count the pulses. I had the program working at one time with a frequency of about 40 Hz but that will not be fast enough. I am beyond the HIGH state duration that the COUNT command needs and well below the maximum allowed frequency. Also, I have verified the frequency/duty cycle of the 555 timer with an oscilloscope so I know thats not the problem. Any suggestions? Thanks in advance!
CODE ATTACHED
Comments
' {$STAMP BS2}
' {$PBASIC 2.5}
'binary long-division algorithm courtesy of
'http://www.emesystems.com/BS2math2.htm
'*****************************
'* Variable/Pin Declarations *
'*****************************
DataIn PIN 5 'square-wave pulse from 555 timer @ 1kHz
StartCount PIN 10 'signal that fault condition is detected
Pulses VAR WORD 'pulses counted from a signle 100ms increment
PulsesTot VAR WORD 'total counted pulses
index VAR BYTE
CountFreq VAR WORD '555 timer astable freq. of 1000 Hz
delayTime VAR WORD
numr VAR WORD 'numerator in binary long-division
deno VAR WORD 'denominator in binary long-division
intg VAR WORD 'integer result of binary long-division
frac VAR WORD 'fractional result of binary long-division
'***************************
'* Variable Initialization *
'***************************
delayTime = 0
CountFreq = 1000 '555 timer astable freq. of 1000 Hz
Pulses = 0 '555 pulse count of each 100mS increment of COUNT command
PulsesTot = 0 ' running pulse-count total
Main:
DO 'check to see if pulses must be counted
GOSUB CountCheck
LOOP 'forever!
CountCheck:
IF StartCount = 1 THEN 'if pin is set to HIGH, count pulses
GOSUB CountTrip
ELSE '...otherwise go back to main and check again
ENDIF
RETURN
CountTrip: '%% counts pulses from 555 timer %%
COUNT DataIn, 100, Cycles 'counts pulses for 1/10th second increments
PulsesTot = PulsesTot + Pulses 'accumulates all pulses counted
IF StartCount = 1 THEN 'checks to see if pin is STILL set to HIGH
GOSUB CountTrip 'it it is HIGH, count pulses for another 1/10th second
ELSE '...otherwise break from IF-ELSE statement and display the elapsed time
ENDIF
GOSUB DisplayTrip
RETURN
DisplayTrip: '%% converts pulses to time and displays the result %%
'%% Binary Long-Division to convert pulses to time in Sec %%
' ' ' ' ' ' ' ' ' ' ' ' '
numr=(PulsesTot) '
deno=(countFreq)-1 '
intg=1-(numr.BIT15 ^ deno.BIT15*2) '
numr=ABS nurm '
deno=ABS deno '
intg=numr/deno*intg '
FOR index=15 TO 10 '
numr=numr//deno<<1 '
frac.BIT0(index)=numr/deno '
NEXT '
frac=frac**10000 '
'** ' ' ' ' ' ' ' ' ' ' ' '
DEBUG HOME, CLS, "Trip Time in Sec: "
DEBUG DEC intg, ":", DEC frac
RETURN
· When the stamp is required to do some other work while tracking pulse inputs, I've found 40 - 60 Hz is about the limit. In your case, you could move up to a BS2sx or BS2px to get better speed.
· Or, feed the 555 output into a counter chip during the timing interval. When the interval is over, the stamp can read the counter at its leisure and not have to worry about missing a pulse.
·I've attached some info on a lumber tally system where I used your technique to measure board width in a sawmill. In my case, the pulse stream was generated by an encoder. Two 4024 counter chips counted the pulses during the measuring interval, then the stamp looked at the counter output when the board had passed.
· Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
Thank you very much for posting your project, I really appreciate it.
This is my first experience for the stamp and while it is quite flexible, I quickly ran found out the speed limitations. Unfortunately, I already have the BS2 and am limited to around 40 Hz. My advisor for my project said this is okay as it still gets the point across without having to spend any more money.
In order to read the counter output, would you recommend a parallel to serial shift register? I dont have the pins available to read all of the outputs directly into the stamp.
Thanks again,
Justin
There is an application note on measuring time intervals with the Stamp here. It uses program loops to get a resolution of better than one millisecond.
There is no reason you could not use COUNT in the manner you suggested in 100ms intervals. However, the program you posted is recursive, in that the CountTrip subroutine calls itself with GOSUB, and that is a no-no on the Stamp. GOTO instead. Or put it in a DO:LOOP.
In any case, I don't think the 555+COUNT is really the best solution. The second Stamp should be able to achieve the required 1ms resolution on its own using a program loop or by using a series of RCTIME commands in a loop like this:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
The shortest time interval I will experience will be on the order of a few hundred milliseconds (around 200-ish).
Hmm...I never really gave using RCTIME serious consideration as I wasn't sure of the accuracy that could be achieved by it. I will agree, the 555 solution has not been very successful; most likely due to delay/lack of accuracy. Also, the 555 requires more external circuitry, which is always nice to avoid [noparse]:)[/noparse]
I just got to the lab and will post my progress (or lack thereof) once I give your RCTIME technique an honest effort.
I sincerely appreciate your input, it's been hard to come up with new ways of attacking these problems since I am such a stamp-noob!
Justin
The shift register idea will work to read multiple bits. I think I used 4 inputs to read either 8 or 10 bits of counter outputs by using multiplexing chips. 74ls125. You can check on the schematic I posted.
Good luck.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
Two quick questions about the RCTIME implementation to make sure I'm understanding its operation:
[noparse][[/noparse]1.] Will a standard RC circuit (such as the one shown in the manual) work with the input signal from the first BS2 to charge that circuit? (I dont need to explicity set the pin to high for whatever duration to ensure RCTIME works correctly if I used a short time-constant for the RC circuit)
[noparse][[/noparse]2.] Since the 'rollover' variable is accumulating pulse-widths (with are 131.07 mSec in duration) while 'cycles' is counting the discharge time of the RC circuit in 2 uSec intervals, I can just multiply/divide those values by the corresponding scaling factors to get the time elapsed?
Thanks again!
Justin
Right, to convert to commensurate units of milliseconds, mS = (rollovers * 132) + (cycles / 500). There are little things you can do to tweak the formula for best accuracy.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I have it working! (for the most part)
Tracy, I would like to really thank you for all of your great work for the STAMP community (especially the math section on your site) and your help via these forums. I attribute most of my STAMP learning outside of the manual to what I found on your site. I truly, truly appreciate it!
I'll post up my results of the entire project once I wrap it up this weekend.
Justin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thanks
Ted