Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
atkbldcdriver
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jake Read
atkbldcdriver
Commits
a8e5d8c8
Commit
a8e5d8c8
authored
Jul 12, 2018
by
Jake Read
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
does speed acceleration to slew between open loop speeds
parent
222f289a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
5 deletions
+32
-5
embedded/atkbldcdriver/atkbldcdriver/bldc.c
embedded/atkbldcdriver/atkbldcdriver/bldc.c
+17
-2
embedded/atkbldcdriver/atkbldcdriver/bldc.h
embedded/atkbldcdriver/atkbldcdriver/bldc.h
+4
-0
embedded/atkbldcdriver/atkbldcdriver/main.c
embedded/atkbldcdriver/atkbldcdriver/main.c
+11
-3
No files found.
embedded/atkbldcdriver/atkbldcdriver/bldc.c
View file @
a8e5d8c8
...
...
@@ -12,6 +12,9 @@ void bldc_init(bldc_t *bldc){
bldc
->
comState
=
0
;
bldc
->
comDir
=
1
;
bldc
->
comDuty
=
0
;
bldc
->
targetSpeed
=
0
;
bldc
->
currentSpeed
=
0
;
}
void
bldc_shutdown
(
bldc_t
*
bldc
){
...
...
@@ -23,10 +26,22 @@ void bldc_shutdown(bldc_t *bldc){
void
bldc_setDuty
(
bldc_t
*
bldc
,
uint32_t
duty
){
// blind pwm duty 0-512
(
duty
>
512
)
?
duty
=
512
:
(
0
);
// hard stop at 256 to avoid breaking things
(
duty
>
256
)
?
duty
=
256
:
(
0
);
bldc
->
comDuty
=
(
uint16_t
)
duty
;
}
void
bldc_setTargetSpeed
(
bldc_t
*
bldc
,
int32_t
speed
){
// assert limits
if
(
speed
>
20000
){
speed
=
20000
;
}
else
if
(
speed
<
-
20000
){
speed
=
-
20000
;
}
bldc
->
targetSpeed
=
speed
;
}
void
bldc_setSpeed
(
bldc_t
*
bldc
,
int32_t
speed
){
// speed in eRPM
// assert max
...
...
@@ -53,5 +68,5 @@ void bldc_setSpeed(bldc_t *bldc, int32_t speed){
void
bldc_newSpeed
(
bldc_t
*
bldc
,
int32_t
speed
,
uint32_t
duty
){
bldc_setDuty
(
bldc
,
duty
);
bldc_setSpeed
(
bldc
,
speed
);
bldc_set
Target
Speed
(
bldc
,
speed
);
}
\ No newline at end of file
embedded/atkbldcdriver/atkbldcdriver/bldc.h
View file @
a8e5d8c8
...
...
@@ -16,6 +16,8 @@ typedef struct{
uint8_t
comDir
;
uint16_t
comDuty
;
int32_t
currentSpeed
;
int32_t
targetSpeed
;
uint16_t
comPeriod
;
}
bldc_t
;
...
...
@@ -25,6 +27,8 @@ void bldc_shutdown(bldc_t *bldc);
void
bldc_setDuty
(
bldc_t
*
bldc
,
uint32_t
duty
);
void
bldc_setTargetSpeed
(
bldc_t
*
bldc
,
int32_t
speed
);
void
bldc_setSpeed
(
bldc_t
*
bldc
,
int32_t
speed
);
void
bldc_start
(
bldc_t
*
bldc
,
int32_t
speed
,
uint32_t
duty
);
...
...
embedded/atkbldcdriver/atkbldcdriver/main.c
View file @
a8e5d8c8
...
...
@@ -151,7 +151,7 @@ void tickers_init(void){
// and a reasonable speed for acceleration ticking
uint16_t
perAccelRate
=
24
00
;
uint16_t
perAccelRate
=
8
00
;
uint8_t
perAl
=
(
uint8_t
)
perAccelRate
;
uint8_t
perAh
=
(
uint8_t
)
(
perAccelRate
>>
8
);
...
...
@@ -188,7 +188,7 @@ int main(void)
// initialize the bldc state structure
bldc_init
(
&
bldc
);
// on startup speed and duty
bldc_setSpeed
(
&
bldc
,
1000
);
bldc_set
Target
Speed
(
&
bldc
,
1000
);
bldc_setDuty
(
&
bldc
,
10
);
// startup the driver
drv_init
();
...
...
@@ -241,7 +241,15 @@ ISR(TCD0_OVF_vect){
// acceleration timer
ISR
(
TCD1_OVF_vect
){
//pin_toggle(&tstpin2);
if
(
bldc
.
currentSpeed
!=
bldc
.
targetSpeed
){
if
(
bldc
.
currentSpeed
<
bldc
.
targetSpeed
){
bldc
.
currentSpeed
++
;
bldc_setSpeed
(
&
bldc
,
bldc
.
currentSpeed
);
}
else
{
bldc
.
currentSpeed
--
;
bldc_setSpeed
(
&
bldc
,
bldc
.
currentSpeed
);
}
}
}
ISR
(
USARTE1_RXC_vect
){
...
...
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