PDA

View Full Version : positive going edge trigger?



rossfree
- 11th January 2005, 11:46
Hi all,

I'm working with PicBasic Pro on a timing issue. My current program watches for a low pulse on a pin. The pin is normally high. The negative going edge trigger starts a timming cycle.

But I'd like to start the timming cycle on it's positive going edge. The pulse is probably long enough to write several lines of code to accomplish this but I thought there was a simple command in PicBasic Pro that would look for a positive going edge. I want to start the timming cycle at the end of the pulse.

Any thoughts?

Thank you,

Ross

mister_e
- 11th January 2005, 15:30
Hi Ross,

There's many many many way to accomplish this task. By using a simple IF Then, While loop, or waiting for an Interrupt. These interrupt can be selected on different port with often rising or falling edges. Tell us wich PIC you want to use and we will be able to tell you what are your Interrupt option.

Bruce
- 11th January 2005, 17:21
X VAR BYTE

SYMBOL P_In = PORTB.0

PULSIN P_In, 1, X

' Start timing cycle here

PULSIN starts counting on the positive going edge, and stops on 1 to 0 transition allowing you to start your timing cycle after the high-going pulse starts & ends.

You can just discard the result returned in X if you don't need it.

rossfree
- 11th January 2005, 17:34
Thank you Steve,

I am aware of multiple ways around the barn. I just didn't know if there was a direct path through the barn... a command that allows you to set execution on the positive or negative going edge of a pulse. I couldn't find such a funciton in PBP but thought I might have overlooked it so I posed the question.

I am satisfied with my solution and it only added a couple lines of code. Easy enough.

The project I am working on uses a slave microcontroller to control pulses to a heater (through an alternistor). The zero-cross detector senses when the AC wave form crosses zero and outputs a pulse to the slave. The slave then outputs a pulse to the triac after a variable pause. But the zero-pulse came about 200us before actual zero and ended 200us after zero. If I acted on the beginning of the pulse, then I could never output a pulse at actual zero without fear of missing the next zero-cross. The following snippet should solve that problem.

If it seems like I'm fussy about my controlling current right down to zero, it's because I'm trying to control many amps of current through three inches of nichrome ribbon (approx 1 ohm of resistance) and maintaining a set temperature. I'm trying to do it without a stepdown transformer. Don't know if I'll get there but I just have to try. :-) Can you say "welding transformer"? :-)

I am receiving 400us pulses every 8ms. The trailing edge of the pulse is in the positive going direction. Portb is constantly updated with the required power (in one byte). The following waits for the pulse, then waits for the positive going transition to execute.

wait_for_pulse:
if portc.2 = 1 then goto wait_for_pulse

wait_for_positive_edge:
if portc.2 = 0 then goto wait_for_positive_edge
pauseus 8276 - portb * 8
pulsout portc.4,45 'fire alternistor
goto wait_for_pulse
end

Thank you Steve for getting back to me!

Ross

rossfree
- 11th January 2005, 17:41
Yep... that'd do it!

Ha!

Ross