|
|
View previous topic :: View next topic |
Author |
Message |
Prashant Patel
Joined: 19 Jul 2004 Posts: 33
|
fast interrupt |
Posted: Tue Dec 21, 2004 9:12 pm |
|
|
Hi..
We are using 18F4525 using PCH compiler and 10 Mhz*4=40MHz.
There are three interrupts now i.e RTCC, CCP2 and Timer3. And we are
going to add two more interrupt CCP1 and Timer1.
Right now there are three interrupts now i.e RTCC, CCP2 and Timer3.
The CCP2 is used for measuring frequency of 2KHz thus fast interrupt.
And same way RTCC is used for generating frequency of 2KHz puls or minus
some frequency thus it is also fast.
The problem is the pulses generating by RTCC is some times having
different pulse width then it should be. Thus disturbed.
What should I do to have interrupt to do not disturb each other.
I have used Interrupt Priority but it does not work.
If I use fast interrupt then output of RTCC interrupt is stable but it is
disturbing the other functionalities. I read in the CCS book that we need
to write separate code for saving register vales etc. But I don't know
assembly. What should I write inside the interrupt when I use "fast"
keyword.
Quote: |
#INT_RTCC fast
void timer0_isr() {
//what code should be here when there is fast keyword used
//I don't know assembly much....
}
|
Is this the write way?
Can it be anyother reason due to which these interrupts effecting eachother?
Any answer appreciated....Thanks.... |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Tue Dec 21, 2004 11:11 pm |
|
|
You need to code in a way that fast ints doesnt use the scratch registers, it can be done.
Code, compile and watch the generated asm for reads/writes in the first 10 ram positions. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Dec 22, 2004 3:04 pm |
|
|
In order to use fast interrupts you'll have to learn assembly! You can write the interrupt handler in C but because you manually have to save any changed registers you'll have to study the generated assembly code to find out which are the registers changed. Assembly language for the PIC processors is not very hard to learn and you don't need a deep knowledge in order to understand the code the compiler has generated.
You'll have to study the generated assembly code for any registers that might need saving, like the FSR0L and FSR0H registers. As Future already pointed you'll have especially to look for the low memory RAM locations in about the range 0x00 to 0x10 which the compiler uses as working registers.
An example:
Code: | unsigned char FSR0H;
#locate FSR0H=0x0FEA
unsigned char FSR0L;
#locate FSR0L=0x0FE9
int8 save_fsr0l; // Save register during interrupt
int8 save_fsr0h; // Save register during interrupt
int8 save_scratch3; // Save register during interrupt
#INT_EXT FAST
void ext0_isr()
{
// Save all used registers.
// The PIC18Fxxx series provide a Fast Register Stack for automatic
// storage of the Status, Wreg and BSR registers during interrupts so we
// don't have to save those registers here manually.
// The other registers saved below have to be determined from studying the
// generated assembly code.
save_fsr0l = FSR0L;
save_fsr0h = FSR0H;
save_scratch3 = *3; // Save working register 3
// Your code goes here
// Restore registers
FSR0L = save_fsr0l;
FSR0H = save_fsr0h;
*3 = save_scratch3; // restore working register 3
} |
Remark: A risk of writing this interrupt handler in C is that when changing to another version of the compiler it is possible other register combinations are used. So with every compiler update you'll have to check this routine again. Many people code the fast interrupt in assembly just to avoid this hassle. |
|
|
Prashant Patel
Joined: 19 Jul 2004 Posts: 33
|
|
Posted: Wed Dec 22, 2004 6:07 pm |
|
|
Excellent ckielstra......
Can you please do me favour?
Can you indicate which are the registers used and I need to save and
restore them at the end of the interrupt. I check it but having trouble
in deciding which register are used.
Here is the code of ISR in assembly.
Quote: |
//----------------------------------------------------------------
#INT_RTCC fast
void timer0_isr() {
MOVF 0x22, F, ACCESS
BNZ 0x342
MOVF 0x23, F, ACCESS
BTFSC 0xfd8, 0x2, ACCESS
BRA 0x460
BTFSS 0x19, 0x1, ACCESS
BRA 0x3a6
MOVFF 0x23, 0x46
MOVFF 0x22, 0x45
BRA 0x15a
MOVLW 0x80
MOVWF 0x5a, ACCESS
MOVLW 0x96
MOVWF 0x59, ACCESS
MOVLW 0x18
MOVWF 0x58, ACCESS
MOVLW 0x94
MOVWF 0x57, ACCESS
MOVFF 0x3, 0x5e
MOVFF 0x2, 0x5d
MOVFF 0x1, 0x5c
MOVFF 0, 0x5b
RCALL 0x194
MOVFF 0x3, 0x5a
MOVFF 0x2, 0x59
MOVFF 0x1, 0x58
MOVFF 0, 0x57
RCALL 0x2f2
MOVFF 0x3, 0x2b
MOVFF 0x2, 0x2a
MOVFF 0x1, 0x29
MOVFF 0, 0x28
MOVFF 0x2b, 0x2f
MOVFF 0x2a, 0x2e
MOVFF 0x29, 0x2d
MOVFF 0x28, 0x2c
BCF 0x19, 0x1, ACCESS
BTFSS 0x19, 0x2, ACCESS
BRA 0x3be
BTFSC 0x19, 0, ACCESS
BRA 0x3b6
BSF 0x19, 0, ACCESS
BCF 0xf94, 0x5, ACCESS
BSF 0xf8b, 0x5, ACCESS
BRA 0x3bc
BCF 0x19, 0, ACCESS
BCF 0xf94, 0x5, ACCESS
BCF 0xf8b, 0x5, ACCESS
BCF 0x19, 0x2, ACCESS
MOVF 0x28, F, ACCESS
BNZ 0x3ce
MOVF 0x29, F, ACCESS
BNZ 0x3ce
MOVF 0x2a, F, ACCESS
BNZ 0x3ce
MOVF 0x2b, F, ACCESS
BZ 0x40e
MOVF 0x2b, F, ACCESS
BNZ 0x3d8
MOVF 0x2a, W, ACCESS
SUBLW 0
BC 0x3ec
MOVLW 0
SUBWF 0x28, F, ACCESS
SUBWFB 0x29, F, ACCESS
MOVLW 0x1
SUBWFB 0x2a, F, ACCESS
MOVLW 0
SUBWFB 0x2b, F, ACCESS
CLRF 0xfd7, ACCESS
CLRF 0xfd6, ACCESS
BRA 0x40c
MOVLW 0xff
BSF 0xfd8, 0, ACCESS
SUBFWB 0x28, W, ACCESS
MOVWF 0x45, ACCESS
MOVLW 0xff
SUBFWB 0x29, W, ACCESS
MOVWF 0x46, ACCESS
MOVFF 0x46, 0xfd7
MOVFF 0x45, 0xfd6
CLRF 0x2b, ACCESS
CLRF 0x2a, ACCESS
CLRF 0x29, ACCESS
CLRF 0x28, ACCESS
BSF 0x19, 0x2, ACCESS
BRA 0x45e
MOVF 0x2c, F, ACCESS
BNZ 0x41e
MOVF 0x2d, F, ACCESS
BNZ 0x41e
MOVF 0x2e, F, ACCESS
BNZ 0x41e
MOVF 0x2f, F, ACCESS
BZ 0x45e
MOVF 0x2f, F, ACCESS
BNZ 0x428
MOVF 0x2e, W, ACCESS
SUBLW 0
BC 0x43c
MOVLW 0
SUBWF 0x2c, F, ACCESS
SUBWFB 0x2d, F, ACCESS
MOVLW 0x1
SUBWFB 0x2e, F, ACCESS
MOVLW 0
SUBWFB 0x2f, F, ACCESS
CLRF 0xfd7, ACCESS
CLRF 0xfd6, ACCESS
BRA 0x45e
MOVLW 0xff
BSF 0xfd8, 0, ACCESS
SUBFWB 0x2c, W, ACCESS
MOVWF 0x45, ACCESS
MOVLW 0xff
SUBFWB 0x2d, W, ACCESS
MOVWF 0x46, ACCESS
MOVFF 0x46, 0xfd7
MOVFF 0x45, 0xfd6
CLRF 0x2f, ACCESS
CLRF 0x2e, ACCESS
CLRF 0x2d, ACCESS
CLRF 0x2c, ACCESS
BSF 0x19, 0x1, ACCESS
BSF 0x19, 0x2, ACCESS
BRA 0x466
BCF 0x19, 0, ACCESS
BCF 0xf94, 0x5, ACCESS
BCF 0xf8b, 0x5, ACCESS
BCF 0xff2, 0x2, ACCESS
RETFIE 0x1
}
//---------------------------------------------------------------------
|
Thanks in advanced........... |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Dec 23, 2004 4:04 am |
|
|
Quote: | BRA 0x15a
MOVLW 0x80
MOVWF 0x5a, ACCESS
MOVLW 0x96
MOVWF 0x59, ACCESS
MOVLW 0x18
MOVWF 0x58, ACCESS
MOVLW 0x94
MOVWF 0x57, ACCESS
MOVFF 0x3, 0x5e
MOVFF 0x2, 0x5d
MOVFF 0x1, 0x5c
MOVFF 0, 0x5b
RCALL 0x194
MOVFF 0x3, 0x5a
MOVFF 0x2, 0x59
MOVFF 0x1, 0x58
MOVFF 0, 0x57
RCALL 0x2f2
| Your code is not complete, several jumps to other functions are performed here and you will have to check those as well. I can see several of these functions return a 32-bit value in the registers 0 - 3, so these registers will have to be saved as well.
Without inspecting the missing functions I can't say anything about possible other registers that need to be saved. |
|
|
Prashant Patel
Joined: 19 Jul 2004 Posts: 33
|
|
Posted: Thu Dec 23, 2004 4:05 pm |
|
|
Hi...
I must use the fast interrupt but having big trouble.
I tried to save and restore the registers 0 to 3 like this
Quote: |
unsigned char R0;
#locate R0 = 0x1
|
but compiler is throughing error that
Quote: |
Constant out of the valid range 000 is reserved by the compiler
Constant out of the valid range 001 is reserved by the compiler
Constant out of the valid range 002 is reserved by the compiler
Constant out of the valid range 003 is reserved by the compiler
|
I have also tried to save and restore WREG,BSR and STATUS registers
but I think it does not solve the original problem.
Here is the whole program with C and Assembly code.
I want the INT_RTCC interrupt to be the fast interrupt. Please check
its ISR on line number: 35 and I have indicate it like following
/*########################################*/
Please tell me exactly which registers are used and How can we save and
restore it? Because for register 0 and have tried
unsigned char R0;
#locate R0 = 0x1
But giving the error above. Then what exactly I should write?
Quote: |
--- C:\PROGRA~1\PICC\devices\18F4525.h ---------------------------------------------------------
1: //////// Standard Header file for the PIC18F4525 device ////////////////
2: #device PIC18F4525
0000AE 0E8E MOVLW 0x8e
0000B0 6E00 MOVWF 0, ACCESS
0000B2 C035 MOVFF 0x35, 0x1
0000B6 C034 MOVFF 0x34, 0x2
0000BA 6A03 CLRF 0x3, ACCESS
0000BC 5201 MOVF 0x1, F, ACCESS
0000BE E109 BNZ 0xd2
0000C0 C002 MOVFF 0x2, 0x1
0000C4 6A02 CLRF 0x2, ACCESS
0000C6 0E08 MOVLW 0x8
0000C8 5E00 SUBWF 0, F, ACCESS
0000CA 5201 MOVF 0x1, F, ACCESS
0000CC E102 BNZ 0xd2
0000CE 6A00 CLRF 0, ACCESS
0000D0 D008 BRA 0xe2
0000D2 90D8 BCF 0xfd8, 0, ACCESS
0000D4 BE01 BTFSC 0x1, 0x7, ACCESS
0000D6 D004 BRA 0xe0
0000D8 3602 RLCF 0x2, F, ACCESS
0000DA 3601 RLCF 0x1, F, ACCESS
0000DC 0600 DECF 0, F, ACCESS
0000DE D7F9 BRA 0xd2
0000E0 9E01 BCF 0x1, 0x7, ACCESS
0000E2 0000 NOP
0000E4 EF58 GOTO 0x2b0
0000E8 5046 MOVF 0x46, W, ACCESS
0000EA B4D8 BTFSC 0xfd8, 0x2, ACCESS
0000EC D0A6 BRA 0x23a
0000EE 6E52 MOVWF 0x52, ACCESS
0000F0 504A MOVF 0x4a, W, ACCESS
0000F2 B4D8 BTFSC 0xfd8, 0x2, ACCESS
0000F4 D0A2 BRA 0x23a
0000F6 5E52 SUBWF 0x52, F, ACCESS
0000F8 E201 BC 0xfc
0000FA D005 BRA 0x106
0000FC 0E7F MOVLW 0x7f
0000FE 2652 ADDWF 0x52, F, ACCESS
000100 B0D8 BTFSC 0xfd8, 0, ACCESS
000102 D09B BRA 0x23a
000104 D006 BRA 0x112
000106 0E81 MOVLW 0x81
000108 5E52 SUBWF 0x52, F, ACCESS
00010A A0D8 BTFSS 0xfd8, 0, ACCESS
00010C D096 BRA 0x23a
00010E B4D8 BTFSC 0xfd8, 0x2, ACCESS
000110 D094 BRA 0x23a
000112 C052 MOVFF 0x52, 0
000116 6A01 CLRF 0x1, ACCESS
000118 6A02 CLRF 0x2, ACCESS
00011A 6A03 CLRF 0x3, ACCESS
00011C 6A51 CLRF 0x51, ACCESS
00011E C047 MOVFF 0x47, 0x50
000122 8E50 BSF 0x50, 0x7, ACCESS
000124 C048 MOVFF 0x48, 0x4f
000128 C049 MOVFF 0x49, 0x4e
00012C 0E19 MOVLW 0x19
00012E 6E52 MOVWF 0x52, ACCESS
000130 504D MOVF 0x4d, W, ACCESS
000132 5E4E SUBWF 0x4e, F, ACCESS
000134 E20D BC 0x150
000136 0E01 MOVLW 0x1
000138 5E4F SUBWF 0x4f, F, ACCESS
00013A E20A BC 0x150
00013C 5E50 SUBWF 0x50, F, ACCESS
00013E E208 BC 0x150
000140 5E51 SUBWF 0x51, F, ACCESS
000142 E206 BC 0x150
000144 2A51 INCF 0x51, F, ACCESS
000146 2A50 INCF 0x50, F, ACCESS
000148 2A4F INCF 0x4f, F, ACCESS
00014A 504D MOVF 0x4d, W, ACCESS
00014C 264E ADDWF 0x4e, F, ACCESS
00014E D028 BRA 0x1a0
000150 504C MOVF 0x4c, W, ACCESS
000152 5E4F SUBWF 0x4f, F, ACCESS
000154 E212 BC 0x17a
000156 0E01 MOVLW 0x1
000158 5E50 SUBWF 0x50, F, ACCESS
00015A E20F BC 0x17a
00015C 5E51 SUBWF 0x51, F, ACCESS
00015E E20D BC 0x17a
000160 2A51 INCF 0x51, F, ACCESS
000162 2A50 INCF 0x50, F, ACCESS
000164 504C MOVF 0x4c, W, ACCESS
000166 264F ADDWF 0x4f, F, ACCESS
000168 504D MOVF 0x4d, W, ACCESS
00016A 264E ADDWF 0x4e, F, ACCESS
00016C E319 BNC 0x1a0
00016E 2A4F INCF 0x4f, F, ACCESS
000170 E117 BNZ 0x1a0
000172 2A50 INCF 0x50, F, ACCESS
000174 E115 BNZ 0x1a0
000176 2A51 INCF 0x51, F, ACCESS
000178 D013 BRA 0x1a0
00017A 504B MOVF 0x4b, W, ACCESS
00017C 0980 IORLW 0x80
00017E 5E50 SUBWF 0x50, F, ACCESS
000180 E20E BC 0x19e
000182 0E01 MOVLW 0x1
000184 5E51 SUBWF 0x51, F, ACCESS
000186 E20B BC 0x19e
000188 2A51 INCF 0x51, F, ACCESS
00018A 504B MOVF 0x4b, W, ACCESS
00018C 0980 IORLW 0x80
00018E 2650 ADDWF 0x50, F, ACCESS
000190 504C MOVF 0x4c, W, ACCESS
000192 264F ADDWF 0x4f, F, ACCESS
000194 E3E9 BNC 0x168
000196 2A50 INCF 0x50, F, ACCESS
000198 E1E7 BNZ 0x168
00019A 2A51 INCF 0x51, F, ACCESS
00019C D7E5 BRA 0x168
00019E 8003 BSF 0x3, 0, ACCESS
0001A0 2E52 DECFSZ 0x52, F, ACCESS
0001A2 D001 BRA 0x1a6
0001A4 D00B BRA 0x1bc
0001A6 90D8 BCF 0xfd8, 0, ACCESS
0001A8 364E RLCF 0x4e, F, ACCESS
0001AA 364F RLCF 0x4f, F, ACCESS
0001AC 3650 RLCF 0x50, F, ACCESS
0001AE 3651 RLCF 0x51, F, ACCESS
0001B0 90D8 BCF 0xfd8, 0, ACCESS
0001B2 3603 RLCF 0x3, F, ACCESS
0001B4 3602 RLCF 0x2, F, ACCESS
0001B6 3601 RLCF 0x1, F, ACCESS
0001B8 3653 RLCF 0x53, F, ACCESS
0001BA D7BA BRA 0x130
0001BC A053 BTFSS 0x53, 0, ACCESS
0001BE D006 BRA 0x1cc
0001C0 90D8 BCF 0xfd8, 0, ACCESS
0001C2 3201 RRCF 0x1, F, ACCESS
0001C4 3202 RRCF 0x2, F, ACCESS
0001C6 3203 RRCF 0x3, F, ACCESS
0001C8 3253 RRCF 0x53, F, ACCESS
0001CA D002 BRA 0x1d0
0001CC 0600 DECF 0, F, ACCESS
0001CE E035 BZ 0x23a
0001D0 BE53 BTFSC 0x53, 0x7, ACCESS
0001D2 D01E BRA 0x210
0001D4 90D8 BCF 0xfd8, 0, ACCESS
0001D6 364E RLCF 0x4e, F, ACCESS
0001D8 364F RLCF 0x4f, F, ACCESS
0001DA 3650 RLCF 0x50, F, ACCESS
0001DC 3651 RLCF 0x51, F, ACCESS
0001DE 504D MOVF 0x4d, W, ACCESS
0001E0 5E4E SUBWF 0x4e, F, ACCESS
0001E2 E207 BC 0x1f2
0001E4 0E01 MOVLW 0x1
0001E6 5E4F SUBWF 0x4f, F, ACCESS
0001E8 E204 BC 0x1f2
0001EA 5E50 SUBWF 0x50, F, ACCESS
0001EC E202 BC 0x1f2
0001EE 5E51 SUBWF 0x51, F, ACCESS
0001F0 E31A BNC 0x226
0001F2 504C MOVF 0x4c, W, ACCESS
0001F4 5E4F SUBWF 0x4f, F, ACCESS
0001F6 E205 BC 0x202
0001F8 0E01 MOVLW 0x1
0001FA 5E50 SUBWF 0x50, F, ACCESS
0001FC E202 BC 0x202
0001FE 5E51 SUBWF 0x51, F, ACCESS
000200 E312 BNC 0x226
000202 504B MOVF 0x4b, W, ACCESS
000204 0980 IORLW 0x80
000206 5E50 SUBWF 0x50, F, ACCESS
000208 E203 BC 0x210
00020A 0E01 MOVLW 0x1
00020C 5E51 SUBWF 0x51, F, ACCESS
00020E E30B BNC 0x226
000210 2A03 INCF 0x3, F, ACCESS
000212 E109 BNZ 0x226
000214 2A02 INCF 0x2, F, ACCESS
000216 E107 BNZ 0x226
000218 2A01 INCF 0x1, F, ACCESS
00021A E105 BNZ 0x226
00021C 2A00 INCF 0, F, ACCESS
00021E E00D BZ 0x23a
000220 3201 RRCF 0x1, F, ACCESS
000222 3202 RRCF 0x2, F, ACCESS
000224 3203 RRCF 0x3, F, ACCESS
000226 C047 MOVFF 0x47, 0x52
00022A 504B MOVF 0x4b, W, ACCESS
00022C 1A52 XORWF 0x52, F, ACCESS
00022E AE52 BTFSS 0x52, 0x7, ACCESS
000230 D002 BRA 0x236
000232 8E01 BSF 0x1, 0x7, ACCESS
000234 D006 BRA 0x242
000236 9E01 BCF 0x1, 0x7, ACCESS
000238 D004 BRA 0x242
00023A 6A00 CLRF 0, ACCESS
00023C 6A01 CLRF 0x1, ACCESS
00023E 6A02 CLRF 0x2, ACCESS
000240 6A03 CLRF 0x3, ACCESS
000242 0000 NOP
000244 0C00 RETLW 0
000246 5046 MOVF 0x46, W, ACCESS
000248 08B6 SUBLW 0xb6
00024A 6E46 MOVWF 0x46, ACCESS
00024C 6A03 CLRF 0x3, ACCESS
00024E C047 MOVFF 0x47, 0x4a
000252 8E47 BSF 0x47, 0x7, ACCESS
000254 90D8 BCF 0xfd8, 0, ACCESS
000256 3247 RRCF 0x47, F, ACCESS
000258 3248 RRCF 0x48, F, ACCESS
00025A 3249 RRCF 0x49, F, ACCESS
00025C 3203 RRCF 0x3, F, ACCESS
00025E 3202 RRCF 0x2, F, ACCESS
000260 3201 RRCF 0x1, F, ACCESS
000262 3200 RRCF 0, F, ACCESS
000264 2E46 DECFSZ 0x46, F, ACCESS
000266 D7F6 BRA 0x254
000268 AE4A BTFSS 0x4a, 0x7, ACCESS
00026A D00B BRA 0x282
00026C 1E00 COMF 0, F, ACCESS
00026E 1E01 COMF 0x1, F, ACCESS
000270 1E02 COMF 0x2, F, ACCESS
000272 1E03 COMF 0x3, F, ACCESS
000274 2A00 INCF 0, F, ACCESS
000276 B4D8 BTFSC 0xfd8, 0x2, ACCESS
000278 2A01 INCF 0x1, F, ACCESS
00027A B4D8 BTFSC 0xfd8, 0x2, ACCESS
00027C 2A02 INCF 0x2, F, ACCESS
00027E B4D8 BTFSC 0xfd8, 0x2, ACCESS
000280 2A03 INCF 0x3, F, ACCESS
000282 0C00 RETLW 0
0003E2 0EB6 MOVLW 0xb6
0003E4 6E00 MOVWF 0, ACCESS
0003E6 6A03 CLRF 0x3, ACCESS
0003E8 6A02 CLRF 0x2, ACCESS
0003EA 6A01 CLRF 0x1, ACCESS
0003EC 5042 MOVF 0x42, W, ACCESS
0003EE 1043 IORWF 0x43, W, ACCESS
0003F0 1044 IORWF 0x44, W, ACCESS
0003F2 1045 IORWF 0x45, W, ACCESS
0003F4 E102 BNZ 0x3fa
0003F6 6A00 CLRF 0, ACCESS
0003F8 D00D BRA 0x414
0003FA 90D8 BCF 0xfd8, 0, ACCESS
0003FC BE01 BTFSC 0x1, 0x7, ACCESS
0003FE D009 BRA 0x412
000400 3642 RLCF 0x42, F, ACCESS
000402 3643 RLCF 0x43, F, ACCESS
000404 3644 RLCF 0x44, F, ACCESS
000406 3645 RLCF 0x45, F, ACCESS
000408 3603 RLCF 0x3, F, ACCESS
00040A 3602 RLCF 0x2, F, ACCESS
00040C 3601 RLCF 0x1, F, ACCESS
00040E 2E00 DECFSZ 0, F, ACCESS
000410 D7F4 BRA 0x3fa
000412 9E01 BCF 0x1, 0x7, ACCESS
000414 EF64 GOTO 0x4c8
000418 6A00 CLRF 0, ACCESS
00041A 6A01 CLRF 0x1, ACCESS
00041C 6A02 CLRF 0x2, ACCESS
00041E 6A03 CLRF 0x3, ACCESS
000420 6A4A CLRF 0x4a, ACCESS
000422 6A4B CLRF 0x4b, ACCESS
000424 6A4C CLRF 0x4c, ACCESS
000426 6A4D CLRF 0x4d, ACCESS
000428 5049 MOVF 0x49, W, ACCESS
00042A 1048 IORWF 0x48, W, ACCESS
00042C 1047 IORWF 0x47, W, ACCESS
00042E 1046 IORWF 0x46, W, ACCESS
000430 E02C BZ 0x48a
000432 0E20 MOVLW 0x20
000434 6E4E MOVWF 0x4e, ACCESS
000436 90D8 BCF 0xfd8, 0, ACCESS
000438 3642 RLCF 0x42, F, ACCESS
00043A 3643 RLCF 0x43, F, ACCESS
00043C 3644 RLCF 0x44, F, ACCESS
00043E 3645 RLCF 0x45, F, ACCESS
000440 364A RLCF 0x4a, F, ACCESS
000442 364B RLCF 0x4b, F, ACCESS
000444 364C RLCF 0x4c, F, ACCESS
000446 364D RLCF 0x4d, F, ACCESS
000448 5049 MOVF 0x49, W, ACCESS
00044A 5C4D SUBWF 0x4d, W, ACCESS
00044C E108 BNZ 0x45e
00044E 5048 MOVF 0x48, W, ACCESS
000450 5C4C SUBWF 0x4c, W, ACCESS
000452 E105 BNZ 0x45e
000454 5047 MOVF 0x47, W, ACCESS
000456 5C4B SUBWF 0x4b, W, ACCESS
000458 E102 BNZ 0x45e
00045A 5046 MOVF 0x46, W, ACCESS
00045C 5C4A SUBWF 0x4a, W, ACCESS
00045E E30F BNC 0x47e
000460 5046 MOVF 0x46, W, ACCESS
000462 5E4A SUBWF 0x4a, F, ACCESS
000464 5047 MOVF 0x47, W, ACCESS
000466 A0D8 BTFSS 0xfd8, 0, ACCESS
000468 3C47 INCFSZ 0x47, W, ACCESS
00046A 5E4B SUBWF 0x4b, F, ACCESS
00046C 5048 MOVF 0x48, W, ACCESS
00046E A0D8 BTFSS 0xfd8, 0, ACCESS
000470 3C48 INCFSZ 0x48, W, ACCESS
000472 5E4C SUBWF 0x4c, F, ACCESS
000474 5049 MOVF 0x49, W, ACCESS
000476 A0D8 BTFSS 0xfd8, 0, ACCESS
000478 3C49 INCFSZ 0x49, W, ACCESS
00047A 5E4D SUBWF 0x4d, F, ACCESS
00047C 80D8 BSF 0xfd8, 0, ACCESS
00047E 3600 RLCF 0, F, ACCESS
000480 3601 RLCF 0x1, F, ACCESS
000482 3602 RLCF 0x2, F, ACCESS
000484 3603 RLCF 0x3, F, ACCESS
000486 2E4E DECFSZ 0x4e, F, ACCESS
000488 D7D6 BRA 0x436
00048A 0000 NOP
00048C 6AEA CLRF 0xfea, ACCESS
00048E 0E4A MOVLW 0x4a
000490 6EE9 MOVWF 0xfe9, ACCESS
000492 EF9B GOTO 0x536
--- C:\prashant\SimpleVec4525\VecAFMFreq2\SimpleVec1.C -----------------------------------------
1:
000000 EFC0 GOTO 0x580
000008 6E05 MOVWF 0x5, ACCESS
00000A CFD8 MOVFF 0xfd8, 0x6
00000E 50E9 MOVF 0xfe9, W, ACCESS
000010 6E07 MOVWF 0x7, ACCESS
000012 50EA MOVF 0xfea, W, ACCESS
000014 6E08 MOVWF 0x8, ACCESS
000016 50E1 MOVF 0xfe1, W, ACCESS
000018 6E09 MOVWF 0x9, ACCESS
00001A 50E2 MOVF 0xfe2, W, ACCESS
00001C 6E0A MOVWF 0xa, ACCESS
00001E 50D9 MOVF 0xfd9, W, ACCESS
000020 6E0B MOVWF 0xb, ACCESS
000022 50DA MOVF 0xfda, W, ACCESS
000024 6E0C MOVWF 0xc, ACCESS
000026 50F3 MOVF 0xff3, W, ACCESS
000028 6E14 MOVWF 0x14, ACCESS
00002A 50F4 MOVF 0xff4, W, ACCESS
00002C 6E15 MOVWF 0x15, ACCESS
00002E 50E0 MOVF 0xfe0, W, ACCESS
000030 6E0D MOVWF 0xd, ACCESS
000032 0100 MOVLB 0
000034 5000 MOVF 0, W, ACCESS
000036 6E0F MOVWF 0xf, ACCESS
000038 5001 MOVF 0x1, W, ACCESS
00003A 6E10 MOVWF 0x10, ACCESS
00003C 5002 MOVF 0x2, W, ACCESS
00003E 6E11 MOVWF 0x11, ACCESS
000040 5003 MOVF 0x3, W, ACCESS
000042 6E12 MOVWF 0x12, ACCESS
000044 5004 MOVF 0x4, W, ACCESS
000046 6E13 MOVWF 0x13, ACCESS
000048 AAF2 BTFSS 0xff2, 0x5, ACCESS
00004A EF2A GOTO 0x54
00004E B4F2 BTFSC 0xff2, 0x2, ACCESS
000050 EF42 GOTO 0x284
000054 A0A0 BTFSS 0xfa0, 0, ACCESS
000056 EF30 GOTO 0x60
00005A B0A1 BTFSC 0xfa1, 0, ACCESS
00005C EF4B GOTO 0x496
000060 A2A0 BTFSS 0xfa0, 0x1, ACCESS
000062 EF36 GOTO 0x6c
000066 B2A1 BTFSC 0xfa1, 0x1, ACCESS
000068 EFA4 GOTO 0x548
00006C 500F MOVF 0xf, W, ACCESS
00006E 6E00 MOVWF 0, ACCESS
000070 5010 MOVF 0x10, W, ACCESS
000072 6E01 MOVWF 0x1, ACCESS
000074 5011 MOVF 0x11, W, ACCESS
000076 6E02 MOVWF 0x2, ACCESS
000078 5012 MOVF 0x12, W, ACCESS
00007A 6E03 MOVWF 0x3, ACCESS
00007C 5013 MOVF 0x13, W, ACCESS
00007E 6E04 MOVWF 0x4, ACCESS
000080 500D MOVF 0xd, W, ACCESS
000082 6EE0 MOVWF 0xfe0, ACCESS
000084 8E0D BSF 0xd, 0x7, ACCESS
000086 5007 MOVF 0x7, W, ACCESS
000088 6EE9 MOVWF 0xfe9, ACCESS
00008A 5008 MOVF 0x8, W, ACCESS
00008C 6EEA MOVWF 0xfea, ACCESS
00008E 5009 MOVF 0x9, W, ACCESS
000090 6EE1 MOVWF 0xfe1, ACCESS
000092 500A MOVF 0xa, W, ACCESS
000094 6EE2 MOVWF 0xfe2, ACCESS
000096 500B MOVF 0xb, W, ACCESS
000098 6ED9 MOVWF 0xfd9, ACCESS
00009A 500C MOVF 0xc, W, ACCESS
00009C 6EDA MOVWF 0xfda, ACCESS
00009E 5014 MOVF 0x14, W, ACCESS
0000A0 6EF3 MOVWF 0xff3, ACCESS
0000A2 5015 MOVF 0x15, W, ACCESS
0000A4 6EF4 MOVWF 0xff4, ACCESS
0000A6 5005 MOVF 0x5, W, ACCESS
0000A8 C006 MOVFF 0x6, 0xfd8
0000AC 0010 RETFIE 0
2: #CASE
3: #include <18F4525.h>
4: #fuses H4,NOWDT,NOPROTECT,NOLVP,BROWNOUT,PUT,NOPBADEN,NOXINST
5: #use delay(clock=4000000)
000554 6AEA CLRF 0xfea, ACCESS
000556 0E33 MOVLW 0x33
000558 6EE9 MOVWF 0xfe9, ACCESS
00055A 50EF MOVF 0xfef, W, ACCESS
00055C E00F BZ 0x57c
00055E 0E01 MOVLW 0x1
000560 6E01 MOVWF 0x1, ACCESS
000562 6A00 CLRF 0, ACCESS
000564 2E00 DECFSZ 0, F, ACCESS
000566 D7FE BRA 0x564
000568 2E01 DECFSZ 0x1, F, ACCESS
00056A D7FB BRA 0x562
00056C 0E4A MOVLW 0x4a
00056E 6E00 MOVWF 0, ACCESS
000570 2E00 DECFSZ 0, F, ACCESS
000572 D7FE BRA 0x570
000574 0000 NOP
000576 0000 NOP
000578 2EEF DECFSZ 0xfef, F, ACCESS
00057A D7F1 BRA 0x55e
00057C EFE7 GOTO 0x5ce
6:
7:
8: unsigned char FSR0H;
9: #locate FSR0H = 0x0FEA
10:
11: unsigned char FSR0L;
12: #locate FSR0L = 0x0FE9
13:
14: unsigned char WREG;
15: #locate WREG = 0xFE8
16:
17: unsigned char BSR;
18: #locate BSR = 0xFE0
19:
20: unsigned char STATUS;
21: #locate STATUS = 0xFD8
22:
23: int8 save_fsr0l;
24: int8 save_fsr0h;
25:
26: int8 save_wreg,save_bsr,save_status;
27:
28:
29: int1 HighPulse,ChangePulse,ChangeStatus;
30: int16 FinalValue,counttimer1,counttimer3,AFMFreq;
31: int16 FinalAFM;
32: int32 TimerCycle,TimerCyH,TimerCyL;
33:
34: /*########################################*/
35: #INT_RTCC
36: void timer0_isr() {
37:
38:
39: save_fsr0l=FSR0L;
000284 CFE9 MOVFF 0xfe9, 0x17
40: save_fsr0h=FSR0H;
000288 CFEA MOVFF 0xfea, 0x18
41:
42: save_wreg=WREG;
00028C CFE8 MOVFF 0xfe8, 0x19
43: save_bsr=BSR;
000290 CFE0 MOVFF 0xfe0, 0x1a
44: save_status=STATUS;
000294 CFD8 MOVFF 0xfd8, 0x1b
45:
46:
47: if(FinalAFM>0)
000298 5225 MOVF 0x25, F, ACCESS
00029A E103 BNZ 0x2a2
00029C 5226 MOVF 0x26, F, ACCESS
00029E B4D8 BTFSC 0xfd8, 0x2, ACCESS
0002A0 D08F BRA 0x3c0
48: {
49: if(ChangePulse==1)
0002A2 A21C BTFSS 0x1c, 0x1, ACCESS
0002A4 D030 BRA 0x306
50: {
51:
52: TimerCyH = (int32)(2500000.0/(float)FinalAFM);
0002A6 C026 MOVFF 0x26, 0x35
0002AA C025 MOVFF 0x25, 0x34
0002AE D6FF BRA 0xae
0002B0 0E80 MOVLW 0x80
0002B2 6E49 MOVWF 0x49, ACCESS
0002B4 0E96 MOVLW 0x96
0002B6 6E48 MOVWF 0x48, ACCESS
0002B8 0E18 MOVLW 0x18
0002BA 6E47 MOVWF 0x47, ACCESS
0002BC 0E94 MOVLW 0x94
0002BE 6E46 MOVWF 0x46, ACCESS
0002C0 C003 MOVFF 0x3, 0x4d
0002C4 C002 MOVFF 0x2, 0x4c
0002C8 C001 MOVFF 0x1, 0x4b
0002CC C000 MOVFF 0, 0x4a
0002D0 DF0B RCALL 0xe8
0002D2 C003 MOVFF 0x3, 0x49
0002D6 C002 MOVFF 0x2, 0x48
0002DA C001 MOVFF 0x1, 0x47
0002DE C000 MOVFF 0, 0x46
0002E2 DFB1 RCALL 0x246
0002E4 C003 MOVFF 0x3, 0x2e
0002E8 C002 MOVFF 0x2, 0x2d
0002EC C001 MOVFF 0x1, 0x2c
0002F0 C000 MOVFF 0, 0x2b
53: // 2500000:Devide by 2 again devide by 2(Don't know why)
54:
55: //TimerCyH=(int32)((float)TimerCyH/2.0);
56: TimerCyL=TimerCyH;
0002F4 C02E MOVFF 0x2e, 0x32
0002F8 C02D MOVFF 0x2d, 0x31
0002FC C02C MOVFF 0x2c, 0x30
000300 C02B MOVFF 0x2b, 0x2f
57:
58:
59: //TimerCyH=1250;
60: //TimerCyL=1250;
61:
62: ChangePulse=0;
000304 921C BCF 0x1c, 0x1, ACCESS
63:
64: }//if(ChangePulse==1)
65:
66: if(ChangeStatus==1)
000306 A41C BTFSS 0x1c, 0x2, ACCESS
000308 D00A BRA 0x31e
67: {
68: if(HighPulse==0)
00030A B01C BTFSC 0x1c, 0, ACCESS
00030C D004 BRA 0x316
69: {
70: HighPulse=1;
00030E 801C BSF 0x1c, 0, ACCESS
71: output_high(PIN_C5);
000310 9A94 BCF 0xf94, 0x5, ACCESS
000312 8A8B BSF 0xf8b, 0x5, ACCESS
72: }
73: else
000314 D003 BRA 0x31c
74: {
75: HighPulse=0;
000316 901C BCF 0x1c, 0, ACCESS
76: output_low(PIN_C5);
000318 9A94 BCF 0xf94, 0x5, ACCESS
00031A 9A8B BCF 0xf8b, 0x5, ACCESS
77: }//if(HighPulse==1)
78:
79: ChangeStatus=0;
00031C 941C BCF 0x1c, 0x2, ACCESS
80: }//if(ChangeStatus==1)
81:
82: if(TimerCyH>0)
00031E 522B MOVF 0x2b, F, ACCESS
000320 E106 BNZ 0x32e
000322 522C MOVF 0x2c, F, ACCESS
000324 E104 BNZ 0x32e
000326 522D MOVF 0x2d, F, ACCESS
000328 E102 BNZ 0x32e
00032A 522E MOVF 0x2e, F, ACCESS
00032C E020 BZ 0x36e
83: {
84: if(TimerCyH>=65536)
00032E 522E MOVF 0x2e, F, ACCESS
000330 E103 BNZ 0x338
000332 502D MOVF 0x2d, W, ACCESS
000334 0800 SUBLW 0
000336 E20A BC 0x34c
85: {
86: TimerCyH = TimerCyH-65536;
000338 0E00 MOVLW 0
00033A 5E2B SUBWF 0x2b, F, ACCESS
00033C 5A2C SUBWFB 0x2c, F, ACCESS
00033E 0E01 MOVLW 0x1
000340 5A2D SUBWFB 0x2d, F, ACCESS
000342 0E00 MOVLW 0
000344 5A2E SUBWFB 0x2e, F, ACCESS
87: set_timer0(0);
000346 6AD7 CLRF 0xfd7, ACCESS
000348 6AD6 CLRF 0xfd6, ACCESS
88: }
89: else
00034A D010 BRA 0x36c
90: {
91: set_timer0(65535-(int16)TimerCyH);
00034C 0EFF MOVLW 0xff
00034E 80D8 BSF 0xfd8, 0, ACCESS
000350 542B SUBFWB 0x2b, W, ACCESS
000352 6E34 MOVWF 0x34, ACCESS
000354 0EFF MOVLW 0xff
000356 542C SUBFWB 0x2c, W, ACCESS
000358 6E35 MOVWF 0x35, ACCESS
00035A C035 MOVFF 0x35, 0xfd7
00035E C034 MOVFF 0x34, 0xfd6
92: TimerCyH=0;
000362 6A2E CLRF 0x2e, ACCESS
000364 6A2D CLRF 0x2d, ACCESS
000366 6A2C CLRF 0x2c, ACCESS
000368 6A2B CLRF 0x2b, ACCESS
93:
94: //ChangePulse=1;
95:
96: ChangeStatus=1;
00036A 841C BSF 0x1c, 0x2, ACCESS
97:
98: }//if(TimerCyH>=65536)
99:
100: }
101: else if(TimerCyL>0)
00036C D028 BRA 0x3be
00036E 522F MOVF 0x2f, F, ACCESS
000370 E106 BNZ 0x37e
000372 5230 MOVF 0x30, F, ACCESS
000374 E104 BNZ 0x37e
000376 5231 MOVF 0x31, F, ACCESS
000378 E102 BNZ 0x37e
00037A 5232 MOVF 0x32, F, ACCESS
00037C E020 BZ 0x3be
102: {
103: if(TimerCyL>=65536)
00037E 5232 MOVF 0x32, F, ACCESS
000380 E103 BNZ 0x388
000382 5031 MOVF 0x31, W, ACCESS
000384 0800 SUBLW 0
000386 E20A BC 0x39c
104: {
105: TimerCyL = TimerCyL-65536;
000388 0E00 MOVLW 0
00038A 5E2F SUBWF 0x2f, F, ACCESS
00038C 5A30 SUBWFB 0x30, F, ACCESS
00038E 0E01 MOVLW 0x1
000390 5A31 SUBWFB 0x31, F, ACCESS
000392 0E00 MOVLW 0
000394 5A32 SUBWFB 0x32, F, ACCESS
106: set_timer0(0);
000396 6AD7 CLRF 0xfd7, ACCESS
000398 6AD6 CLRF 0xfd6, ACCESS
107: }
108: else
00039A D011 BRA 0x3be
109: {
110: set_timer0(65535-(int16)TimerCyL);
00039C 0EFF MOVLW 0xff
00039E 80D8 BSF 0xfd8, 0, ACCESS
0003A0 542F SUBFWB 0x2f, W, ACCESS
0003A2 6E34 MOVWF 0x34, ACCESS
0003A4 0EFF MOVLW 0xff
0003A6 5430 SUBFWB 0x30, W, ACCESS
0003A8 6E35 MOVWF 0x35, ACCESS
0003AA C035 MOVFF 0x35, 0xfd7
0003AE C034 MOVFF 0x34, 0xfd6
111: TimerCyL=0;
0003B2 6A32 CLRF 0x32, ACCESS
0003B4 6A31 CLRF 0x31, ACCESS
0003B6 6A30 CLRF 0x30, ACCESS
0003B8 6A2F CLRF 0x2f, ACCESS
112:
113: ChangePulse=1;
0003BA 821C BSF 0x1c, 0x1, ACCESS
114:
115: ChangeStatus=1;
0003BC 841C BSF 0x1c, 0x2, ACCESS
116:
117: }//if(TimerCyL>=65536)
118:
119: }//if(TimerCyH>0)
120: }
121: else
0003BE D003 BRA 0x3c6
122: {
123: HighPulse=0;
0003C0 901C BCF 0x1c, 0, ACCESS
124: output_low(PIN_C5);
0003C2 9A94 BCF 0xf94, 0x5, ACCESS
0003C4 9A8B BCF 0xf8b, 0x5, ACCESS
125: }//if(FinalAFM!=0)
126:
127:
128:
129: FSR0L=save_fsr0l;
0003C6 6AEA CLRF 0xfea, ACCESS
0003C8 C017 MOVFF 0x17, 0xfe9
130: FSR0H=save_fsr0h;
0003CC C018 MOVFF 0x18, 0xfea
131:
132: WREG=save_wreg;
0003D0 C019 MOVFF 0x19, 0xfe8
133: BSR=save_bsr;
0003D4 C01A MOVFF 0x1a, 0xfe0
134: STATUS=save_status;
0003D8 C01B MOVFF 0x1b, 0xfd8
135:
136: /*
137: #asm
138: retfie 1
139: #endasm
140: */
141:
142: }//timer0_isr
143:
0003DC 94F2 BCF 0xff2, 0x2, ACCESS
0003DE EF36 GOTO 0x6c
144: #int_ccp2
145: void ccp2_isr()
146: {
147:
148: TimerCycle = make32(counttimer3,get_timer3());
000496 50B2 MOVF 0xfb2, W, ACCESS
000498 CFB3 MOVFF 0xfb3, 0x3
00049C 6E42 MOVWF 0x42, ACCESS
00049E C003 MOVFF 0x3, 0x43
0004A2 C021 MOVFF 0x21, 0x29
0004A6 C022 MOVFF 0x22, 0x2a
0004AA C042 MOVFF 0x42, 0x27
0004AE C043 MOVFF 0x43, 0x28
149:
150: set_timer3(0);
0004B2 6AB3 CLRF 0xfb3, ACCESS
0004B4 6AB2 CLRF 0xfb2, ACCESS
151:
152: TimerCycle = (int32)((float)TimerCycle/4.0);
0004B6 C02A MOVFF 0x2a, 0x45
0004BA C029 MOVFF 0x29, 0x44
0004BE C028 MOVFF 0x28, 0x43
0004C2 C027 MOVFF 0x27, 0x42
0004C6 D78D BRA 0x3e2
0004C8 C000 MOVFF 0, 0x42
0004CC C001 MOVFF 0x1, 0x43
0004D0 C002 MOVFF 0x2, 0x44
0004D4 C003 MOVFF 0x3, 0x45
0004D8 C003 MOVFF 0x3, 0x49
0004DC C002 MOVFF 0x2, 0x48
0004E0 C001 MOVFF 0x1, 0x47
0004E4 C000 MOVFF 0, 0x46
0004E8 6A4D CLRF 0x4d, ACCESS
0004EA 6A4C CLRF 0x4c, ACCESS
0004EC 6A4B CLRF 0x4b, ACCESS
0004EE 0E81 MOVLW 0x81
0004F0 6E4A MOVWF 0x4a, ACCESS
0004F2 DDFA RCALL 0xe8
0004F4 C003 MOVFF 0x3, 0x49
0004F8 C002 MOVFF 0x2, 0x48
0004FC C001 MOVFF 0x1, 0x47
000500 C000 MOVFF 0, 0x46
000504 DEA0 RCALL 0x246
000506 C003 MOVFF 0x3, 0x2a
00050A C002 MOVFF 0x2, 0x29
00050E C001 MOVFF 0x1, 0x28
000512 C000 MOVFF 0, 0x27
153:
154: AFMFreq = (int16)(10000000/TimerCycle); //for 40MHz
000516 6A45 CLRF 0x45, ACCESS
000518 0E98 MOVLW 0x98
00051A 6E44 MOVWF 0x44, ACCESS
00051C 0E96 MOVLW 0x96
00051E 6E43 MOVWF 0x43, ACCESS
000520 0E80 MOVLW 0x80
000522 6E42 MOVWF 0x42, ACCESS
000524 C02A MOVFF 0x2a, 0x49
000528 C029 MOVFF 0x29, 0x48
00052C C028 MOVFF 0x28, 0x47
000530 C027 MOVFF 0x27, 0x46
000534 D771 BRA 0x418
000536 C001 MOVFF 0x1, 0x24
00053A C000 MOVFF 0, 0x23
155:
156: counttimer3=0;
00053E 6A22 CLRF 0x22, ACCESS
000540 6A21 CLRF 0x21, ACCESS
157:
158: }//#int_ccp2
159:
000542 90A1 BCF 0xfa1, 0, ACCESS
000544 EF36 GOTO 0x6c
160: #INT_TIMER3
161: void timer3_isr() {
162:
163: counttimer3++;
000548 2A21 INCF 0x21, F, ACCESS
00054A B4D8 BTFSC 0xfd8, 0x2, ACCESS
00054C 2A22 INCF 0x22, F, ACCESS
164: }
165:
00054E 92A1 BCF 0xfa1, 0x1, ACCESS
000550 EF36 GOTO 0x6c
166: void main() {
167:
000580 6AF8 CLRF 0xff8, ACCESS
000582 9ED0 BCF 0xfd0, 0x7, ACCESS
000584 8E0D BSF 0xd, 0x7, ACCESS
000586 6AEA CLRF 0xfea, ACCESS
000588 6AE9 CLRF 0xfe9, ACCESS
00058A 50C1 MOVF 0xfc1, W, ACCESS
00058C 0BC0 ANDLW 0xc0
00058E 090F IORLW 0xf
000590 6EC1 MOVWF 0xfc1, ACCESS
000592 0E07 MOVLW 0x7
000594 6EB4 MOVWF 0xfb4, ACCESS
168: #PRIORITY RTCC,CCP2,TIMER3
169:
170:
171: setup_timer_0(RTCC_INTERNAL);
000596 0E80 MOVLW 0x80
000598 6ED5 MOVWF 0xfd5, ACCESS
172: set_timer0(0);
00059A 6AD7 CLRF 0xfd7, ACCESS
00059C 6AD6 CLRF 0xfd6, ACCESS
173:
174: setup_ccp2(CCP_CAPTURE_DIV_4);
00059E 0EB7 MOVLW 0xb7
0005A0 16B1 ANDWF 0xfb1, F, ACCESS
0005A2 8693 BSF 0xf93, 0x3, ACCESS
0005A4 6ABA CLRF 0xfba, ACCESS
0005A6 0E06 MOVLW 0x6
0005A8 6EBA MOVWF 0xfba, ACCESS
0005AA 6AB6 CLRF 0xfb6, ACCESS
0005AC 6AB7 CLRF 0xfb7, ACCESS
175:
176: setup_timer_3(T3_INTERNAL); // Start timer 1
0005AE 50B1 MOVF 0xfb1, W, ACCESS
0005B0 0B48 ANDLW 0x48
0005B2 0985 IORLW 0x85
0005B4 6EB1 MOVWF 0xfb1, ACCESS
177: set_timer3(0);
0005B6 6AB3 CLRF 0xfb3, ACCESS
0005B8 6AB2 CLRF 0xfb2, ACCESS
178: enable_interrupts(INT_TIMER3);
0005BA 82A0 BSF 0xfa0, 0x1, ACCESS
179: enable_interrupts(INT_CCP2); // Setup interrupt on rising edge
0005BC 80A0 BSF 0xfa0, 0, ACCESS
180: enable_interrupts(INT_RTCC);
0005BE 8AF2 BSF 0xff2, 0x5, ACCESS
181: enable_interrupts(GLOBAL);
0005C0 0EC0 MOVLW 0xc0
0005C2 12F2 IORWF 0xff2, F, ACCESS
182:
183: set_tris_c(0x87); //C3-C6 output
0005C4 0E87 MOVLW 0x87
0005C6 6E94 MOVWF 0xf94, ACCESS
184:
185: delay_ms(100);
0005C8 0E64 MOVLW 0x64
0005CA 6E33 MOVWF 0x33, ACCESS
0005CC D7C3 BRA 0x554
186:
187:
188: HighPulse=0;
0005CE 901C BCF 0x1c, 0, ACCESS
189: ChangePulse=1;
0005D0 821C BSF 0x1c, 0x1, ACCESS
190: ChangeStatus=1;
0005D2 841C BSF 0x1c, 0x2, ACCESS
191:
192: while(TRUE) {
193:
194: FinalAFM = AFMFreq;
0005D4 C024 MOVFF 0x24, 0x26
0005D8 C023 MOVFF 0x23, 0x25
195:
196: }//while(TRUE)
0005DC D7FB BRA 0x5d4
|
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Dec 23, 2004 6:17 pm |
|
|
Quote: | Please tell me exactly which registers are used and How can we save and restore it? |
You know, I have some mixed feelings here: I want to help you, but basically you are asking me to do your work...
I see a forum like this is as away to help you to fix problems and to do that in such a manner that you will learn from it and won't ask the same question again.....
Try reading my responses more carefully, for example:
Quote: | I tried to save and restore the registers 0 to 3 like this
Quote:
unsigned char R0;
#locate R0 = 0x1
|
As was already pointed out in my previous post:
Code: | save_scratch3 = *3; // Save working register 3 |
and Quote: | I have also tried to save and restore WREG,BSR and STATUS registers but I think it does not solve the original problem. | You don't have to save these registers, which was also answered in the same post Code: | // The PIC18Fxxx series provide a Fast Register Stack for automatic
// storage of the Status, Wreg and BSR registers during interrupts so we
// don't have to save those registers here manually.
|
I guess you are using the FAST interrupt because of time critical code, but just look at how much code your interrupt routine is generating! This interrupt will never be fast.... As a general rule, try to avoid int32 when possible and try even much, much, harder to avoid float..
For example this line Code: | 52: TimerCyH = (int32)(2500000.0/(float)FinalAFM); |
This requires a staggering 272 instructions to execute !!! But with FinalAFM being an int16 and assigning the result to an int32 there is no advantage of using floats here.
Currently your code is way too large for me to examine in my spare time, I'm doing this now way after midnight when I should have gone to bed for a long time.
Try to optimize your code by getting rid of the int32 and floats. You might even be able to optimize your code so much that you don't need fast interupts anymore. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Dec 24, 2004 4:05 am |
|
|
It looks like you are building your own pulse-width modulator (PWM). What is the reason that you can't use the inbuilt hardware PWM circuit?
You can improve speed a lot by changing the line Code: | TimerCyH = (int32)(2500000.0/(float)FinalAFM); | to Code: | TimerCyH = (int32)(2500000/FinalAFM); |
and the lines Code: | TimerCycle = (int32)((float)TimerCycle/4.0);
AFMFreq = (int16)(10000000/TimerCycle); //for 40MHz | to: Code: | AFMFreq = (int16)(40000000/TimerCycle); //for 40MHz |
This will reduce the code size of your interrupt handlers from 1800 to about 900 bytes, still huge but a big improvement anyway.
From your code I guess you are running at 40MHz? If yes, then fix the following line: Code: | #use delay(clock=4000000)
| A zero is missing...
When configuring the timers specify the exact configuration you want, don't ommit some parameters as the default values might be different from what you expect: Code: | setup_timer_0(RTCC_INTERNAL); | is equal to: Code: | setup_timer_0(RTCC_INTERNAL | RTCC_DIV_2); | ... and I don't think you intended to divide by 2...
This might also be an explanation for your remark: Code: | // 2500000:Devide by 2 again devide by 2(Don't know why)
|
Edited: In my suggestion for 'and change lines ... to ...' I forgot to add the 'to ...' part. Now added this missing part.
Last edited by ckielstra on Fri Dec 31, 2004 4:35 am; edited 1 time in total |
|
|
Prashant Patel
Joined: 19 Jul 2004 Posts: 33
|
|
Posted: Sun Dec 26, 2004 12:15 am |
|
|
Dear ckielstra,
You asked....
Quote: |
what is the reason, you can't use the inbuilt hardware PWM circuit?
|
I want to generate frequency from 1Hz to 2KHz(In future may be 3KHz).
Which is, I think not possible with inbuilt PWM.
I don't mean to ask to do my work. It is because, I don't know assembly.
And I have few months of experience in Embedded C and Microprocessor.
But step by step I am getting my way with the help of you guys.
Any way, wright now I have christmus holiday and can try your indicated
points on 29th Dec. But those are really important points.
Thanks........ |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Dec 31, 2004 4:47 am |
|
|
Quote: | I want to generate frequency from 1Hz to 2KHz(In future may be 3KHz). Which is, I think not possible with inbuilt PWM. |
Running at 40MHz you are right, then the minimum frequency achievable is 2.44kHz. But do you really need to run at 40MHz? Let's just assume you bring down the clock frequency to 16kHz, then the hardware PWM circuits can be used! And as a positive side effect your power consumption wil drop to almost nothing and no more EMC problems. You might even consider using a much less powerfull and therefor cheaper processor... |
|
|
|
|
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
|