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

TIMER1 & TIMER3 won't interrupt
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

TIMER1 & TIMER3 won't interrupt
PostPosted: Thu Jan 11, 2024 8:33 am     Reply with quote

Hi

The above timers won't interrupt in my program.
PIC18F26K22
CCS PCH C Compiler, Version 5.059, 31220

I tested on my PCB and also in MPLAB 8.92, hope somebody remember it
Timer 0 & Timer 2 interrupts have no problem
I made a new program for testing, see bellow:


Code:
/////////////////////////////////////////////////////////////////////
//TEST26K22
/////////////////////////////////////////////////////////////////////
#include <18F26K22.h>
#device ADC=10
#FUSES WDT//Watch Dog Timer enabled; WDT period is 4ms
#FUSES WDT4//Watch Dog Timer uses 1:4 Postscale;interrupts every 16ms                                         
#FUSES NOPBADEN//PORTB pins are configured as digital I/O on RESET
#FUSES PUT//Power Up Timer enabled
#FUSES BROWNOUT//Reset when brownout detect enabled
#FUSES BORV29//Brownout reset at 2.9V
#FUSES HSH//High speed Osc, high power 16MHz-25MHz
#FUSES PLLEN//4X HW PLL enabled
#FUSES NOIESO//Internal External Switch Over mode disabled
#FUSES NOFCMEN//Fail-safe clock monitor disabled
#FUSES NOHFOFST//High Frequency INTRC waits until stable before clocking CPU
#FUSES MCLR//Master Clear pin enabled
#FUSES STVREN//Stack full/underflow will cause reset
#FUSES NOLVP// No low voltage progming
#FUSES NOXINST//Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NODEBUG//No Debug mode for ICD
#FUSES NOPROTECT//Code not protected from reading
#FUSES NOCPD//No EE protection
#FUSES NOWRT//Program memory not write protected
#FUSES NOWRTC//configuration registers not write protected
#FUSES NOWRTD//Data EEPROM not write protected
#use delay(clock=64MHz,crystal=16MHz)
#use rs232(baud=9600, UART1, stream=PORT1, errors)//communication with the PC
#use rs232(baud=9600, UART2, stream=PORT2, errors)
//#use I2C(MASTER, FAST=400000, I2C1, STREAM=I2CPORT)//I2C1 hardware used
#device HIGH_INTS=TRUE

#define LED PIN_B5
int LEDcounter=0;

#ZERO_RAM

#int_TIMER0
void TIMER0_isr(void)
{
   LEDcounter++;
   if(LEDcounter>=8)//524ms
   {
      LEDcounter=0;
      output_toggle(LED);
   }   
}
#int_TIMER1
void TIMER1_isr(void)
{
   delay_us(1);   
}
#int_TIMER2
void TIMER2_isr(void)
{
   delay_us(1);   
}
#int_TIMER3
void TIMER3_isr(void)
{
   delay_us(1);
}

void main()
{
   setup_adc_ports(NO_ANALOGS);
   setup_wdt(WDT_16MS);//~16 ms reset   
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);//65.536 ms overflow
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);//65.536 ms overflow
   setup_timer_2(T2_DIV_BY_16,255,16);//512 us overflow, 8.192 ms interrupt
   setup_timer_3(T3_INTERNAL|T3_DIV_BY_8);//65.536 ms overflow
   setup_ccp2(CCP_CAPTURE_FE);// Configure CCP2 to capture fall
/////////////////////////////////////////////////////////////////////
   enable_interrupts(INT_TIMER0);
   enable_interrupts(INT_TIMER1);
      enable_interrupts(INT_TIMER2);
   enable_interrupts(INT_TIMER3);
   enable_interrupts(INT_RDA);
   disable_interrupts(INT_TBE);
   disable_interrupts(INT_RDA2);
   disable_interrupts(INT_TBE2);
      disable_interrupts(INT_CCP2);
   enable_interrupts(GLOBAL);
/////////////////////////////////////////////////////////////////////
   while(TRUE)
   {
      restart_wdt();
      delay_us(1);
   }
}


I don't understand why. I suppose I made some mistake.

Best wishes
Joe
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jan 11, 2024 9:08 am     Reply with quote

get rid of the WDT !
ONLY enable it when program is 100% completely tested and product is ready to go out he door.

A quick read both timer 1 and 3 are 65ms and the WDT is 16ms
so....WDT keeps resetting the program, T1 and t3 will never occour
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Jan 11, 2024 9:08 am     Reply with quote

One thing leaps out in what you post. You have INT_RDA enabled, without
any handler for it. This is a disaster. Will cause erratic operation, and
unexpected events. Might well be the problem.
Repeat ten times, I must never enable an interrupt without a handler....

You also have high_ints enabled, but none of your interrupts are set to
be high priority. That shouldn't cause a problem but might.

As a comment, you are setting the watchdog both in fuses and using
setup_wdt. You can only setup the watchdog once. The setup_wdt line
sets up the fuses for you. I'd have expected the compiler to warn about
this.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Thu Jan 11, 2024 11:55 pm     Reply with quote

Hi Temtronic
Thank you for the answer
The project is to test only so the WDT is just there as in the program and I have restart_wdt(); in the main
I make it NOWDT in the fuses.
The fuses from the LST file:
Code:
Configuration Fuses:
   Word  1: 3200   HSH PLLEN PRIMARY NOFCMEN NOIESO
   Word  2: 3C06   PUT BROWNOUT BORV29 NOWDT WDT32768
   Word  3: B500   CCP2C1 NOPBADEN CCP3B5 NOHFOFST TIMER3C0 CCP2B5 MCLR
   Word  4: 0081   STVREN NOLVP NOXINST NODEBUG
   Word  5: C00F   NOPROTECT NOCPB NOCPD
   Word  6: E00F   NOWRT NOWRTC NOWRTB NOWRTD
   Word  7: 400F   NOEBTR NOEBTRB


Hi Ttelmah
Thank you for the answer
I made

Code:
disable_interrupts(INT_RDA);

Remain there by mistake from my program
I outcommented
Quote:
//#device HIGH_INTS=TRUE

Deletet the setup_wdt in the main

But still TIMER1 and TIMER3 won't interrupt

Best wishes
Joe
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jan 12, 2024 6:14 am     Reply with quote

time to cut new code
New program ONLY has code for Timer1 testing
Inside the ISR, simply 'toggle led'
Don't setup serial, other timers and NO WDT code

This way the program is small, easy to see, easier to debug.

So cut new code/compile/test/report back progress. if still doesn't work, post your new program
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Fri Jan 12, 2024 6:29 am     Reply with quote

Hi Temtronic

Made new program per your advice, TIMER1 still won't interrupt
Code:
/////////////////////////////////////////////////////////////////////
//TEST26K22V1
/////////////////////////////////////////////////////////////////////
#include <18F26K22.h>
#device ADC=10
#FUSES NOWDT//Watch Dog Timer enabled; WDT period is 4ms
//#FUSES WDT4//Watch Dog Timer uses 1:4 Postscale;interrupts every 16ms                                         
#FUSES NOPBADEN//PORTB pins are configured as digital I/O on RESET
#FUSES PUT//Power Up Timer enabled
#FUSES BROWNOUT//Reset when brownout detect enabled
#FUSES BORV29//Brownout reset at 2.9V
#FUSES HSH//High speed Osc, high power 16MHz-25MHz
#FUSES PLLEN//4X HW PLL enabled
#FUSES NOIESO//Internal External Switch Over mode disabled
#FUSES NOFCMEN//Fail-safe clock monitor disabled
#FUSES NOHFOFST//High Frequency INTRC waits until stable before clocking CPU
#FUSES MCLR//Master Clear pin enabled
#FUSES STVREN//Stack full/underflow will cause reset
#FUSES NOLVP// No low voltage progming
#FUSES NOXINST//Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NODEBUG//No Debug mode for ICD
#FUSES NOPROTECT//Code not protected from reading
#FUSES NOCPD//No EE protection
#FUSES NOWRT//Program memory not write protected
#FUSES NOWRTC//configuration registers not write protected
#FUSES NOWRTD//Data EEPROM not write protected
#use delay(clock=64MHz,crystal=16MHz)

#define LED PIN_B5
int LEDcounter=0;

#ZERO_RAM

#int_TIMER1
void TIMER1_isr(void)
{
   LEDcounter++;
   if(LEDcounter>=8)//524ms
   {
      LEDcounter=0;
      output_toggle(LED);
   }      
}
void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);//65.536 ms overflow
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);//65.536 ms overflow
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);

   while(TRUE)
   {
      delay_us(1);
   }
}
/////////////////////////////////////////////////////////////////////


Best wishes
Joe
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jan 12, 2024 6:37 am     Reply with quote

hmm..
maybe have main() toggle a second LED at 1Hz, to confirm the PIC is actually running at the correct speed ?

maybe use the internal oscillator as the clock source instead of the external 16MHz xtal/2 caps ??


Last edited by temtronic on Fri Jan 12, 2024 6:42 am; edited 1 time in total
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Fri Jan 12, 2024 6:41 am     Reply with quote

Hi Temtonic

The controller works because it works correct with the LED activated by TIMER0

Best wishes
Joe
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Fri Jan 12, 2024 9:08 am     Reply with quote

I copied your code above and compiled it using version 5.061 (the closest I had to yours). The pin toggles fine.
My board has an 8MHz resonator instead of a 16MHz crystal, so 32MHz clock.
It toggles every 520ms or so.
8MHzx4 = 32MHz / 4 = 8MHz instruction /8 = 1MHz / 65536 = 15.3Hz interrupt = 65.5ms * 8 = 524ms toggle
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Sat Jan 13, 2024 4:02 am     Reply with quote

Hi Gaugeguy

Thank you for the answer.
Will try it again Monday in the office

Best wishes
Joe
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sat Jan 13, 2024 6:45 am     Reply with quote

There s one worrying possibility.
I too went back and looked for a compiler closer to the one being usd
here. Like you gauugeguy I found I had not lkept 5.059. Now I will keep
compilers that worked, but not keep compilers with major problems.
It is possible 5.059 was one of the ones I got rid of as 'known faulty'. Sad
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jan 13, 2024 7:45 am     Reply with quote

It'd be nice to compare the listings ! Should be real easy to spot any differences...
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sat Jan 13, 2024 8:14 am     Reply with quote

There is a glaring problem.

He has left the watchdog enabled in the test program......

I was setting up to compile it and post the listing, and went to modify the
fuses (get rid of the ones controlling the oscillator since the compiler does
this), and realised he has left the watchdog enabled, so it won't work.

Code:

/////////////////////////////////////////////////////////////////////
//TEST26K22V1
/////////////////////////////////////////////////////////////////////
#include <18F26K22.h>
#device ADC=10                                 
#FUSES NOPBADEN//PORTB pins are configured as digital I/O on RESET
#FUSES PUT//Power Up Timer enabled
#FUSES BROWNOUT//Reset when brownout detect enabled
#FUSES NOIESO//Internal External Switch Over mode disabled
#FUSES NOFCMEN//Fail-safe clock monitor disabled
#FUSES NOHFOFST//High Frequency INTRC waits until stable before clocking CPU
#FUSES MCLR//Master Clear pin enabled
#FUSES STVREN//Stack full/underflow will cause reset
#FUSES NOLVP// No low voltage progming
#FUSES NOXINST//Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NODEBUG//No Debug mode for ICD
#FUSES NOPROTECT//Code not protected from reading
#FUSES NOCPD//No EE protection
#FUSES NOWRT//Program memory not write protected
#FUSES NOWRTC//configuration registers not write protected
#FUSES NOWRTD//Data EEPROM not write protected

#use delay(clock=64MHz,crystal=16MHz)

#define LED PIN_B5
int LEDcounter=0;

#ZERO_RAM

#int_TIMER1
void TIMER1_isr(void)
{
   LEDcounter++;
   if(LEDcounter>=8)//524ms
   {
      LEDcounter=0;
      output_toggle(LED);
   }     
}
void main()
{
   setup_timer_0(T0_INTERNAL|T0_DIV_16);//65.536 ms overflow
   //The RTCC names are for com[atibilty with old code. Use the modern names
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);//65.536 ms overflow
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);

   while(TRUE)
   {
      delay_us(1);
   }
}
/////////////////////////////////////////////////////////////////////


This compiles with 5.061, and runs correctly.

Code:

*
00000:  GOTO   00C2
*
00008:  MOVWF  04
0000A:  MOVFF  FD8,05
0000E:  MOVFF  FE0,06
00012:  MOVLB  0
00014:  MOVFF  FE9,0C
00018:  MOVFF  FEA,07
0001C:  MOVFF  FE1,08
00020:  MOVFF  FE2,09
00024:  MOVFF  FD9,0A
00028:  MOVFF  FDA,0B
0002C:  MOVFF  FF3,12
00030:  MOVFF  FF4,13
00034:  MOVFF  FFA,14
00038:  MOVFF  FF5,15
0003C:  MOVFF  FF6,16
00040:  MOVFF  FF7,17
00044:  MOVFF  00,0E
00048:  MOVFF  01,0F
0004C:  MOVFF  02,10
00050:  MOVFF  03,11
00054:  BTFSS  F9D.0
00056:  GOTO   0060
0005A:  BTFSC  F9E.0
0005C:  GOTO   00AE
00060:  MOVFF  0E,00
00064:  MOVFF  0F,01
00068:  MOVFF  10,02
0006C:  MOVFF  11,03
00070:  MOVFF  0C,FE9
00074:  MOVFF  07,FEA
00078:  BSF    07.7
0007A:  MOVFF  08,FE1
0007E:  MOVFF  09,FE2
00082:  MOVFF  0A,FD9
00086:  MOVFF  0B,FDA
0008A:  MOVFF  12,FF3
0008E:  MOVFF  13,FF4
00092:  MOVFF  14,FFA
00096:  MOVFF  15,FF5
0009A:  MOVFF  16,FF6
0009E:  MOVFF  17,FF7
000A2:  MOVF   04,W
000A4:  MOVFF  06,FE0
000A8:  MOVFF  05,FD8
000AC:  RETFIE 0
.................... /////////////////////////////////////////////////////////////////////
.................... //TEST26K22V1
.................... /////////////////////////////////////////////////////////////////////
.................... #include <18F26K22.h>
.................... //////////// Standard Header file for the PIC18F26K22 device ////////////////
.................... ///////////////////////////////////////////////////////////////////////////
.................... ////        (C) Copyright 1996, 2020 Custom Computer Services          ////
.................... //// This source code may only be used by licensed users of the CCS C  ////
.................... //// compiler.  This source code may only be distributed to other      ////
.................... //// licensed users of the CCS C compiler.  No other use, reproduction ////
.................... //// or distribution is permitted without written permission.          ////
.................... //// Derivative programs created using this software in object code    ////
.................... //// form are not restricted in any way.                               ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... #device PIC18F26K22
....................
.................... #list
....................
.................... #device ADC=10                                 
.................... #FUSES NOPBADEN//PORTB pins are configured as digital I/O on RESET
.................... #FUSES PUT//Power Up Timer enabled
.................... #FUSES BROWNOUT//Reset when brownout detect enabled
.................... #FUSES NOIESO//Internal External Switch Over mode disabled
.................... #FUSES NOFCMEN//Fail-safe clock monitor disabled
.................... #FUSES NOHFOFST//High Frequency INTRC waits until stable before clocking CPU
.................... #FUSES MCLR//Master Clear pin enabled
.................... #FUSES STVREN//Stack full/underflow will cause reset
.................... #FUSES NOLVP// No low voltage progming
.................... #FUSES NOXINST//Extended set extension and Indexed Addressing mode disabled (Legacy mode)
.................... #FUSES NODEBUG//No Debug mode for ICD
.................... #FUSES NOPROTECT//Code not protected from reading
.................... #FUSES NOCPD//No EE protection
.................... #FUSES NOWRT//Program memory not write protected
.................... #FUSES NOWRTC//configuration registers not write protected
.................... #FUSES NOWRTD//Data EEPROM not write protected
....................
.................... #use delay(clock=64MHz,crystal=16MHz)
....................
.................... #define LED PIN_B5
.................... int LEDcounter=0;
....................
.................... #ZERO_RAM
....................
.................... #int_TIMER1
.................... void TIMER1_isr(void)
.................... {
....................    LEDcounter++;
000AE:  INCF   19,F
....................    if(LEDcounter>=8)//524ms
000B0:  MOVF   19,W
000B2:  SUBLW  07
000B4:  BC    00BC
....................    {
....................       LEDcounter=0;
000B6:  CLRF   19
....................       output_toggle(LED);
000B8:  BCF    F93.5
000BA:  BTG    F8A.5
....................    }     
000BC:  BCF    F9E.0
000BE:  GOTO   0060
.................... }
.................... void main()
000C2:  CLRF   FF8
000C4:  BCF    FD0.7
000C6:  BSF    07.7
000C8:  MOVLW  36
000CA:  MOVWF  00
000CC:  MOVLW  10
000CE:  MOVWF  01
000D0:  MOVLW  02
000D2:  MOVWF  FE9
000D4:  MOVLW  00
000D6:  MOVWF  FEA
000D8:  CLRF   FEE
000DA:  DECFSZ 00,F
000DC:  BRA    00D8
000DE:  DECFSZ 01,F
000E0:  BRA    00D8
000E2:  CLRF   19
000E4:  MOVLB  F
000E6:  CLRF   x38
000E8:  CLRF   x39
000EA:  CLRF   x3A
000EC:  CLRF   F77
000EE:  CLRF   F78
000F0:  CLRF   F79
.................... {
....................    setup_timer_0(T0_INTERNAL|T0_DIV_16);//65.536 ms overflow
000F2:  MOVLW  83
000F4:  MOVWF  FD5
....................    setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);//65.536 ms overflow
000F6:  MOVLW  37
000F8:  MOVWF  FCD
000FA:  CLRF   FCC
....................    enable_interrupts(INT_TIMER1);
000FC:  BSF    F9D.0
....................    enable_interrupts(GLOBAL);
000FE:  MOVLW  C0
00100:  IORWF  FF2,F
....................
....................    while(TRUE)
....................    {
....................       delay_us(1);
00102:  MOVLW  05
00104:  MOVWF  00
00106:  DECFSZ 00,F
00108:  BRA    0106
0010A:  BRA    0102
....................    }
.................... }
.................... /////////////////////////////////////////////////////////////////////
0010C:  SLEEP
....................

Configuration Fuses:
   Word  1: 3200   HSH PLLEN PRIMARY NOFCMEN NOIESO
   Word  2: 3C1E   PUT BROWNOUT BORV19 NOWDT WDT32768
   Word  3: B500   CCP2C1 NOPBADEN CCP3B5 NOHFOFST TIMER3C0 CCP2B5 MCLR
   Word  4: 0081   STVREN NOLVP NOXINST NODEBUG
   Word  5: C00F   NOPROTECT NOCPB NOCPD
   Word  6: E00F   NOWRT NOWRTC NOWRTB NOWRTD
   Word  7: 400F   NOEBTR NOEBTRB
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Sun Jan 14, 2024 12:15 am     Reply with quote

Thank you for all the answers

Bu no, he didn't
Quote:
He has left the watchdog enabled in the test program......


In his code posted on Fri Jan 12, 2024 8:29 pm can see:

Code:
#FUSES NOWDT//Watch Dog Timer enabled; WDT period is 4ms
//#FUSES WDT4//Watch Dog Timer uses 1:4 Postscale;interrupts every 16ms     


In the LST of the program can see also WDT not enabled:
Code:
Configuration Fuses:
   Word  1: 3200   HSH PLLEN PRIMARY NOFCMEN NOIESO
   Word  2: 3C06   PUT BROWNOUT BORV29 NOWDT WDT32768
   Word  3: B500   CCP2C1 NOPBADEN CCP3B5 NOHFOFST TIMER3C0 CCP2B5 MCLR
   Word  4: 0081   STVREN NOLVP NOXINST NODEBUG
   Word  5: C00F   NOPROTECT NOCPB NOCPD
   Word  6: E00F   NOWRT NOWRTC NOWRTB NOWRTD
   Word  7: 400F   NOEBTR NOEBTRB


Best wishes
Joe
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sun Jan 14, 2024 1:31 am     Reply with quote

Have to disagree.
I cut and pasted the code directly from here when it was originally posted.
The version posted had the WDT silll left enabled. The WDT4 fuse
had been remmed out, but the WDT one was still there. The reset_wdt
from the oriignal coe had been removed, so it woud not work.

Anyway I have posted the source with the watchdog disabled, and
the listing generated by the 4.061 compiler. Compile the code as I posted
it, and compae the listing. Is it the same???. This works.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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