Ok,
Sorry I didn’t get back to my issue at hand. I was pretty bummed and just wasn’t feeling it yesterday.
Anyway…
I have two circuits that are identical. They are both clocked with a 60Hz, 50% duty, ~8.2mS pulse width +5 volt going square pulse. Low is 0V, high is 5V. They both need this signal all the time. So for now I’m just using a 12F675 to provide that signal.
With that clock signal running, the two individual circuits each output a +5V square wave of their own, which by itself on a scope, doesn’t look like much but a square wave.
But when you trigger a scope using the leading edge of the 60Hz, 50% duty pulse that the 12F675 is currently generating (and being provided to the clock inputs on the two circuits) and you have one of the other pulses on a second scope channel, you’ll see what is in my drawing, which shows just one circuits output for clarity.
You have the 60Hz pulse with the other square wave nested inside of it. And if you adjust that circuit’s control, the pulse can be moved in relation to the steady 60Hz pulse. The other circuit is identical and does the exact same thing. And yes, it can lead the other circuits pulse (not the 60Hz pulse, both other pusles are always inside of the 60Hz pulse!) or fall behind it, or be right on top of it.
My perfect solution for this would be:
1. Generate the 60Hz 50% duty signal on one pin. Always running. HPWM10 maybe?
2. Trigger a timer off of the leading edge of the 60Hz 50% duty signal (no clue, still haven’t messed with timers!!!)
3. Count until the leading edge of the pulse from the first circuit comes in on a pin, hold that number in a variable.
4. Repeat 2 and 3 a few times to build an average – hold that average in a variable.
5. Trigger a timer off of the leading edge of the 60Hz 50% duty signal
6. Count until the leading edge of the pulse from the second circuit comes in on another pin, hold that number in a variable.
7. Repeat 5 and 6 a few times to build an average – hold that average in a variable
8. Send the measurement from both average variables out via SEROUT.
The future plan is to find out exactly what numbers to expect by spitting them out via SEROUT, once I know the ranges and such, I would build a lookup table using SELECT CASE or something and if the shift in a signal falls within a certain value, send a command out serially. This would be done for both circuits
So: SEROUT serialPin, 4, [circuit1Data, circuit2Data…]
The only timing in this that is critical is the 60Hz pulse must always be there, steady, constant. And of course the measurement itself need to be fairly accurate, with my lookup table I’m planning on building in hysteresis(?) like of
circuit one's variable equals 225, my lookup would handle it as “if x = <230 AND <220 then” – or something like that just to cancel out minor errors.
The signals I am measuring only vary by user input (i.e. turning a knob) and are independent of each other and will be handled by separate lookup tables, so measuring one before the other doesn’t matter, or if they both get measured at the same time. And seeing them change in any fine detail doesn’t matter either, So waiting on a routine to finish or something isn’t a big deal. Mainly its just getting an accurate measurement of the shift between the clock pulses leading edge and each circuits outputs leading edge.
I’d like to do this all on one chip if possible. I was trying to think in terms of the 16F648A because I have them on hand and have used them quite a bit. I’m trying to stay away from having more pins than I need, so I really don’t want to have to use an 18F4550 or something. So if there is something around the same pin count as the 16F648A that can do all this in one chip, great. If not, I can live with the 12F675 and two 16F648A I guess.
As always, thanks to all of you for helping me out!
Respectfully,
Ryan
![]()
Bookmarks