Professional Documents
Culture Documents
interface
(1)
Dimensions: 45 mm 90 mm
Note: 1. The ATmega88 is supported by AVR Studio, version 4.12 or higher. For up-to-date information
on this and other AVR
tool products, please consult our web site. The newest version of AVR
Studio, AVR tools, and user guide can be found in the AVR section of the Atmel web site,
http://www.atmel.com
Figure 4-1. Application Board Top View, and Connector Usage
Motor Out 1
Motor Out 2
PGND
SIO
Vbat
CW
Stop
CCW
Speed
1 2
3 4
5 6
JP1
ISP MK2 Header
MISO
SCK
NRES
MOSI
VCC 5V
GND
5
9102AAUTO08/07
ATA6824 and ATmega88
5. Software Description
All code is implemented in C language. Source code can be compiled using IAR
EWAVR 4.20A
as well as AVR-GCC (WinAVR-20060421 with AVR Studio).
HTML documentation is included in the package. Use the High_temp_brushed_DC.html file in
the root directory to start viewing the documentation.
5.1 Motor Management
Motor stopped
PWM ratio is set to zero
Command switch inputs are monitored to start motor or keep it stopped.
Motor running
ATA6824 DIR pin is set according to command direction. PWM ratio is refreshed
constantly according to speed of the potentiometer ADC input.
Command switch inputs are monitored to stop motor or keep it stopped.
Degraded mode:
ATA6824 detects a short circuit: H-bridge short-circuited and FET is switched off
until next PWM rising edge. This default is reported to software through a diagnostic
feature: an interrupt occurs on DG1 MCU input pin, which internally latches a failure.
Apart from switching on the DG1 LED, no action is taken by the software in response
to this event. In a customer application, this should be managed, eventually by the
interrupt sub-routine, especially in case of a 100% PWM ratio where no rising edge
appears at the ATA6824 PWM input to make a retry. Care should be taken in motor
transient state (e.g. motor start-up). An accelerating curve is preferable from 0% to
100% PWM ratio transition, which may be mistaken for a short-circuit condition.
Without management, in the worst case scenario, the motor will not start as the
outputs are switched off, and short circuit will be shown on DG1 pin.
ATA6824 detects an over-temperature warning: an interrupt occurs on the MCU. This
diagnostic doesnt need to be software latched as it remains high until the
temperature decreases. The application software toggles an LED.
ATA6824 detects an under-voltage, an over-voltage, or a charge pump failure. Then,
an interrupt occurs on DG2 MCU input PIN. This diagnostic is latched by software
and an LED is switched on.
An over-current is detected by the analog comparator. An interrupt is generated. The
output PWM is then disabled until the current decreases bellow the over-current
limit.
5.2 Resources
Table 5-1. Code, Data, and CPU Resources (without Compiler Optimizations)
Compiler/Resources Code Size (Flash) Data Size (Ram) CPU Load
IAR EWAVR 4.20A 1 180 bytes 335 bytes
All routines are
constantly executed in
main loop
AVR-GCC 1724 bytes 15 bytes
6
9102AAUTO08/07
ATA6824 and ATmega88
The following MCU peripherals are used:
Timer 0
PWM generation through output compare 0B (OC0B pin)
ADC channels 0, 6, and 7
Resp. current, battery supply voltage and desired speed (potentiometer) value
acquisitions.
Pin change interrupts
DG1, DG2 and DG3 diagnostic pins interrupts
Optional hall sensors
Analog comparator
Generates over-current interrupts
I/O
LEDs, switch and push-button operations, watchdog trigger, motor direction
command
Additional (not managed by this stand-alone software)
UART for SIO implementation (communication through high-voltage serial interface).
5.3 Caution about ATmega88 Start-up Time (Fuse Configuration)
ATA6824 uses a windowed watchdog, which can reset the ATmega88 using the reset pin.
ATmega88 is configured by default (fuse configuration) with a start-up time of 65 ms after a
power-on reset. With tolerances, this value can increase up to 69 ms.
ATA6824 waits for a watchdog trigger within 68 ms after the reset signal has been released.
Such an additional 65 ms delay is unnecessary and could cause the application not to start.
ATA6824 ensures an adequate VCC through its power-on delay. ATmega88 default fuse config-
uration should be over-written with a smaller start-up time. The start-up time can be set to
4.1 ms or 0 ms. The start-up settings in the fuse configuration can be changed by setting the
SUTx and CKSELx fuse bits. Further details about fuses can be found in ATmega88 datasheet
and in the AVR Studio Help: AVR Tools users guide.
7
9102AAUTO08/07
ATA6824 and ATmega88
Figure 5-1. ATmega88 Fuse Configuration Editing in AVR Studio
8
9102AAUTO08/07
ATA6824 and ATmega88
5.4 Diagrams
Figure 5-2. Flowchart for Analog Comparator (Over-current) ISR
Figure 5-3. Flowchart for Optional Hall Sensors ISR
Figure 5-4. Flowchart for Diagnostic Interrupt Pins
Y N
Over-current ISR
(Analog Comparator ISR)
Current Over Limit?
Latch Over Current
Report Over Current
Disable Output PWM
Clear Over-current Report
Re-enable Output PWM
Pin Change Interrupt 0
(Hall Sensor ISR)
Optional Code Can Be Put in it
Y
Pin Change Interrupt 1
(Diagnostic 1, 2 and 3 ISR
DG1 set? Latch DG1 Failure
DG2 set?
DG3 set?
Clear DG3 Warning
Latch DG2 Failure
Report DG3 Warning
Y
Y
N
N
N
9
9102AAUTO08/07
ATA6824 and ATmega88
Figure 5-5. Main Loop Flowchart
5.5 Modules
void ADC_Init(); (void)
Sets up ADC to acquire desired speed from potentiometer.
void Timer0_start(void)
Configures timer 1 for PWM on Output compare 0 B pin.
void AN_compare_init(void)
Configures Analog comparator to detect over-currents by interrupts.
void Hall_sensors_ISR_init(void)
Sets up pin change interrupts on hall sensors inputs.
void Diag_inputs_ISR_init(void)
Sets up interrupts on Diagnostic pins.
void ADC_task(void)
Schedules ADC acquisitions: desired speed, Vbat, and Motor current. It is called in background
(main loop).
unsigned int adc_get_speed(void)
Returns last acquired desired speed from potentiometer.
unsigned int adc_get_current(void)
Returns last acquired motor current.
unsigned int adc_get_V_bat(void)
Returns last acquired supply voltage measurement.
void manage_time_base(void)
Main Loop
(Background)
ADC Scheduler
Time Base Management
Watchdog Refresh Task
Motor Management
Diagnostic Display on LED
Initialize I/O, ATA6824 WD, ADC, Hall Sensors ISR, Diagnostic ISR, Timer0-PWM
10
9102AAUTO08/07
ATA6824 and ATmega88
Manages a general purpose time base by monitoring Timer0 overflows (used by watchdog
refresh routine, LED toggling).
void refresh_ATA6824_watchdog(void)
Refreshes ATA6824 according to hardware fixed period and software time base. It is called in
background (main loop).
void clear_faults(void)
Clears software latched faults (from diagnostics pins) only when they have disappeared.
TIMER0_SET_OC0B_PWM (val)
This macro changes PWM ratio.
DISABLE_OCB0()
This macro disables PWM output by changing pin multiplexing back to general I/O configuration.
RE_ENABLE_OCB0()
This macro enables PWM output by giving pin control to Output compare 0 B (Timer 0 PWM
output).
11
9102AAUTO08/07
ATA6824 and ATmega88
6. Application Board Full Description
Figure 6-1. BLDC Application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H
e
a
d
e
r S
W
IT
C
H
_
C
C
W
S
W
IT
C
H
_
C
W
V
C
C
5
V
G
N
D
H
a
ll1
_
S
0
R
:
N
e
t
t
ie
P
B
5
(
S
C
K
/
P
C
I
N
T
5
)
A
V
C
C
P
C
0
(
A
D
C
0
/
P
C
I
N
T
8
)
P
C
1
(
A
D
C
1
/
P
C
I
N
T
9
)
P D 2 ( I N T 0 / P C I N T 1 8 )
P D 1 ( T X D / P C I N T 1 7 )
P D 0 ( R X D / P C I N T 1 6 )
P C 6 ( R E S E T / P C I N T 1 4 )
P C 5 ( A D C 5 / S C L / P C I N T 1 3 )
P C 4 ( A D C 4 / S D A / P C I N T 1 2 )
P C 3 ( A D C 3 / P C I N T 1 1 )
P C 2 ( A D C 2 / P C I N T 1 0 )
P
D
3
(
I
N
T
1
/
O
C
2
B
/
P
C
I
N
T
1
9
)
P
D
4
(
T
0
/
X
C
K
/
P
C
I
N
T
2
0
)
P
B
6
(
T
O
S
C
1
/
X
T
A
L
L
1
/
P
C
I
N
T
6
)
P
B
7
(
T
O
S
C
2
/
X
T
A
L
2
/
P
C
I
N
T
7
)P D 5 ( T 1 / O C 0 B / P C I N T 2 1 )
P D 6 ( A I N 0 / O C 0 A / P C I N T 2 2 )
P D 7 ( A I N 1 / P C I N T 2 3 )
P B 0 ( I C P 1 / C L K O / P C I N T 0 )
P B 1 ( O C 1 A / P C I N T 1 )
P B 2 ( O C 1 B / S S / P C I N T 2 )
P B 3 ( M O S I / O C 2 A / P C I N T 3 )
P B 4 ( M I S O / P C I N T 4 )
D
G
2
_
F
a
u
lt
D
G
1
_
F
a
u
lt
B Z X 8 4 - C 5 V 1
B
A
S
1
6
L
1
6
H
Q
2
B
C
8
1
7
-
4
0
L
o
w
D
r
o
p
R
e
v
e
r
s
e
V
o
l
t
a
g
e
P
r
o
t
e
c
t
i
o
n
S
U
D
5
0
N
0
4
0
R
: N
e
t T
ie
H
S
id
e
2
C
m
d
M
o
t_
S
id
e
2
H
S
id
e
1
C
m
d
M
o
t_
S
id
e
1
S I O _ R X D
S I O _ T X D
M o t _ D i r
M o t _ P W M
V B A T S W
S
h
u
n
t
o
f
5
m
-
-
>
G
a
i
n
=
2
5
D
e
f
e
c
t
>
2
0
A
V
S
h
u
n
t
=
1
0
0
m
V
V
A
m
p
l
=
2
.
5
V
S
U
D
5
0
N
0
4
S
U
D
5
0
N
0
4
S
U
D
5
0
N
0
4
S
U
D
5
0
N
0
4
L
S
id
e
2
C
m
d
H
S
id
e
2
C
m
d
M
o
t_
S
id
e
2
C
M
S
Y
e
llo
w
M
o
t_
S
id
e
2
M
o
t_
S
id
e
1
12
9102AAUTO08/07
ATA6824 and ATmega88
Figure 6-2. BLDC Application Board Top View and Component Placement
Figure 6-3. BLDC Application Board Bottom View
9102AAUTO08/07
Headquarters International
Atmel Corporation
2325 Orchard Parkway
San Jose, CA 95131
USA
Tel: 1(408) 441-0311
Fax: 1(408) 487-2600
Atmel Asia
Room 1219
Chinachem Golden Plaza
77 Mody Road Tsimshatsui
East Kowloon
Hong Kong
Tel: (852) 2721-9778
Fax: (852) 2722-1369
Atmel Europe
Le Krebs
8, Rue Jean-Pierre Timbaud
BP 309
78054
Saint-Quentin-en-Yvelines Cedex
France
Tel: (33) 1-30-60-70-00
Fax: (33) 1-30-60-71-11
Atmel Japan
9F, Tonetsu Shinkawa Bldg.
1-24-8 Shinkawa
Chuo-ku, Tokyo 104-0033
Japan
Tel: (81) 3-3523-3551
Fax: (81) 3-3523-7581
Product Contact
Web Site
www.atmel.com
Technical Support
auto_control@atmel.com
Sales Contact
www.atmel.com/contacts
Literature Requests
www.atmel.com/literature
Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any
intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMELS TERMS AND CONDI-
TIONS OF SALE LOCATED ON ATMELS WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY
WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDEN-
TAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF
THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no
representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications
and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided
otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmels products are not intended, authorized, or warranted for use
as components in applications intended to support or sustain life.
2007 Atmel Corporation. All rights reserved. Atmel
, AVR Studio