CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Timer0 interrupts not working, I think...

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
svcguy



Joined: 12 Oct 2006
Posts: 9

View user's profile Send private message

Timer0 interrupts not working, I think...
PostPosted: Thu Oct 12, 2006 10:12 pm     Reply with quote

Hi all,

I'm new to CCS's forum and realtively new to PIC programming. The formals: PIC16F737 based alarm clock project, version info PCM 3.206, PCH 4.002d. MPLAB 7.3.

Code compiles with only a few standard warnings (except for Interrupts disabled to prevent reentrancy) and runs in MPLAB's MPSIM exactly as I desire. Problem is when placed in breadboard, code works, except time never changes. (Using JDM programmer and WinPic to burn chip). Code is quite long >500 lines, so I've put it here. Schematic is here. Not sure about the hosting site, pls give feedback.

Thanks for help,
Andy
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Oct 12, 2006 10:37 pm     Reply with quote

Too hard to get at your code.

Post your #fuse settings and, your timer_isr, and you interrupt initialization code.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
svcguy



Joined: 12 Oct 2006
Posts: 9

View user's profile Send private message

PostPosted: Thu Oct 12, 2006 11:06 pm     Reply with quote

Sorry, bad host site. These links should be much better

Code
Schematic
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Oct 12, 2006 11:31 pm     Reply with quote

OK. Few suggestions.

Unless your programmer is using Low Voltage Programming and you hardware is specifically set up for it add

Code:
#fuse NOLVP     // This is almost certainly your problem.



In principle, you are doing too much in your interrrupt handler although that is not a problem in this instance. Ideally after doing your 1 second check. You set a "0ne second done flag" and in your mail loop add a call to "service_rtc()" or whatever. In here you check to see if the falg is set, if so clear the flag and do the rest of your rtc updating.

You are manually seting TRIS but have not told the compiler you want to manage TRIS yourself. So the compiler will happily change the TRIS as it sees fit. Add the directives #use FAST_IO(x) where x is the port that you want to manage yourself.

You should clear an interrupts flag before enabling it as you aer likely to immediately generate an interrupt based on the stale state of the flag. I suggest changing the order of you interrupt enables:

Code:

   set_timer0(0x00);
   clear_interrupt(INT_TIMER0);
   enable_interrupts(GLOBAL);      //   Allow interrupts
   enable_interrupts(INT_TIMER0);      //   Enable Timer0 interrupt


You have dropped into assembler in a few places. There is nothing wrong with that but you do not need to. You can use the bit_clear(x,y) instead of the bcf instruction.

If you want to modify a register. Tell the comopiler where the register is:

Code:
#byte STATUS = 0x03  // tell the compiler where to find the status register


then later in your code

Code:
STATUS = 0x48  // put some value into the status register

_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
svcguy



Joined: 12 Oct 2006
Posts: 9

View user's profile Send private message

PostPosted: Fri Oct 13, 2006 5:54 am     Reply with quote

Andrew,

Thanks for all the excellent advice, I will try these things when I get home later tonight. You may have solved another problem that I didn't even mention about a pin not responding. I'll post an update sometime tonight.

Thanks,
Andy
svcguy



Joined: 12 Oct 2006
Posts: 9

View user's profile Send private message

PostPosted: Fri Oct 13, 2006 10:13 pm     Reply with quote

Andrew,

I have tried the following

Implemented #use fast_io for ports a,b,c
Redesigned the timer0 isr as per your advice

No change. My device does not support the NOLVP fuse. I am beginning to think I have some kind of oscillator/timer0 source problem. I also have a problem with pin 27 (RB6/PGC) not responding. How can I make sure that this pin is not setup as an input?

Again, the code functions perfectly in MPSIM. It keeps time and I can change the alarm and clock time and LEDs and buzzer work correctly. When I burn the chip, It no longer keeps time. I can change the time for the alarm and clock, so the code for that and displaying works fine (except that segment g on 7segs doesn't work, which is the one connected to RB6/PGC).

So, it is almost as if Timer0 either never runs or never interrupts. I'm trying to use the internal oscillator at 8MHz if that helps.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Oct 13, 2006 10:30 pm     Reply with quote

Have you updated yor code link to the current version you are testing?
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
svcguy



Joined: 12 Oct 2006
Posts: 9

View user's profile Send private message

PostPosted: Fri Oct 13, 2006 10:53 pm     Reply with quote

Here is latest code
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Oct 13, 2006 11:21 pm     Reply with quote

TimerOverflows should be int16

In general, unless your are returning a value, at the end of a function you do not need to use return. This is implicit. You use return when you want to break out of a function early.

Remove the return from the interrrupt handler this will cause problems.

You do not need to clear the interrupt in the interrupt handler. The compiler automatically generates this code for you.

In updateTime() the OneSecondFlag = 0 is in the wrong place. It should be the first instruction executed after the test if(OneSecondFlag == 1)

You can IM me.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!


Last edited by asmallri on Sat Oct 14, 2006 12:51 am; edited 1 time in total
svcguy



Joined: 12 Oct 2006
Posts: 9

View user's profile Send private message

PostPosted: Fri Oct 13, 2006 11:51 pm     Reply with quote

The internal oscillator code is defined in the config word and by writing a 0x7A to the osccon reg (0x8F).

I understand reducing the timeroverflow size ( that is carried over from a previous program that used a 10-second interrupt time)

Changed the clear_interrupt() and removed the return statements from the isr and changed the location of the clearing of the flag

No luck. I really appreciate your help Andrew and if you're ever Stateside, I'll buy you a beer.

Here is the new code
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sat Oct 14, 2006 12:22 am     Reply with quote

BTW do you know your COLON LEDs should not work if either of the other two LEDs are on?

Time to do a sanity check. We will steal your AM/PM LED for some testing.

Code:

#define PORTA 0x05
#define DEBUG_LED 7
      
// global flag
volatile boolean flag = false;

modified ISR
Code:

/****************** Interrupt Vector **************/
#int_TIMER0
void TIMER0_isr(void)
{
   TimerOverflows++;   

   if(TimerOverflows == 3906)
   {
      if (flag)
          bit_clear(PORTA, DEBUG_LED);
      else
         bit_set(PORTA, DEBUG_LED);
      flag = ~flag;
      OneSecondFlag = 1;
      TimerOverflows = 0;
   }
}



Comment out your mainline code that modifies this LED. And change the type of TimerOverflows
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
svcguy



Joined: 12 Oct 2006
Posts: 9

View user's profile Send private message

PostPosted: Sat Oct 14, 2006 5:28 pm     Reply with quote

Sanity Check failed. LED connected to RA7 (which I've determined was pin 9 not pin 10) doesn't blink after burning. PORTA register changes when in MPSIM. Question
svcguy



Joined: 12 Oct 2006
Posts: 9

View user's profile Send private message

PostPosted: Sat Oct 14, 2006 5:55 pm     Reply with quote

I tried using a crystal and eliminating the possibility that something was not working with the internal osc. I changed my INTRC_IO fuse to HS and put a crystal across pins 9 and 10. Same thing. Could the compiler be placing the interrupt vector in the wrong place on the chip and that's why I never get into the interrupt?
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sat Oct 14, 2006 7:02 pm     Reply with quote

Did you change the variable type of TimerOverflows?
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
svcguy



Joined: 12 Oct 2006
Posts: 9

View user's profile Send private message

PostPosted: Sat Oct 14, 2006 11:22 pm     Reply with quote

Discovered the problem. Among other things, WinPic was changing the value of my config word's debug bit when writing. After changing the DEBUG bitmask in WinPic's device.ini file, it stopped and the program started working again.

Special thanks to asmallri who spent several hours of his spare time helping me figure this out as well as lending his expertise to streamline my C code.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group