Jump to content
Sign in to follow this  
julian265

Reading Tmr0? 16f876a

Recommended Posts

Hi, my problem seems pretty simple, but has stumped me....

 

I'm trying to read the tmr0 register using this chunk of code, called on INT interrupt:

 

//	PULSE INTERUPT	==================================

void pulse_int (void)
{	
unsigned short temp_short;
clear_bit(intcon,INTF);
if (pulse == 1)
{	pulse_timer1 = TMR0;

SNIP

 

the line "pulse_timer1 = TMR0;" will place a 1 in the (unsigned char) pulse_timer1 register, no matter what the value of TMR0 is.

 

Can anyone think of a reason for this?

 

I have been using TMR0 in this program successfully, it is incrementing and giving the TMR0IF normally. The only problem is that I can't write it's value to another register.

Share this post


Link to post
Share on other sites

julian265,

mmmm capitals.... It works if I use tmr0, not TMR0. The PIC's include file has TMR0 in upper case, so I'm a bit confused there!
Capitals are used for constants. TMR0 is the address of TMR0 register. tmr0 is a variable that is declared to have address TMR0. So when you access the tmr0 variable you access the registers value, and not its address.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Not sure if the previous has given you the answer, but if you are using TMR0 should you not be resetting its interrupt flag? I.e.

 

clear_bit(intcon,TMR0IF);

 

to avoid continuous interrupts.

Share this post


Link to post
Share on other sites
Not sure if the previous has given you the answer, but if you are using TMR0 should you not be resetting its interrupt flag? I.e.

 

clear_bit(intcon,TMR0IF);

 

to avoid continuous interrupts.

 

He's not interrupting off Timer 0

Share this post


Link to post
Share on other sites

Thanks for checking Mike, I am using the TMR0IF, however the snippet posted is used for debouncing an input which is potentially too fast to use full tmr0 cycles for. Hence I'm recording the starting value of tmr0, then its value when the input pulse has finished, and a comparison is done to work out the duration. I have also dealt with the cases of single and multiple tmr0 interrupts between the start and finish of the input.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...