Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Anders Blomdell
processer
Commits
b2bcd0e0
Commit
b2bcd0e0
authored
May 05, 2015
by
Anders Blomdell
Browse files
Minor changes to make project compile with new version of
avr toolchain.
parent
e78ba71a
Changes
9
Hide whitespace changes
Inline
Side-by-side
linear_pendulum_2009/avr/.gitignore
0 → 100644
View file @
b2bcd0e0
compiled
\ No newline at end of file
linear_pendulum_2009/avr/Makefile
View file @
b2bcd0e0
PROJECT
=
current_control
CHIP
=
atmega16
ARCH
=
avr
AVRSOURCE
=
AVRAUTO
=
compiled/
$(ARCH)
/
AVRARCH
=
compiled/
$(ARCH)
/
LIB_TARGET
=
$(AVRARCH)
lib
$(TARGET)
.a
CC
=
$(ARCH)
-gcc
CXX
=
$(ARCH)
-gcc
CCFLAGS
=
-mmcu
=
$(CHIP)
-O5
-I
.
-I
$(AVRAUTO)
AS
=
$(ARCH)
-as
ASFLAGS
=
-mmcu
=
$(CHIP)
AR
=
$(ARCH)
-ar
LD
=
$(ARCH)
-ld
OBJDUMP
=
$(ARCH)
-objdump
LDFLAGS
=
-T
$(CHIP)
.link
all
:
$(AVRARCH)$(PROJECT)
$(LIB_TARGET)(%.o)
:
$(AVRSOURCE)%.c Makefile
$(CC)
$(CCFLAGS)
-c
-o
$(AVRARCH)
$
(
%
)
-I
$(AVRSOURCE)
-I
$(AVRAUTO)
$
(
<
)
$(AR)
r
$
(
@
)
$(AVRARCH)
$
(
%
)
rm
$(AVRARCH)
$
(
%
)
$(LIB_TARGET)(%.o)
:
$(AVRSOURCE)%.cc Makefile
$(CXX)
$(CCFLAGS)
-c
-o
$(AVRARCH)
$
(
%
)
-I
$(AVRSOURCE)
-I
$(AVRAUTO)
$
(
<
)
$(AR)
r
$
(
@
)
$(AVRARCH)
$
(
%
)
rm
$(AVRARCH)
$
(
%
)
$(LIB_TARGET)(%.o)
:
$(AVRSOURCE)%.s Makefile
$(AS)
$(ASFLAGS)
-o
$(AVRARCH)
$
(
%
)
$(AVRSOURCE)
$
(
*
)
.s
$(AR)
r
$
(
@
)
$(AVRARCH)
$
(
%
)
rm
$(AVRARCH)
$
(
%
)
$(AVRARCH)%.o
:
$(AVRSOURCE)%.s Makefile
$(AS)
$(ASFLAGS)
-o
$@
$(AVRSOURCE)
$
(
*
)
.s
$(AVRARCH)%.o
:
$(AVRSOURCE)%.c Makefile
$(CC)
$(CCFLAGS)
-c
-o
$@
-I
.
-I
$(AVRAUTO)
$<
$(AVRARCH)%
:
$(AVRARCH)%.o Makefile
$(CC)
$(CCFLAGS)
-o
$@
$<
-lm
$(AVRARCH)%.sr
:
all $(AVRARCH)%
avr-objcopy
-O
srec
$(AVRARCH)
/
$
(
*
)
$@
%.sr
:
$(AVRARCH)%.sr
@
/bin/true
%.load
:
compiled/avr/%.sr
# /work/andersb/atmel/uisp/uisp-0.2b/src/uisp \
# -dno-poll -dstk200 --erase --upload if=$(AVRARCH)/$(*).sr
uisp
\
-dprog
=
stk200
\
--erase
\
--upload
if
=
compiled/avr/
$*
.sr
%.load.stk500
:
compiled/avr/%.sr
uisp
\
-dprog
=
stk500
\
--erase
\
--upload
if
=
compiled/avr/
$*
.sr
%.dump
:
all $(AVRARCH)/%
$(OBJDUMP)
-D
$(AVRARCH)
/
$
(
*
)
$(AVRARCH)fuse.sr
:
fuse.s
avr-gcc
-o
$(AVRARCH)
fuse.o
-c
fuse.s
avr-objcopy
-O
srec
$(AVRARCH)
fuse.o
$(AVRARCH)
fuse.sr
fuse.load
:
$(AVRARCH)fuse.sr
uisp
\
-dprog
=
stk200
\
--erase
\
--segment
=
fuse
\
--upload
if
=
compiled/avr/fuse.sr
load.stk500
:
$(PROJECT).load.stk500
\ No newline at end of file
TARGETS
=
current_control vel_control
current_control.ARCH
=
avr
current_control.CHIP
=
atmega16
# 14.7456 MHz crystal, brown out
current_control.FUSE
=
--wr_fuse_l
=
0x1f
--wr_fuse_h
=
0xd9
--wr_fuse_e
=
0xff
current_control.C
=
current_control
vel_control.ARCH
=
avr
vel_control.CHIP
=
atmega16
# 14.7456 MHz crystal, brown out
vel_control.FUSE
=
--wr_fuse_l
=
0x1f
--wr_fuse_h
=
0xd9
--wr_fuse_e
=
0xff
vel_control.C
=
vel_control pccom
vel_control.H
=
pccom serialio_core
include
../../common/avr/Makefile.common
linear_pendulum_2009/avr/compileUploadCurrentControl.sh
deleted
100755 → 0
View file @
e78ba71a
avr-gcc
-mmcu
=
atmega16
-g
-Wall
-o
current_control current_control.c
avr-objcopy
-Osrec
current_control current_control.sr
uisp
-dprog
=
stk200
--erase
--upload
if
=
current_control.sr
\ No newline at end of file
linear_pendulum_2009/avr/compileUploadVelControl.sh
deleted
100755 → 0
View file @
e78ba71a
avr-gcc
-mmcu
=
atmega16
-O
-g
-Wall
-o
vel_control.o vel_control.c pccom.c
avr-objcopy
-Osrec
vel_control.o vel_control.sr
uisp
-dprog
=
stk200
--erase
--upload
if
=
vel_control.sr
\ No newline at end of file
linear_pendulum_2009/avr/current_control.c
View file @
b2bcd0e0
...
...
@@ -6,11 +6,11 @@
***************************************************************
*/
#include <
avr
/twi.h>
#include <
util
/twi.h>
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <compat/deprecated.h>
// control variables
...
...
@@ -80,10 +80,10 @@ static inline void sendData() {
/* Timer 2 compare match interupt, 28.8 kHz, syncronized with pwm-period */
SIGNAL
(
SIG_OUTPUT_COMPARE2
)
{
SIGNAL
(
TIMER2_COMP_vect
)
{
// Start AD conversion
ADCSRA
|=
BV
(
ADSC
);
ADCSRA
|=
_
BV
(
ADSC
);
// Read previous AD-conversion result
low
=
inp
(
ADCL
);
...
...
@@ -129,7 +129,7 @@ SIGNAL(SIG_OUTPUT_COMPARE2) {
// TWI-communication, recieve reference from velocity controller
if
((
BV
(
TWINT
)
&
inp
(
TWCR
)))
{
if
((
_
BV
(
TWINT
)
&
inp
(
TWCR
)))
{
status
=
(
inp
(
TWSR
)
&
0xf8
);
// status 0x80 means data recieved
if
(
status
==
0x80
)
{
...
...
@@ -138,7 +138,7 @@ SIGNAL(SIG_OUTPUT_COMPARE2) {
}
else
{
}
outp
(
BV
(
TWINT
)
|
BV
(
TWEN
)
|
BV
(
TWEA
),
TWCR
);
outp
(
_
BV
(
TWINT
)
|
_
BV
(
TWEN
)
|
_
BV
(
TWEA
),
TWCR
);
}
// For logging purposes
...
...
@@ -176,8 +176,8 @@ int main()
/* Timer section */
// Timer 1, fast PWM no prescaling (non-inverting mode (start high, switch to low))
outp
(
BV
(
COM1B1
)
|
BV
(
WGM11
)
|
BV
(
WGM10
),
TCCR1A
);
outp
(
BV
(
CS10
)
|
BV
(
WGM13
)
|
BV
(
WGM12
),
TCCR1B
);
outp
(
_
BV
(
COM1B1
)
|
_
BV
(
WGM11
)
|
_
BV
(
WGM10
),
TCCR1A
);
outp
(
_
BV
(
CS10
)
|
_
BV
(
WGM13
)
|
_
BV
(
WGM12
),
TCCR1B
);
// Reset Timer1 and set TOP-value to 128 (means 7-bit pwm-signal-> 115.2 kHz)
outp
(
0x00
,
OCR1AH
);
...
...
@@ -190,13 +190,13 @@ int main()
/* Timer 2, 4 times pwm-period, for control sampling, prescaler 8, 28.8 kHz */
outp
(
BV
(
WGM21
)
|
BV
(
CS21
),
TCCR2
);
outp
(
_
BV
(
WGM21
)
|
_
BV
(
CS21
),
TCCR2
);
outp
(
0x3f
,
OCR2
);
/* Reset timer 2 */
outp
(
0
,
TCNT2
);
// Enable timer2 compare match interrupts
outp
(
BV
(
OCIE2
),
TIMSK
);
outp
(
_
BV
(
OCIE2
),
TIMSK
);
//Serial communication
outp
(
0x00
,
UCSRA
);
// USART:
...
...
@@ -206,16 +206,16 @@ int main()
outp
(
7
,
UBRRL
);
// USART: 115200 @ 14.7456MHz
/* AREF (AREF is 5V) pin external capacitor, MUX0 for current measurement */
outp
(
BV
(
REFS0
)
|
BV
(
MUX0
),
ADMUX
);
outp
(
_
BV
(
REFS0
)
|
_
BV
(
MUX0
),
ADMUX
);
// Enable ADC, start first conversion, prescaler 32, not free running mode
outp
(
BV
(
ADEN
)
|
BV
(
ADSC
)
|
BV
(
ADPS2
)
|
BV
(
ADPS0
),
ADCSRA
);
outp
(
_
BV
(
ADEN
)
|
_
BV
(
ADSC
)
|
_
BV
(
ADPS2
)
|
_
BV
(
ADPS0
),
ADCSRA
);
// Initialize TWI
outp
(
0x02
,
TWBR
);
// set SCL-frequency CPU-freq/(16+2*2)
outp
(
0x02
,
TWAR
);
// slave address
outp
(
BV
(
TWEA
)
|
BV
(
TWEN
),
TWCR
);
// enable TWI, enable ACK
outp
(
_
BV
(
TWEA
)
|
_
BV
(
TWEN
),
TWCR
);
// enable TWI, enable ACK
//Enable interrupts
sei
();
...
...
linear_pendulum_2009/avr/pccom.c
View file @
b2bcd0e0
...
...
@@ -69,7 +69,10 @@ void pccom_receiveByte(char ch)
case
serialio_setchannel
:
{
switch
(
serialio_channel
)
{
case
0
:
{
setRef
(
serialio_value
-
(
1L
<<
12
));
setVelRef
(
serialio_value
-
(
1L
<<
12
));
}
break
;
case
1
:
{
setAccRef
(
serialio_value
-
(
1L
<<
15
));
}
break
;
}
}
break
;
...
...
@@ -107,6 +110,10 @@ static uint8_t sendConfigPacket(uint8_t position)
case
13
:
CONF_ANALOG_OUT
(
0
,
CONF_MIN
(
CONF_NEGATIVE_VOLT
(
1
)));
break
;
case
14
:
CONF_ANALOG_OUT
(
0
,
CONF_MAX
(
CONF_POSITIVE_VOLT
(
1
)));
break
;
case
15
:
CONF_ANALOG_OUT
(
1
,
CONF_RESOLUTION
(
16
));
break
;
// Reference to acc-ctrl
case
16
:
CONF_ANALOG_OUT
(
1
,
CONF_MIN
(
CONF_NEGATIVE_VOLT
(
1
)));
break
;
case
17
:
CONF_ANALOG_OUT
(
1
,
CONF_MAX
(
CONF_POSITIVE_VOLT
(
1
)));
break
;
default:
CONF_END
();
return
0
;
}
...
...
linear_pendulum_2009/avr/serialio_core.h
View file @
b2bcd0e0
...
...
@@ -137,6 +137,7 @@ static void serialio_putchannel(unsigned char channel, unsigned long value);
static
volatile
unsigned
long
serialio_value
;
static
volatile
unsigned
char
serialio_channel
,
serialio_length
;
__attribute__
((
unused
))
static
void
serialio_putbit
(
unsigned
char
channel
,
unsigned
char
value
)
{
if
(
value
)
{
...
...
@@ -144,7 +145,7 @@ static void serialio_putbit(unsigned char channel, unsigned char value)
}
else
{
serialio_putchar
(
0x00
|
(
channel
&
0x1f
));
}
}
}
static
void
serialio_putchannel
(
unsigned
char
channel
,
unsigned
long
value
)
{
...
...
linear_pendulum_2009/avr/vel_control.c
View file @
b2bcd0e0
...
...
@@ -6,20 +6,21 @@
***************************************************************
*/
#include <
avr
/twi.h>
#include <
util
/twi.h>
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <compat/deprecated.h>
#include "pccom.h"
#include "vel_control.h"
// reference variables
volatile
int32_t
ref
=
0
;
// 11 frac bits
volatile
int32_t
ref
=
0
;
// 11 frac bits
(variable in mm/s, max 2^12)
volatile
int32_t
refCtrl
=
0
;
// ref used in ctrl-loop (=ref sent from simulink)
volatile
int32_t
aRef
=
0
;
// 14 frac bits (variable in mm/s, max 2^15)
volatile
uint16_t
nbrSamples
=
0
;
// nbr of samples between ctrl-ref updates
// velocity control variables
volatile
int32_t
u
=
0
;
// 11 frac bits
...
...
@@ -93,9 +94,16 @@ int32_t getCurrentRef() {
}
/* Set new reference value */
void
setRef
(
int32_t
newRef
)
{
ref
=
newRef
;
/* Set new acceleration reference value */
void
setAccRef
(
int32_t
newAccRef
)
{
aRef
=
newAccRef
;
nbrSamples
=
0
;
}
/* Set new velocity reference value */
void
setVelRef
(
int32_t
newVelRef
)
{
ref
=
newVelRef
;
}
/* Routine used to initialize the positional encoders */
...
...
@@ -106,7 +114,7 @@ void initPos()
}
/* Timer 2, Encoder counter, 73 kHz updates position variable */
SIGNAL
(
SIG_OUTPUT_COMPARE2
)
{
SIGNAL
(
TIMER2_COMP_vect
)
{
// Update position from encoder
newX
=
ENCODERX
;
...
...
@@ -138,9 +146,9 @@ SIGNAL(SIG_OUTPUT_COMPARE2) {
/* Timer 0, serial communication with simulink */
SIGNAL
(
SIG_OUTPUT_COMPARE0
)
{
SIGNAL
(
TIMER0_COMP_vect
)
{
TIMSK
&=
~
(
BV
(
OCIE0
)
|
BV
(
OCIE1A
));
// Disable communication and ctrl-interrupts
TIMSK
&=
~
(
_
BV
(
OCIE0
)
|
_
BV
(
OCIE1A
));
// Disable communication and ctrl-interrupts
sei
();
// enable interrupts from encoder-counter
...
...
@@ -163,14 +171,14 @@ SIGNAL(SIG_OUTPUT_COMPARE0) {
TIFR
=
(
1
<<
OCF0
);
// skip pending interrupts from serial comm, (but not from ctrl)
TIMSK
|=
(
BV
(
OCIE0
)
|
BV
(
OCIE1A
));
// reenable communication and ctrl-interrupts
TIMSK
|=
(
_
BV
(
OCIE0
)
|
_
BV
(
OCIE1A
));
// reenable communication and ctrl-interrupts
}
/* Timer 0, control loop , 1 kHz */
SIGNAL
(
SIG_OUTPUT
_COMPA
RE1A
)
{
SIGNAL
(
TIMER1
_COMPA
_vect
)
{
posCtrl
=
pos
;
// store pos to use in this loop
...
...
@@ -183,7 +191,11 @@ SIGNAL(SIG_OUTPUT_COMPARE1A) {
// store velEst and ref to be sent/used here
cli
();
velEstSend
=
velEst
;
refCtrl
=
ref
;
nbrSamples
++
;
refCtrl
=
ref
+
((
aRef
*
nbrSamples
)
>>
10
);
//shift nbrSamples 10 steps (= nbrSamples*h)
if
(
nbrSamples
>
500
)
{
refCtrl
=
0
;
// for safety reasons if doesn't send anything in 0.5 s
}
// ref = ref*(1-brake); // emergency stop
sei
();
...
...
@@ -230,21 +242,21 @@ SIGNAL(SIG_OUTPUT_COMPARE1A) {
// TWI-communication to set current reference on the other atmel
// send start command
outp
(
BV
(
TWINT
)
|
BV
(
TWEN
)
|
BV
(
TWSTA
),
TWCR
);
while
(
!
(
TWCR
&
BV
(
TWINT
)))
{}
outp
(
_
BV
(
TWINT
)
|
_
BV
(
TWEN
)
|
_
BV
(
TWSTA
),
TWCR
);
while
(
!
(
TWCR
&
_
BV
(
TWINT
)))
{}
// Contact slave
outp
(
0x02
,
TWDR
);
// slave is 0x02 (sla+w)
outp
(
BV
(
TWINT
)
|
BV
(
TWEN
),
TWCR
);
while
(
!
(
TWCR
&
BV
(
TWINT
)))
{}
outp
(
_
BV
(
TWINT
)
|
_
BV
(
TWEN
),
TWCR
);
while
(
!
(
TWCR
&
_
BV
(
TWINT
)))
{}
// Send reference byte to slave
outp
((
int8_t
)
u
,
TWDR
);
// send 8 bits reference
outp
(
BV
(
TWINT
)
|
BV
(
TWEN
),
TWCR
);
while
(
!
(
TWCR
&
BV
(
TWINT
)))
{}
outp
(
_
BV
(
TWINT
)
|
_
BV
(
TWEN
),
TWCR
);
while
(
!
(
TWCR
&
_
BV
(
TWINT
)))
{}
// stop transmission
outp
(
BV
(
TWINT
)
|
BV
(
TWEN
)
|
BV
(
TWSTO
),
TWCR
);
outp
(
_
BV
(
TWINT
)
|
_
BV
(
TWEN
)
|
_
BV
(
TWSTO
),
TWCR
);
}
...
...
@@ -261,26 +273,26 @@ int main()
/* Timer section */
// Enable timer0, timer1, timer2 compare match interrupts
outp
(
BV
(
OCIE0
)
|
BV
(
OCIE1A
)
|
BV
(
OCIE2
),
TIMSK
);
outp
(
_
BV
(
OCIE0
)
|
_
BV
(
OCIE1A
)
|
_
BV
(
OCIE2
),
TIMSK
);
/* Timer 2, 73 kHz Prescaler 1, encoder counter for position measurement */
outp
(
BV
(
WGM21
)
|
BV
(
CS20
),
TCCR2
);
outp
(
_
BV
(
WGM21
)
|
_
BV
(
CS20
),
TCCR2
);
outp
(
200
,
OCR2
);
/* Reset timer 2 */
outp
(
0
,
TCNT2
);
/* Timer 1, 1 kHz , prescaler 1, ctrl-loop */
outp
(
BV
(
WGM12
)
|
BV
(
CS10
),
TCCR1B
);
outp
(
0x3
9
,
OCR1AH
);
outp
(
0x
7
f
,
OCR1AL
);
outp
(
_
BV
(
WGM12
)
|
_
BV
(
CS10
),
TCCR1B
);
outp
(
0x3
8
,
OCR1AH
);
outp
(
0x
3
f
,
OCR1AL
);
outp
(
0
,
TCNT1H
);
outp
(
0
,
TCNT1L
);
/* Timer 0, 40 kHz, Prescaler 8, serial communication */
outp
(
BV
(
WGM01
)
|
BV
(
CS01
),
TCCR0
);
outp
(
_
BV
(
WGM01
)
|
_
BV
(
CS01
),
TCCR0
);
//outp(184-1,OCR0); // 10 kHz
outp
(
4
6
-
1
,
OCR0
);
// 40 kHz
outp
(
4
5
-
1
,
OCR0
);
// 40 kHz
/* Reset timer 0 */
outp
(
0
,
TCNT0
);
...
...
@@ -298,15 +310,15 @@ int main()
/* AREF (AREF is 5V) pin external capacitor, ADC3 for pendulum angle */
outp
(
BV
(
REFS0
)
|
BV
(
MUX0
)
|
BV
(
MUX1
),
ADMUX
);
outp
(
_
BV
(
REFS0
)
|
_
BV
(
MUX0
)
|
_
BV
(
MUX1
),
ADMUX
);
// Enable ADC on adc3, start first conversion, prescaler 128, free running mode
outp
(
BV
(
ADEN
)
|
BV
(
ADSC
)
|
BV
(
ADATE
)
|
BV
(
ADPS2
)
|
BV
(
ADPS1
)
|
BV
(
ADPS0
),
ADCSRA
);
outp
(
_
BV
(
ADEN
)
|
_
BV
(
ADSC
)
|
_
BV
(
ADATE
)
|
_
BV
(
ADPS2
)
|
_
BV
(
ADPS1
)
|
_
BV
(
ADPS0
),
ADCSRA
);
// Initialize Master TWI
outp
(
0x10
,
TWBR
);
// set SCL-frequency CPU-freq/(16+2*16)
outp
(
BV
(
TWEN
),
TWCR
);
// enable TWI
outp
(
_
BV
(
TWEN
),
TWCR
);
// enable TWI
// initialize position measurements
initPos
();
...
...
linear_pendulum_2009/avr/vel_control.h
View file @
b2bcd0e0
...
...
@@ -2,7 +2,8 @@
#define __vel_control_h
void
setRef
(
int32_t
newRef
);
void
setVelRef
(
int32_t
newVelRef
);
void
setAccRef
(
int32_t
newAccRef
);
int32_t
getPosition
();
int32_t
getVelocity
();
int16_t
getAngle
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment