PDA

View Full Version : Pulse generation help required



Muzza
- 2nd November 2005, 13:30
Hello, I need to generate a 16mS pulse (16F84A).

Only issue is that I need to do that whilst reading a whole bunch of input signals. If I use Pause or Pulseout the processor does not do anything else during the 16mS and I miss input data.
I can tolerate a 1mS pulse and not miss input but 16m is way to long.
Other than using an external 16mS pulse generator triggered by a short pulse from the 16F84A.... is there any way of doing this in PicBasicPro ??

Assistance appreciated.

HenrikOlsson
- 2nd November 2005, 15:01
Muzza,

You have various options to choose from.

The first that springs to mind is to use one of the timers on the chip. TMR1 is usually 16bit wide (look it up in the 'F84 datasheet). It can be set to increment on each tick of the CPU so if your running on a 4MHz X-tal TMR1 will count uS (16mS = 16000uS).

The timer will generate an interupt when it rolls over from 65535 to 0 so if you preset the timer to 59535 (65535-16000). It will interupt 16mS after it's started.

You can use PBP OnInterupt to detect it OR just check the TMR1 Interuptflag in a loop to catch it. If you're going to use OnInterupt remember not to use any time consuming commands like pause while waiting for the interupt.

/Henrik Olsson.

HenrikOlsson
- 2nd November 2005, 18:30
Hi again,
Im sorry... I just returned from work and checked the datasheet for the 'F84 and it doesn't have TMR1. It does, however have TMR0 and a prescaler that you may be able to use as long as you turn off the WDT.

If I where you I'd consider changing that 'F84 to something like the 'F628 if at all possible. If you NEED to run it on the 'F84 let us know...

Here's a quick non tested example of how you could use TMR1 on 'F628. It doesn't use interupts it only polls the TMR1 interupt flag to se if it has rolled over.



Loop:
If PortB.1 = 0 then Goto Loop 'Wait here until PortB.1 goes high.


SetPulse:
'Preload TMR1 ((232*256) + 143 = 59535)
TMR1H = 232
TMR1L = 143
High PortB.1 'Set the output.
T1CON.0 = 1 'Start the tmr.

WaitForTimeOut:
If PIR1.0 = 1 then 'The time is up...
Low PortB.0 'Turn off the output
T1CON.0 = 0 'Stop TMR1
PIR1.0 = 0 'Reset the TMR1 Interupt Flag
TMR1H = 232 'Reload TMR1 so it ready for the next pulse
TMR1L = 143
Goto Loop
Endif

'Do your other stuff here.....
'Don't use any time consuming pauses etc.
Goto WaitForTimeOut


Hope that helps a bit more than my first suggestion.
/Henrik Olsson.

Muzza
- 2nd November 2005, 22:50
Hendrik, thanks for the speedy advice.
Looks like what I need to do to make my implementation work.
I will go to the F628 as you suggest.
I am new to this (PICs and PBP) and just learned heaps through investigating your suggested code and studying the datasheets to see how it works.
Thanks heaps for that.
Best Regards.
Murray