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.

Interrupts with PIC12F629

Status
Not open for further replies.

rturnock

New Member
Hi guys I'm using a 12F629 to measure the time between rising edges on the external interrupt pin GPIO.2 but experiencing some timing problems.

To do this I'm using the 16bit TMR1 (driven from internal clock) and the external interrupt. Basically no code is in the main loop, and everything is performed in the interrupt routine.
Bare with me while I describe the code, then I'll explain the problem.

The interrupt routine fires on either the external interrupt, or TMR1 overflow. The general idea is that when the routine fires a few checks are made which determine the next course of action. First a check is made to see if an TMR1 overflow has happened. If it has the timer is stopped and the routine returns. If in fact a external interrupt has occurred the running state of the timer is checked. If its not running the timer is cleared out and started before returning from the routine. If on the other hand the timer is running, (ie this is the second rising edge) then the timer is stopped and the TMR1 value serial comm'd out.

The first problem I have is that if I set any of the prescaler bits for the timer on T1CON then any delays I have (inside the serial comms code) take longer to execute than expected and therefore come out as nonsense. For example a 50us delay is now taking approx 70us when the prescaler is set 2:1. I don't understand how this can effect the delays since they are coded with looped nop's and don't use any timers ?

The second problem is that the timer values retrieved are way out from the real timings. Sometimes by as much as 1000 cycles under. The error changes as the period of the signal presented on GPIO.2 is altered. Again I cannot see where I'm going wrong. The period of the signal on GPIO.2 is typically arround 8000us -> 12000us

If anyone has any ideas, no matter how basic they may seem as I'm new to PIC asm I'd love to here them.

Alternatively, the code is very short and simple and if someone wouldn't mind quickly taking a look and hopefully seeing something glaringly obvious that would be great.

Thanks

Rob
 

Attachments

  • code.zip
    1.1 KB · Views: 404
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top