Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Port b output whilst reading porta.

Status
Not open for further replies.

ukmxer

New Member
I am a Noob but I am trying to learn from the datasheet and strugling.

I want to read in 5 pulses and then output one pulse for 1.5 seconds.
I can do both myself but I can not do them simultaneous. My program is a right mess now so I am going to start again. I have not used tmr0 yet but I am wondering if that is how I do it.
Currently I have F84 and F628 to choose from.

1....Count in five pulses
2....Now output a 1.5 sec high
3....Go back and read in five pulses but carry on output until 1.5 secs ends.
4....If five pulses are in before 1.5secs are over then refresh output back to 1.5secs and start output again.

My main problem is that I do not know how to carry on running my program whilst outputting and checking output to see if the 1.5secs are over.


Thank you
 
I have not used tmr0 yet but I am wondering if that is how I do it.
Yes, use one of the timers to trigger an interrupt routine at a set rate; say 0.1 second. Then have a variable called COUNTER that you set to 15 (decimal) in your main routine when a string of 5 pulses is detected.
In your interrupt routine you'd decrement COUNTER if it is not zero and also output a "high" for the pulse. If COUNTER is zero, you'd just output a "low" for the end of the pulse (no decrementing COUNTER) and exit.
 
Thank you for your guidance.

Is an interrupt routine something you code yourself or is it something you call that is already resident in the chip.

Going to work now so hope to read this later.
 
You code it yourself. You also have to set the PIC to generate interrupts when the timer overflows etc so your routine will run at a set interval. Look at the PIC docs for the INTCON, PIR1 and PIE1 registers for more info. Section 8 of the Mid-Range MCU Family manual has more details:
https://www.electro-tech-online.com/custompdfs/2007/12/33023a.pdf
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top