Page 1 of 1

pulse out and slow simulate

Posted: Thu Jun 24, 2010 10:03 pm
by jimtr6
I want to send a pulse out of a pin on a port, like a one shot of fixed duration, I can do it with a 1 out, a delay, then clear the bit or go low, is there a pulse out command, or is it in C or Assembly I must do this, if so what would the syntax be, also can I do slow simulate when testing programs rather than step by step, thanks much

Re: pulse out and slow simulate

Posted: Fri Jun 25, 2010 8:27 am
by Sean
If you want an output to be automatically cleared a fixed time after is has been set, you will need to use a timer interrupt with the clearing code in the interrupt handler.

Set the output from the main program and enable the timer interrupt.

Clear the output from the timer interrupt handler and disable the interrupt.

Re: pulse out and slow simulate

Posted: Fri Jun 25, 2010 8:37 am
by Sean
Simulation speed can be controlled from the View -> Project options menu. Using the Simulation Speed setting.

Re: pulse out and slow simulate

Posted: Fri Jun 25, 2010 9:50 am
by jimtr6
thanks, but I'm unclear how to set a value for the timer, I want a 250 msec pulse out, so I set that pin, go to interupt and the direction there says TMR0, does this mean "timer = 0", where do I set a value to start the count down from to make it last 250 msec, is this a variable I must set somewhere? Another question is this, is the interupt called on by me putting it in the flow or am I only "enabling" it at that point, the simulate does jump to the macro so it appears enable means make it happen at that time.

Re: pulse out and slow simulate

Posted: Fri Jun 25, 2010 10:15 am
by Sean
TMR0 is the Timer0 hardware provided in the target device.

The interrupt rate is based on the master clock frequency and the selected prescaler. The calculated interrupt frequency is displayed on the interrupt properties panel.

You can turn the interrupt on and off as required, or leave it running continuously as a system 'tick'.

The interrupt handler can share variables with the main program, and you can allocate variables as counters to control delays that are multiples of the 'tick' period.

There is a brief description of the operation of a monostable timer in the 'MIAC electronic door lock' article in the Articles section of this forum.

Re: pulse out and slow simulate

Posted: Fri Jun 25, 2010 12:17 pm
by jimtr6
forget it, more confused than when I began, I'm new to this so not only am I learning basic programming but need to learn terminology and meanings, thanks for your help

Re: pulse out and slow simulate

Posted: Fri Jun 25, 2010 1:41 pm
by medelec35
If you want to keep it simple, then do what you have said, but create a macro. Within the macro have the pin high, delay 250ms, pin low.
Then just call the macro when you require the pulse.
Only if you want a pulse to fire every say 2 seconds for 250ms, then an interrupt could be used.
To create a macro, just selecc 'new from Macro menu. Enter a name for the macro. Just drag o/p and delay etc in the macro.
Finally drag the macro icon into your main program, double click on macro and select the name of the macro just been created.

Re: pulse out and slow simulate

Posted: Fri Jun 25, 2010 4:15 pm
by Albert38
Hi,

I have tried to make you an example to understand how to work with interupts. This example rises the value on the display as follows.
The upper line rises by one 300 times a second ( this is not visual in simulation ) and the real display is to slow to display at this speed.
The lower line rises by one 4 times a second ( this must be visual on the display )

I hope this help you.

Re: pulse out and slow simulate

Posted: Fri Jun 25, 2010 5:21 pm
by jimtr6
thank you, what I'm trying to do is this, a wheel spins at variable speeds (a flywheel actually as in a single cylinder engine), there is a trigger at a fixed location on the wheel and a pickup stationary that is triggered every 360 degrees of wheel rotation. The fixed pulse will be a negative pulse on a normally high bit (this is spark), for testing simulating purposes I chose 250 msecs so I could see it as a LED. Having a macro I could call with a delay seems to be the easiest way to do this but I like Sean' is idea of using an interrupt which in my limited (very limited) understanding seems similar but better than staying in the main program, I need to understand timers, macros and interrupts. This application is actually simple, where it gets tricky is spark retard because there will be varying durations between an input (which also will be a pulse) and when I send a spark pulse, this duration is dependent on engine speed, when I'm not frustrated I really enjoy this new brain activity, I got Flowcode on Monday and can't stay away from it!

Re: pulse out and slow simulate

Posted: Fri Jun 25, 2010 9:31 pm
by Albert38
Flowcode is realy fun, and it doesn't take to long to figure out the basics of making a program with it.

For what you are willing to do i think an interupt is not suitable becours the time between picking up the signal from the sensor and the moment you need a spark will variate depending on the rotation speed of the weel. in your case I would use two sensors lets say 60 degrees from each other.

You can measure the time it takes to travel 60 degrees and from there you can calculate the time needed to travel to the point of the spark.

60 degrees is 1/6 part of 360 degrees
For example it takes when it takes 100 ms to travel the distance between the two sensors 60 degrees from each other You can calculate that it takes 600 ms to make one complete turn so when the spark moment is 30 degrees after the second sensor you will have to wait 50 ms after sensor 2 is activated to fire the spark signal.

When your engine is running twice as fast it takes 50 ms between the two sensors so 25 ms after the second sensor you need to fire the spark signal.

Re: pulse out and slow simulate

Posted: Sat Jun 26, 2010 2:18 am
by jimtr6
yes, two sensors makes sense, if I used one and started the count waited 360 degrees my number and be very high, a lower number would be better to manage. At low speed (high count) my retard (long delay) would be max, as speed picked up and the number dropped I would lower (lessen) the delay. My method to accomplish varying delays would be based on decisions with the equal to or less than and follow it with the appropriate delay, I think about six different distinct delay adjustments would be ok, actually spark advance ranges from idle to about 4000 rpm and then just stays at full advance to redline from the 4000 mark, at least that's the way it is on my old Brit bike, and it idles about 900 rpm so my range is roughly 3100 rpms. My circuitry on the output will emulate breaker points, so it would be a high on no fire then when time for spark go low.

Re: pulse out and slow simulate

Posted: Sat Jun 26, 2010 2:21 am
by jimtr6
or one sensor with two notches on the wheel 60 degrees apart?

Re: pulse out and slow simulate

Posted: Sat Jun 26, 2010 7:11 pm
by Albert38
One sensor with two notches is also posible in a case where it is not needed to be able to detect turning direction.