I'm making pwm motor driver. And I have written interrupt routine using assembler for speed. honestly, I have revised lss file produced by atmel studio. and I have written main source using atmel studio 7. But there is no function combine C++ and assembler in atmel studio. And It does not have function inserting object file in toolchain option. So I compile and link in prompt(Windows 10). But I cannot get a result that I want.
- interrupt source
#include <avr/io.h>
.global __vector_13
.extern INDEX_carrier_nth_section
.extern Mf
.extern TOP
.extern Io
.extern tick_rr
.extern Clock_Per_quarter_Cycle_of_Carrier
.extern PWM_duty_clocks
__vector_13:
push r0
in r0, 0x3f ; 63
push r1
eor r1, r1
......
......
- C++ source
#include <avr/io.h>
#include <avr/interrupt.h>
#include <math.h>
#include <stdlib.h>
#define F_CPU 16000000UL
#define NEWTON_ITER 3
#define U_LIMIT_Mf 601
#define Irm 3.0 // A
#define Vs 310.0 // V
#define Lr 20e-6 // H
#define Cr 1e-9 // F
....
....
ISR(TIMER1_COMPA_vect) //for debug
{
;
}
int main(void)
{
/* Replace with your application code */
full_length_of_power_clock = static_cast<long>(Mf)*Clock_Per_1_Cycle_of_Carrier;
half_length_of_power_clock = full_length_of_power_clock>>1;
quarter_length_of_power_clock = half_length_of_power_clock>>1;
TOP = Clock_Per_1_Cycle_of_Carrier/4;
get_pwm_dutys();
start_PWM();
......
......
and I run gcc
avr-gcc -mmcu=atmega328p -o main.o main.cpp
and I run assembler
avr-as -mmcu=atmega328p -o interrupt.o interrupt.asm
and then
avr-gcc -o pwm.elf main.o interrupt.o
There was no error message.
and I saw output file by
avr-objdump -d pwm.elf
It said
Disassembly of section .text:
00000000 <__ctors_end>:
0: 0c 94 44 00 jmp 0x88 ; 0x88 <__init>
4: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
8: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
c: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
10: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
14: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
18: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
1c: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
20: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
24: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
28: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
2c: 0c 94 6e 00 jmp 0xdc ; 0xdc <__vector_11>
30: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
34: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
38: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
3c: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
40: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
44: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
48: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
4c: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
50: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
54: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
58: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
5c: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
60: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
64: 0c 94 6c 00 jmp 0xd8 ; 0xd8 <__bad_interrupt>
68: 05 a8 ldd r0, Z+53 ; 0x35
6a: 4c cd rjmp .-1384 ; 0xfffffb04 <_ZL8tick_rcb+0xfefff984>
6c: b2 d4 rcall .+2404 ; 0x9d2 <__addsf3x+0x82>
6e: 4e b9 out 0x0e, r20 ; 14
70: 38 36 cpi r19, 0x68 ; 104
only TIMER1_COMPA_vect(__vector_11) exist. There isn't __vector_13.
In order to refer to atmel studio's output, I add --save-temps option in atmel studio. And main.s by atmel is like this.
.file "main.cpp"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
.text
.Ltext0:
.cfi_sections .debug_frame
.section .text.__vector_11,"ax",@progbits
.global __vector_11
.type __vector_11, @function
__vector_11:
.LFB6:
.file 1 ".././main.cpp"
.loc 1 67 0
.cfi_startproc
push r1
I change the code regarding __vector_13.
.text
.section .text.__vector_13,"ax",@progbits
.global __vector_13
__vector_13:
But It doesn't give what I want. Somebody help me.