I want to use timerB to generate an interrupt every 1ms. I try it several times but without success. Here my initialisation of timerB TBCR1 = 0b01000000; TBCR2 = 0b00001000; TBRS = 0b00000000; In Interrupt of timerB: -------------------------------------- int Temp; if((TBSR & 0b01000000) != 0) { #asm ld A,_TBOC1LR add A,#$E3 ld Y,A ld A,_TBOC1HR adc A,#$03 ld _TBOC1HR,A ld A,Y ld _TBOC1LR,A #endasm } Temp = TBOC2LR; ------------------------------------ I use ST72521. Who can help me and can me say if the code is ok? regards, Ampel
void timb_rt(void) { unsigned int timer; if (ValBit(TBSR,6)) { timer=TBOC1HR< timer+=TBOC1LR; timer+= 1000; // int every 1 ms - depends of crystal // & prediviser settings TBOC1HR=timer>>8; TBOC1LR=timer; ... } } Happy programming! F
But is the same code I write only in other words. But now I have another problem with ST72521: I enable all interrupt with ''rim'' but none of this reached. So I searched for a ''initialisation bit'' who enable all interrupts. Is there any bit I can write and all interrupts enable? (PS:sorry,my english is bad...) regards, Ampel
There are 2 output compare interrupts/timer. You are currently using OCF1 (bit 6 of TBSR)...Do you clear the OCF2 bit by reading the TBOC2LR register? If not, you have to, otherwise the code execution might be frozen. Here's an example: void timb_rt(void) { unsigned int timer; if (ValBit(TBSR,6)) { timer=TBOC1HR< timer+=TBOC1LR; timer+= 1000; TBOC1HR=timer>>8; TBOC1LR=timer; ... } else TBOC2LR; // means read the register and clear OCF2!! } } Please remember that once you have enable the output compare int, both sources (OCF1 & OCF2 event) are enabled: so you have to care of both cases. By the way, for 1 ms delay, using 16 Mhz crystal, you should add 0x3e8 better than 0x3e3. Cheers! Florent
Ok, I understand. I have this in my code: ''else TBOC2LR; ''
My problem is now another one: All interrupts are enabled with ''rim''. I mean timerA, timerB, EINT0..3, CAN, SCI, SPI, I2C,...... So, if an interrupt is pending, the code of interrupt should be execute. I use the debugger inDART ST7 from SofTecMicrosystems (v.1.11) and my own application. I insert breakpoints to all routines of interrupts and run the application. But nothing happens. I mean: no breakpoint is jumped. I have my code reduced with an empty main loop. And the interrupts are enabled. But nothing happens! I can't find the bug! Is there an problem with initialisation or link command file or anything else I can do wrong? regards, Ampel
I guess that you have a problem in your .prm/map file...Here's my prm file for the ST72321 (= ST72521 minus the CAN device). Please check it!
LINK example.abs NAMES main.o St72321.o+ /* ''+'' is mandatory !!!! */ inter.o libr.o /* STARTUP */ ansi.lib END STACKSIZE 0xFF SECTIONS BITS_RAM = READ_WRITE 0x0080 TO 0x00FF; MYSTACK = READ_WRITE 0x0100 TO 0x01FF; BYTE_RAM = READ_WRITE 0x0200 TO 0x087F; /* 2K RAM */ USER_ROM = READ_ONLY 0x1000 TO 0xFFDF; PLACEMENT ST7_PA INTO NO_INIT 0x0000 TO 0x0002; ST7_PB INTO NO_INIT 0x0003 TO 0x0005; ST7_PC INTO NO_INIT 0x0006 TO 0x0008; ST7_PD INTO NO_INIT 0x0009 TO 0x000b; ST7_PE INTO NO_INIT 0x000c TO 0x000e; ST7_PF INTO NO_INIT 0x000f TO 0x0011; ST7_I2C INTO NO_INIT 0x0018 TO 0x001e; ST7_SPI INTO NO_INIT 0x0021 TO 0x0023; ST7_ITC INTO NO_INIT 0x0024 TO 0x0028; ST7_FLASH INTO NO_INIT 0x0029 TO 0x0029; ST7_WDG INTO NO_INIT 0x002A TO 0x002B; ST7_MCC INTO NO_INIT 0x002C TO 0x002D; ST7_TIMA INTO NO_INIT 0x0031 TO 0x003F; ST7_TIMB INTO NO_INIT 0x0041 TO 0x004F; ST7_SCI INTO NO_INIT 0x0050 TO 0x0057; ST7_ADC INTO NO_INIT 0x0070 TO 0x0072; ST7_PWMART INTO NO_INIT 0x0073 TO 0x007d; DEFAULT_ROM, ROM_VAR, STRINGS INTO USER_ROM; DEFAULT_RAM INTO BYTE_RAM; _ZEROPAGE, _OVERLAP INTO BITS_RAM; SSTACK INTO MYSTACK; END PRESTART OFF /* INTERRUPT VECTOR SETTING : ADDRESS - ROUTINE */ VECTOR ADDRESS 0xfffe main VECTOR ADDRESS 0xfffc INT_TRAP VECTOR ADDRESS 0xfffa INT_TLI VECTOR ADDRESS 0xfff8 INT_MCC VECTOR ADDRESS 0xfff6 INT_PortA0123 VECTOR ADDRESS 0xfff4 INT_PortF012 VECTOR ADDRESS 0xfff2 INT_PortB0123 VECTOR ADDRESS 0xfff0 INT_PortB4567 VECTOR ADDRESS 0xffee dummy_rt VECTOR ADDRESS 0xffec INT_Spi VECTOR ADDRESS 0xffea INT_TimerA VECTOR ADDRESS 0xffe8 INT_TimerB VECTOR ADDRESS 0xffe6 INT_Sci VECTOR ADDRESS 0xffe4 INT_AVD VECTOR ADDRESS 0xffe2 INT_I2C VECTOR ADDRESS 0xffe0 INT_PWMART /***** End of File **********/ Please check your configuration files as well (default.env, makefile, map file) and your it.c file -> #pragma TRAP_PROC SAVE_REGS before each int routine! Rgds Florent
To generate output compare interrupts, you just need to configure the TimerB registers and reset the interrupt mask: your init code seems OK. The problem is somewhere else...a wrong placement of the hardware registers, and nothing can work! So please check once again your batch file/hardware registers declaration/.... -> you can check as well the .map file generated by the compiler to see if all the hardware registers/IT vectors are well placed.