generating pulses
stef
Posts: 173
Hi
I'm trieing to generate pulses on an outputpin with some strickt timing. Every 2 mS (millyseconds)· a puls with a duration off 50 µs (micro).
Is this possible. I already tried but I have no scoop to verify and I think the timing is wrong.
I'm running on 50 Mhz.
stef
I'm trieing to generate pulses on an outputpin with some strickt timing. Every 2 mS (millyseconds)· a puls with a duration off 50 µs (micro).
Is this possible. I already tried but I have no scoop to verify and I think the timing is wrong.
I'm running on 50 Mhz.
stef
Comments
Otherwise an interrupt is probably the easiest.
'
OutPin PIN RA.0 OUTPUT
counter VAR Byte
INTERRUPT 20000 ' 20000 = 50uSec
· INC counter
· IF counter = 40 THEN
··· OutPin = 1
····counter = 0
· ELSE
··· OutPin = 0
· ENDIF
· RETURNINT
'
or with the SX48
'
OutPin PIN RB.6 OUTPUT ' Must use pin RB.6 for Timer1 output
TIMER1 PRESCALE, 1 ' 1:2 Prescale (timer counts @ 25Mhz)
TIMER1 PWM, 1250, 50000
'
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1
"People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
Post Edited (Bean (Hitt Consulting)) : 11/27/2006 11:18:03 PM GMT
I'm using an sx28. So i need to go for the interrupt routine. (I think)
Thanks for the example.
What I understood from it is that the interrupt routine is triggerd every 50µs. The code folowing I understand. But can·i stop with code at a certain point the interruproutine. I like for exaple start pulsing when an other pin is high an stop pulsing when it is low.
stef
Sure just change "OutPin = 1" to "OutPin = InPin".
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1
"People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
·
So if I change the pin I use for pulsing to input the interuproutine is not called anymore. Sounds bizar our did I understoud it wrong.
The interruptroutine is called on an internal timer. I thouth that that timer is not influenced by a in our output.
Is thier a way to just stop the timer. Something like "TIMER OFF"
stef
No, the "OutPin = InPin" does not change the output pin to an input pin. It simply sets the output pin to the same state as the input pin. That is if the input pin is high, then the output pin will be set high. If the input pin is low, the output pin will be set low.
To turn the interrupts "off" you need to set the OPTION register manually instead of using "INTERRUPT 20000".
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1
"People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
·
I'm not the greatest, but I'll throw in what I know.
Sounds like you have MyInputPin and MyOutputPin. You want the pulses on MyOutputPin only while MyInputPin is high.
I don't know of a way to turn on and off execution of timed interrupts at run time if you are using teh INTERRUPT RATE directive.
So I would keep running the ISR every 20 mSec and within there either send a pulse or not depending on state of MyInputPin
' ** untested **
INTERRUPT 500
ISR_Start:
IF MyInputPin=1 THEN
PULSOUT MyOutputPin,5 ' units by default are 10 uS
ENDIF
ISR_Exit:
RETURNINT
>>>>>>>>>>>>>>>>>>>
Alternately you could not set RATE and instead code the RTTC with prescalar. I think that call for ISR can be turned on and off at run time by setting the Option bit 6.
Thank for the info but is the option regeister manual adjustable in sx basic.
In I use interrupt 20000 it is configuring the complete register. Can I only set the bit to turn it on and off??
Stef
·
Thanks for this alternitive way.The problem is that the puses need an exact timing.
Every 2 mS (millyseconds)· a puls with a duration off 50 µs (micro).
Is the pulsout command capable of this??? and how exact is that.
Yes you are correct when saying that I only want to puls when I set the input high. I even want to add something that I need
to use a variable that specifies the amount of pulses.
Exampel : I want to send 10 pulses out when I set the imput high. Than I set the imput low and changes the variable to 7 . If I set the input back again high i want to send 7 pulses and stop again pulses.
That eventualy what I want to set that up. The device that is connected to the sx is reakting in binair strings.
I just what to know if it is possible and start with a litle hind (like you examples)
I'm just a beginner but my first project wend well (reading wiegand data) that now I 'm interested in doing more.
But i still need to lurn a lot.
stef
·
It would probably be easier to just send the pulses manually.
howMany = 10
FOR cnt = 1 TO howMany
OutPin = 1
PAUSEUS 50
OutPin = 0
PAUSEUS 1950
NEXT
Depending on how accurate you need you may need to lower the PAUSEUS values slightly to get it exact.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1
"People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
·
Bean's suggestion is best.
To directly answer your questions:
>Every 2 mS (millyseconds) a puls with a duration off 50 µs (micro).
>Is the pulsout command capable of this??? and how exact is that.
Pulsout does not address the time between pulses (interval). It only sets the duration (width) of the one pulse it is sending
You can set the interval as follows:
- An interupt that fires every interval of time and contains one pulsout
- A pause of interval length between pulsouts
>Exampel : I want to send 10 pulses out when I set the imput high. Than I set the imput low and changes the variable to 7 .
> If I set the input back again high i want to send 7 pulses
Either technique for creating the interval can use a variable for the duration of the pulse. That variable can be set by sensing your input pin.
> ... and stop again pulses.
You can send or not send pulses by two stratigies:
- You can run the interrupt every 20 mS and within the interupt check the input pin to decide to send or not send a pulse
- You can make a loop in your non-ISR program that checks the input pin and decides to create a set of pulses with PAUSE for intervals
The first is better if you don't need the ISR for other purposes or if you will frequently be sending pulses
The second is better if your ISR is already occupied with another timing or if your sending is occasional
Thanks for the explanation. I'm working on the projekt an use one of the sollutions.
Thanks
Stef