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.

16F628, get a fast pulse

Status
Not open for further replies.

patroclus

New Member
Hello,
I'm designing a circuit to make conversion between a Ps2 PC mouse protocol, and another protocol.
I can use a 16F628 for most things, but I need to get a 12us width pulse. I don't think I can do by software (as it is like a 3Mhz pulse width). I just need to get one of those pulses, to make PIC do some routine. Then get another pulse 16-20ms after.

I'm thinking on using a timer for this. Get the pulse, do the routine, and reset the counter. Then just wait for another pulse.

Can this be done??
Thank you!
 
patroclus said:
Hello,
I'm designing a circuit to make conversion between a Ps2 PC mouse protocol, and another protocol.
I can use a 16F628 for most things, but I need to get a 12us width pulse. I don't think I can do by software (as it is like a 3Mhz pulse width). I just need to get one of those pulses, to make PIC do some routine. Then get another pulse 16-20ms after.

I don't see your problem?. A 16F628 running at 4MHz (as in the internal oscillator) takes only 1uS per instruction cycle, so simply set the pin high (1uS), ten NOP's (10uS), set the bit low (1uS), there you have a 12uS pulse. If you want to call it as a subroutine?, use only 6 NOP's, to account for the call and return instructions.
 
No, what I need is to detect a 6us or 12us pulse, not generate it. that would be so easy! :)
I need to detect a 12us period clock to output data through another pins. I suppose I nee dsome resolution to output data in low state, si it is valid when clock raises
 
patroclus said:
No, what I need is to detect a 6us or 12us pulse, not generate it. that would be so easy! :)
I need to detect a 12us period clock to output data through another pins. I suppose I nee dsome resolution to output data in low state, si it is valid when clock raises

Sorry!.

Are there other width pulses on this same pin?, or is the 12uF pulse the only one?. If so you could wait for the pulse in a simple loop - as long as the processor doesn't need to be doing something else at the same time. If it does need to be doing something else, you could use interrupts (interrupt on change on portb should do it?).
 
Yes, I found a way to do it.
Now I need to respond yo a 12us period clock. Each time clock raises, PIC has to output a bit. It is a serie comunication.

If I store the 8 bit data in a register in PIC's ram, how can I output bit by bit when clock is low in another pin??
I can find some way to do it but I wonder if there's an efficient way...
 
The most common technique is to connect the keyboard clock signal to the RB0/INT pin. You then let the negative going edge initiate an interrupt. The interrupt service routine will shift-in the data bit by bit when you are receiving or shift-out when you are sending a byte to the keyboard.

Just google for "PC keyboard to PIC" to get all the info you need.
 
thank you.
I already detect the start pulse without interrupts.
What I need to know is how to shift-out bits from a register. 2 registers contain 16 bit to output. An efficient way?
 
What I need to know is how to shift-out bits from a register. 2 registers contain 16 bit to output. An efficient way?

Your question is rather vague. Are you asking a software question? In assembly language, it could be as simple as:

Code:
         RRF  REGH,F
         RRF  REGL,F
         RLF  PORTA,F     ; shift bit appears on PORTA, bit0 (setup as output)

I already detect the start pulse without interrupts.

However, while you're shifting out bits, you could miss the center of the 12us pulse and this can make your keyboard program prone to errors. A keyboard scan code can come at anytime. That is why interrupts are recommended.

You can also use hardware like the USART to shift out bits for you but not as a contiguous stream of 16-bits. There are really many ways to do it but they might not work out with what you need.
 
Yes, that routine is what I was asking for.
But imagine I want to output data trough another pin which is not pin 0 of port. Is there an efficient way of doing it??
thank you.
 
patroclus said:
Yes, that routine is what I was asking for.
But imagine I want to output data trough another pin which is not pin 0 of port. Is there an efficient way of doing it??
thank you.

Check my RS232 tutorials for how simple it is, the routine is very easily altered to send 16 bits instead of the ten used by RS232.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top