  | 
	  | 
		 
	 
	
		| View previous topic :: View next topic   | 
	 
	
	
		| Author | 
		Message | 
	 
	
		
			overmindx
 
 
  Joined: 06 Oct 2008 Posts: 43
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| timer1 and 18f67k22 | 
			 
			
				 Posted: Mon Aug 11, 2014 1:37 am     | 
				     | 
			 
			
				
  | 
			 
			
				hi,
 
  how come this code doesnt work? 
 
 
 	  | Code: | 	 		  
 
#include <18F67K22.h>
 
#device adc=12
 
#device PASS_STRINGS = IN_RAM
 
 
#FUSES WDT_SW, WDT32768, INTRC_IO, NOPROTECT, NOIESO, BROWNOUT, PUT, NOCPD, STVREN, NODEBUG, NOWRT, NOWRTD, NOEBTR, NOCPB, NOEBTRB, NOWRTC, NOWRTB, FCMEN, NOXINST, MCLR, RTCOSC_T1
 
#use delay(clock=16000000)
 
 
#use rs232(force_sw,baud=57600, xmit=PIN_G1, rcv=PIN_G2, stream=PC)
 
 
#Byte TMR1H = 0xFCF
 
#Byte T1CON = 0xFCD
 
int1 TESTFLAG=0;
 
 
 
#int_TIMER1
 
void TIMER1_isr()    
 
{ 
 
   bit_clear(T1CON,1);
 
   bit_set(TMR1H,7);
 
   bit_set(T1CON,1);
 
   
 
   TESTFLAG=TRUE;
 
}
 
 
void main()
 
{
 
   delay_ms(2000);
 
   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_ENABLE_SOSC); 
 
   
 
   enable_interrupts(INT_TIMER1);
 
   enable_interrupts(GLOBAL);
 
   do{
 
      fprintf(PC,"TESTFLAG=%i\r",TESTFLAG);
 
      delay_ms(1000);
 
   }while(1);
 
}
 
 
 | 	  
 
 
this code just outputs TESTFLAG=0.
 
my compiler version is 5.26. when i used a lower compiler version, this code works. please help.
 
 
thanks. | 
			 
		  | 
	 
	
		  | 
	 
	
		
			Ttelmah
 
 
  Joined: 11 Mar 2010 Posts: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Aug 11, 2014 3:15 am     | 
				     | 
			 
			
				
  | 
			 
			
				| What version 'earlier compiler'?. | 
			 
		  | 
	 
	
		  | 
	 
	
		
			overmindx
 
 
  Joined: 06 Oct 2008 Posts: 43
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Aug 11, 2014 3:58 am     | 
				     | 
			 
			
				
  | 
			 
			
				| if i used v.4.114 it outputs TESTFLAG=1 | 
			 
		  | 
	 
	
		  | 
	 
	
		
			asmallri
 
 
  Joined: 12 Aug 2004 Posts: 1660 Location: Perth, Australia 
			
			 
			 
			 
			 
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Aug 11, 2014 6:32 am     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | overmindx wrote: | 	 		  | if i used v.4.114 it outputs TESTFLAG=1 | 	  
 
 
In traditional C TESTFLAG should be declared volatile _________________ Regards, Andrew
 
 
http://www.brushelectronics.com/software
 
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! | 
			 
		  | 
	 
	
		  | 
	 
	
		
			overmindx
 
 
  Joined: 06 Oct 2008 Posts: 43
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Aug 11, 2014 7:48 am     | 
				     | 
			 
			
				
  | 
			 
			
				hi,
 
  i followed your suggestion by declaring TEST_FLAG as volatile but it still doesnt solve the problem. It seems for some reason isnt triggering the interrupt. | 
			 
		  | 
	 
	
		  | 
	 
	
		
			Ttelmah
 
 
  Joined: 11 Mar 2010 Posts: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Aug 11, 2014 8:44 am     | 
				     | 
			 
			
				
  | 
			 
			
				Odd.
 
 
I had already tried in 4.141, and this develops identical code setting up the timer, enabling the interrupts, and the fuses were all the same. Just tried 4.114, and this too develops identical code.
 
One difference is the register 0xFD3, which is loaded with 0x74, instead of 0x72, in the initialisation. This is OSCCON, which controls the way the oscillator is configured. So looking, the later code is setup to run off the internal oscillator block, while the older code is set to run off the 'default primary oscillator', which is then set in CONFIG1H as the internal oscillator. These should both give the same result.
 
You can though change this by adding the line:
 
 
setup_oscillator(OSC_NORMAL|OSC_16MHZ); 
 
 
I can't see though why that would change the behaviour of the secondary oscillator.
 
 
This though is the only register set differently when you reach the start of the printf statement, between the versions. | 
			 
		  | 
	 
	
		  | 
	 
	
		
			overmindx
 
 
  Joined: 06 Oct 2008 Posts: 43
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Aug 11, 2014 9:43 am     | 
				     | 
			 
			
				
  | 
			 
			
				hi,
 
   i tried placing 
 
    	  | Code: | 	 		  
 
   setup_oscillator(OSC_NORMAL|OSC_16MHZ); 
 
    | 	  
 
 
   but it still wont work. 
 
 
   On a side note, i tried using v4.124 and it works. | 
			 
		  | 
	 
	
		  | 
	 
	
		
			overmindx
 
 
  Joined: 06 Oct 2008 Posts: 43
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sun Jan 11, 2015 11:31 pm     | 
				     | 
			 
			
				
  | 
			 
			
				hi, 
 
  i just wanna revive this thread since i am still clueless why code involving timer1 will work on one version (4.124) and it wont work on (4.141). below is the code and .lst file for each version. please help so that this code will work for different versions and not just on 4.124.
 
 
code:
 
 
 	  | Code: | 	 		  
 
#include <18F67K22.h>
 
#device adc=12
 
#device PASS_STRINGS = IN_RAM
 
 
#FUSES WDT_SW, WDT32768, INTRC_IO, NOPROTECT, NOIESO, BROWNOUT, PUT, NOCPD, STVREN, NODEBUG, NOWRT, NOWRTD, NOEBTR, NOCPB, NOEBTRB, NOWRTC, NOWRTB, FCMEN, NOXINST, MCLR, RTCOSC_T1
 
#use delay(clock=16000000)
 
 
#int_timer1
 
void timer1_isr(void)
 
{
 
   output_toggle(PIN_E1);
 
}
 
 
void main()
 
{
 
   delay_ms(1000);
 
   output_low(PIN_E1);
 
   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_ENABLE_SOSC); //no T1_CLK_OUT
 
   
 
   enable_interrupts(INT_TIMER1);
 
   enable_interrupts(GLOBAL);
 
   
 
   while(1);
 
}
 
 | 	  
 
 
.lst file for 4.124
 
 	  | Code: | 	 		  
 
CCS PCH C Compiler, Version 4.124, 5967               12-Jan-15 12:21
 
 
               Filename: E:\bryan\FIRMWARE 2014\timer1test.lst
 
 
               ROM used: 324 bytes (0%)
 
                         Largest free fragment is 65536
 
               RAM used: 28 (1%) at main() level
 
                         29 (1%) worst case
 
               Stack:    2 worst case (1 in main + 1 for interrupts)
 
 
*
 
00000:  GOTO   00F2
 
*
 
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  FF8,18
 
00048:  MOVFF  FFB,19
 
0004C:  MOVFF  00,0E
 
00050:  MOVFF  01,0F
 
00054:  MOVFF  02,10
 
00058:  MOVFF  03,11
 
0005C:  BTFSS  F9D.0
 
0005E:  GOTO   0068
 
00062:  BTFSC  F9E.0
 
00064:  GOTO   00BE
 
00068:  MOVFF  0E,00
 
0006C:  MOVFF  0F,01
 
00070:  MOVFF  10,02
 
00074:  MOVFF  11,03
 
00078:  MOVFF  0C,FE9
 
0007C:  MOVFF  07,FEA
 
00080:  BSF    07.7
 
00082:  MOVFF  08,FE1
 
00086:  MOVFF  09,FE2
 
0008A:  MOVFF  0A,FD9
 
0008E:  MOVFF  0B,FDA
 
00092:  MOVFF  12,FF3
 
00096:  MOVFF  13,FF4
 
0009A:  MOVFF  14,FFA
 
0009E:  MOVFF  15,FF5
 
000A2:  MOVFF  16,FF6
 
000A6:  MOVFF  17,FF7
 
000AA:  MOVFF  18,FF8
 
000AE:  MOVFF  19,FFB
 
000B2:  MOVF   04,W
 
000B4:  MOVFF  06,FE0
 
000B8:  MOVFF  05,FD8
 
000BC:  RETFIE 0
 
.................... #include <18F67K22.h> 
 
.................... //////// Standard Header file for the PIC18F67K22 device //////////////// 
 
.................... #device PIC18F67K22 
 
.................... #list 
 
....................  
 
.................... #device adc=12 
 
.................... #device PASS_STRINGS = IN_RAM 
 
....................  
 
.................... #FUSES WDT_SW, WDT32768, INTRC_IO, NOPROTECT, NOIESO, BROWNOUT, PUT, NOCPD, STVREN, NODEBUG, NOWRT, NOWRTD, NOEBTR, NOCPB, NOEBTRB, NOWRTC, NOWRTB, FCMEN, NOXINST, MCLR, RTCOSC_T1 
 
.................... #use delay(clock=16000000) 
 
*
 
000C8:  CLRF   FEA
 
000CA:  MOVLW  1C
 
000CC:  MOVWF  FE9
 
000CE:  MOVF   FEF,W
 
000D0:  BZ    00EE
 
000D2:  MOVLW  05
 
000D4:  MOVWF  01
 
000D6:  CLRF   00
 
000D8:  DECFSZ 00,F
 
000DA:  BRA    00D8
 
000DC:  DECFSZ 01,F
 
000DE:  BRA    00D6
 
000E0:  MOVLW  2E
 
000E2:  MOVWF  00
 
000E4:  DECFSZ 00,F
 
000E6:  BRA    00E4
 
000E8:  BRA    00EA
 
000EA:  DECFSZ FEF,F
 
000EC:  BRA    00D2
 
000EE:  GOTO   012A (RETURN)
 
....................  
 
.................... #int_timer1 
 
.................... void timer1_isr(void) 
 
.................... { 
 
....................    output_toggle(PIN_E1); 
 
*
 
000BE:  BCF    F96.1
 
000C0:  BTG    F8D.1
 
.................... } 
 
....................  
 
000C2:  BCF    F9E.0
 
000C4:  GOTO   0068
 
.................... void main() 
 
.................... { 
 
*
 
000F2:  CLRF   FF8
 
000F4:  BCF    FD0.7
 
000F6:  BSF    07.7
 
000F8:  CLRF   FEA
 
000FA:  CLRF   FE9
 
000FC:  MOVLW  72
 
000FE:  MOVWF  FD3
 
00100:  CLRF   F9B
 
00102:  CLRF   F64
 
00104:  MOVLB  1
 
00106:  CLRF   x88
 
00108:  MOVLW  00
 
0010A:  MOVLB  F
 
0010C:  MOVWF  x23
 
0010E:  MOVWF  x24
 
00110:  MOVWF  x25
 
00112:  BCF    FC1.3
 
00114:  BCF    FC1.4
 
00116:  BCF    FC1.5
 
00118:  CLRF   x2E
 
0011A:  CLRF   x2F
 
0011C:  CLRF   x54
 
....................    delay_ms(1000); 
 
0011E:  MOVLW  04
 
00120:  MOVWF  1B
 
00122:  MOVLW  FA
 
00124:  MOVWF  1C
 
00126:  MOVLB  0
 
00128:  BRA    00C8
 
0012A:  DECFSZ 1B,F
 
0012C:  BRA    0130
 
0012E:  BRA    0134
 
00130:  MOVLB  F
 
00132:  BRA    0122
 
....................    output_low(PIN_E1); 
 
00134:  BCF    F96.1
 
00136:  BCF    F8D.1
 
....................    setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_ENABLE_SOSC); //no T1_CLK_OUT 
 
00138:  MOVLW  8F
 
0013A:  MOVWF  FCD
 
0013C:  CLRF   FAA
 
....................     
 
....................    enable_interrupts(INT_TIMER1); 
 
0013E:  BSF    F9D.0
 
....................    enable_interrupts(GLOBAL); 
 
00140:  MOVLW  C0
 
00142:  IORWF  FF2,F
 
....................     
 
....................    while(1); 
 
00144:  BRA    0144
 
.................... } 
 
00146:  SLEEP 
 
 
Configuration Fuses:
 
   Word  1: 481D   VREGSLEEP INTRC_HP SOSC_HIGH NOXINST INTRC_IO NOPLLEN FCMEN NOIESO
 
   Word  2: 3E7E   PUT BROWNOUT BORV18 ZPBORM WDT_SW WDT32768
 
   Word  3: 8901   RTCOSC_T1 CCP2C1 MSSPMSK7 MCLR
 
   Word  4: 0091   STVREN BBSIZ2K NODEBUG
 
   Word  5: C0FF   NOPROTECT NOCPB NOCPD
 
   Word  6: E0FF   NOWRT NOWRTC NOWRTB NOWRTD
 
   Word  7: 40FF   NOEBTR NOEBTRB
 
 
 | 	  
 
 
.lst file for 4.141
 
 	  | Code: | 	 		  
 
CCS PCH C Compiler, Version 4.141, 39552               12-Jan-15 12:27
 
 
               Filename:   D:\FILES\FIRMWARE 2014\timer1samp.lst
 
 
               ROM used:   322 bytes (0%)
 
                           Largest free fragment is 65536
 
               RAM used:   28 (1%) at main() level
 
                           29 (1%) worst case
 
               Stack:     2 worst case (1 in main + 1 for interrupts)
 
 
00000:  GOTO   00F2
 
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  FF8,18
 
00048:  MOVFF  FFB,19
 
0004C:  MOVFF  00,0E
 
00050:  MOVFF  01,0F
 
00054:  MOVFF  02,10
 
00058:  MOVFF  03,11
 
0005C:  BTFSS  F9D.0
 
0005E:  GOTO   0068
 
00062:  BTFSC  F9E.0
 
00064:  GOTO   00BE
 
00068:  MOVFF  0E,00
 
0006C:  MOVFF  0F,01
 
00070:  MOVFF  10,02
 
00074:  MOVFF  11,03
 
00078:  MOVFF  0C,FE9
 
0007C:  MOVFF  07,FEA
 
00080:  BSF    07.7
 
00082:  MOVFF  08,FE1
 
00086:  MOVFF  09,FE2
 
0008A:  MOVFF  0A,FD9
 
0008E:  MOVFF  0B,FDA
 
00092:  MOVFF  12,FF3
 
00096:  MOVFF  13,FF4
 
0009A:  MOVFF  14,FFA
 
0009E:  MOVFF  15,FF5
 
000A2:  MOVFF  16,FF6
 
000A6:  MOVFF  17,FF7
 
000AA:  MOVFF  18,FF8
 
000AE:  MOVFF  19,FFB
 
000B2:  MOVF   04,W
 
000B4:  MOVFF  06,FE0
 
000B8:  MOVFF  05,FD8
 
000BC:  RETFIE 0
 
.................... #include <18F67K22.h> 
 
.................... //////// Standard Header file for the PIC18F67K22 device //////////////// 
 
.................... #device PIC18F67K22 
 
.................... #list 
 
....................  
 
.................... #device adc=12 
 
.................... #device PASS_STRINGS = IN_RAM 
 
....................  
 
.................... #FUSES WDT_SW, WDT32768, INTRC_IO, NOPROTECT, NOIESO, BROWNOUT, PUT, NOCPD, STVREN, NODEBUG, NOWRT, NOWRTD, NOEBTR, NOCPB, NOEBTRB, NOWRTC, NOWRTB, FCMEN, NOXINST, MCLR, RTCOSC_T1 
 
.................... #use delay(clock=16000000) 
 
000C8:  CLRF   FEA
 
000CA:  MOVLW  1C
 
000CC:  MOVWF  FE9
 
000CE:  MOVF   FEF,W
 
000D0:  BZ    00EE
 
000D2:  MOVLW  05
 
000D4:  MOVWF  01
 
000D6:  CLRF   00
 
000D8:  DECFSZ 00,F
 
000DA:  BRA    00D8
 
000DC:  DECFSZ 01,F
 
000DE:  BRA    00D6
 
000E0:  MOVLW  2E
 
000E2:  MOVWF  00
 
000E4:  DECFSZ 00,F
 
000E6:  BRA    00E4
 
000E8:  BRA    00EA
 
000EA:  DECFSZ FEF,F
 
000EC:  BRA    00D2
 
000EE:  GOTO   0128 (RETURN)
 
....................  
 
.................... #int_timer1 
 
.................... void timer1_isr(void) 
 
.................... { 
 
....................    output_toggle(PIN_E1); 
 
000BE:  BCF    F96.1
 
000C0:  BTG    F8D.1
 
.................... } 
 
....................  
 
000C2:  BCF    F9E.0
 
000C4:  GOTO   0068
 
.................... void main() 
 
.................... { 
 
000F2:  CLRF   FF8
 
000F4:  BCF    FD0.7
 
000F6:  BSF    07.7
 
000F8:  MOVLW  72
 
000FA:  MOVWF  FD3
 
000FC:  CLRF   F9B
 
000FE:  CLRF   F64
 
00100:  MOVLW  00
 
00102:  MOVLB  F
 
00104:  MOVWF  x23
 
00106:  MOVWF  x24
 
00108:  MOVWF  x25
 
0010A:  BCF    FC1.3
 
0010C:  BCF    FC1.4
 
0010E:  BCF    FC1.5
 
00110:  MOVLB  1
 
00112:  CLRF   x88
 
00114:  MOVLB  F
 
00116:  CLRF   x2E
 
00118:  CLRF   x2F
 
0011A:  CLRF   x54
 
....................    delay_ms(1000); 
 
0011C:  MOVLW  04
 
0011E:  MOVWF  1B
 
00120:  MOVLW  FA
 
00122:  MOVWF  1C
 
00124:  MOVLB  0
 
00126:  BRA    00C8
 
00128:  DECFSZ 1B,F
 
0012A:  BRA    012E
 
0012C:  BRA    0132
 
0012E:  MOVLB  F
 
00130:  BRA    0120
 
....................    output_low(PIN_E1); 
 
00132:  BCF    F96.1
 
00134:  BCF    F8D.1
 
....................    setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_ENABLE_SOSC); //no T1_CLK_OUT 
 
00136:  MOVLW  8F
 
00138:  MOVWF  FCD
 
0013A:  CLRF   FAA
 
....................     
 
....................    enable_interrupts(INT_TIMER1); 
 
0013C:  BSF    F9D.0
 
....................    enable_interrupts(GLOBAL); 
 
0013E:  MOVLW  C0
 
00140:  IORWF  FF2,F
 
....................     
 
....................    while(1); 
 
00142:  BRA    0142
 
.................... } 
 
00144:  SLEEP 
 
 
Configuration Fuses:
 
   Word  1: 4815   VREGSLEEP INTRC_HP SOSC_DIG NOXINST INTRC_IO NOPLLEN FCMEN NOIESO
 
   Word  2: 3E7E   PUT BROWNOUT BORV18 ZPBORM WDT_SW WDT32768
 
   Word  3: 8901   RTCOSC_T1 CCP2C1 MSSPMSK7 MCLR
 
   Word  4: 0091   STVREN BBSIZ2K NODEBUG
 
   Word  5: C0FF   NOPROTECT NOCPB NOCPD
 
   Word  6: E0FF   NOWRT NOWRTC NOWRTB NOWRTD
 
   Word  7: 40FF   NOEBTR NOEBTRB
 
 
 | 	 
  | 
			 
		  | 
	 
	
		  | 
	 
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Jan 12, 2015 12:14 am     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | Quote: | 	 		  |  why code involving timer1 will work on one version (4.124) and it wont work on (4.141).  | 	  
 
Download the free version of Examdiff (vs. 1.9, exe).  Compare both files:
 
http://www.prestosoft.com/edp_examdiff.asp
 
The first line of #fuses has a difference.   It's the reason. | 
			 
		  | 
	 
	
		  | 
	 
	
		
			overmindx
 
 
  Joined: 06 Oct 2008 Posts: 43
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Jan 12, 2015 12:46 am     | 
				     | 
			 
			
				
  | 
			 
			
				| thank you PCM programmer.. | 
			 
		  | 
	 
	
		  | 
	 
	
		 | 
	 
 
  
	 
	    
	   | 
	
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
  
		 |