Hello all!
After finally getting my first project to run well [timer with interrupt as clock divider to a counting variable and then output of the counted value to port D], I decided to get into something more advanced.
Right now I'm experimenting with ADC and PWM. Trying to read the adc value through channel 3 and using timer 2 to generate PWM on an AtMega8 chip. The OCR2 value is updated in the main program, while the ADC complete interrupt just sets a flag variable for the main program to know it has to update OCR2.
But it doesn't work!
I tried to debug using the AVRSTUDIO simulator. The configuration registers are all loaded as in my code and both the timer and the ADC start. The ADC runs until the end of the first conversion and it seems to enter the ISR, where it sets the flag variable, and then stops at the IRET instruction!
The timer keeps running but execution never goes from IRET to the main code, and in the disassembly window there is no address associated to the IRET, as shown below. [would the address be stored in an SFR somwhere?]
0000003C: 9518 RETI Interrupt return
Any ideas on what is happening? I am using WinAvr to compile my code, with the KamAvr gui. I have no knowledge of AVR assembly [but I have done assembly on other chips], so my interpretation of the code might not be exact!
Here is the assembly code, if you would like the source ask me [trying not to post too long].
+00000013: 2411 CLR R1 Clear Register +00000014: BE1F OUT 0x3F,R1 Out to I/O location +00000015: E5CF LDI R28,0x5F Load immediate +00000016: E0D4 LDI R29,0x04 Load immediate +00000017: BFDE OUT 0x3E,R29 Out to I/O location +00000018: BFCD OUT 0x3D,R28 Out to I/O location +00000019: E010 LDI R17,0x00 Load immediate +0000001A: E6A0 LDI R26,0x60 Load immediate +0000001B: E0B0 LDI R27,0x00 Load immediate +0000001C: EBE0 LDI R30,0xB0 Load immediate +0000001D: E0F0 LDI R31,0x00 Load immediate +0000001E: C002 RJMP PC+0x0003 Relative jump +0000001F: 9005 LPM R0,Z+ Load program memory and postincrement +00000020: 920D ST X+,R0 Store indirect and postincrement +00000021: 36A0 CPI R26,0x60 Compare with immediate +00000022: 07B1 CPC R27,R17 Compare with carry +00000023: F7D9 BRNE PC-0x04 Branch if not equal +00000024: E010 LDI R17,0x00 Load immediate +00000025: E6A0 LDI R26,0x60 Load immediate +00000026: E0B0 LDI R27,0x00 Load immediate +00000027: C001 RJMP PC+0x0002 Relative jump +00000028: 921D ST X+,R1 Store indirect and postincrement +00000029: 36A1 CPI R26,0x61 Compare with immediate +0000002A: 07B1 CPC R27,R17 Compare with carry +0000002B: F7E1 BRNE PC-0x03 Branch if not equal +0000002C: C01C RJMP PC+0x001D Relative jump +0000002D: CFD2 RJMP PC-0x002D Relative jump +0000002E: 921F PUSH R1 Push register on stack +0000002F: 920F PUSH R0 Push register on stack +00000030: B60F IN R0,0x3F In from I/O location +00000031: 920F PUSH R0 Push register on stack +00000032: 2411 CLR R1 Clear Register +00000033: 938F PUSH R24 Push register on stack +00000034: EF8F SER R24 Set Register +00000035: 93800060 STS 0x0060,R24 Store direct to data space +00000037: 918F POP R24 Pop register from stack +00000038: 900F POP R0 Pop register from stack +00000039: BE0F OUT 0x3F,R0 Out to I/O location +0000003A: 900F POP R0 Pop register from stack +0000003B: 901F POP R1 Pop register from stack +0000003C: 9518 RETI Interrupt return +0000003D: BC13 OUT 0x23,R1 Out to I/O location +0000003E: E68A LDI R24,0x6A Load immediate +0000003F: BD85 OUT 0x25,R24 Out to I/O location
Thanks,
nxp