Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jake Read
ucbus-stepper
Commits
76447143
Commit
76447143
authored
Oct 13, 2020
by
Jake Read
Browse files
stores one float
parent
b97fda7f
Changes
2
Hide whitespace changes
Inline
Side-by-side
firmware/cl-step-controller/src/drivers/step_cl.cpp
View file @
76447143
...
...
@@ -46,92 +46,28 @@ void Step_CL::init(void){
//lut = flash_lut.read();
}
// das lut / flash stuff,
// s/o to mechaduino code for this
#define PAGE_SIZE 512 // start_flash_write reports this bit value, use datasheet 25.8.3 to reference
const
float
__attribute__
((
__aligned__
(
PAGE_SIZE
)))
lut
[
ENCODER_COUNTS
]
=
{};
uint32_t
start_addr
=
0x00000000
;
float
temp_quad
[
4
];
uint8_t
temp_indice
;
FlashStorage
(
flash_store
,
float
);
void
flash_wait_ready
(
void
){
while
(
NVMCTRL
->
STATUS
.
bit
.
READY
==
0
);
}
// erase block at this addr
void
flash_erase_block
(
uint32_t
*
dst
){
sysError
(
"erasing 0x"
+
String
((
uint32_t
)
dst
,
HEX
));
flash_wait_ready
();
// do 'erase row'
NVMCTRL
->
ADDR
.
reg
=
(
uint32_t
)
dst
;
NVMCTRL
->
CTRLB
.
reg
=
NVMCTRL_CTRLB_CMDEX_KEY
|
NVMCTRL_CTRLB_CMD_EB
;
flash_wait_ready
();
}
// writes blocks of four four bit words: i.e. 4 floats per row, 4 uint32, etc
// dst address, src address...
#define QUAD_WORD (4 * 4)
void
flash_write_words
(
uint32_t
*
dst
,
uint32_t
*
src
,
uint32_t
n_words
){
sysError
(
"writing quad to addr: 0x"
+
String
((
uint32_t
)
dst
,
HEX
));
// set manuel page write
NVMCTRL
->
CTRLA
.
bit
.
WMODE
=
NVMCTRL_CTRLA_WMODE_MAN
;
sysError
(
"pbc"
);
// execute page buffer clear
flash_wait_ready
();
NVMCTRL
->
CTRLB
.
reg
=
NVMCTRL_CTRLB_CMDEX_KEY
|
NVMCTRL_CTRLB_CMD_PBC
;
flash_wait_ready
();
void
flash_write_init
(
void
){
// write em ?
sysError
(
"writing..."
);
while
(
n_words
>
0
){
sysError
(
String
(
n_words
));
// more than 4 words left?
uint32_t
len
=
4
<
n_words
?
4
:
n_words
;
// write one quad word into page buffer (is ... the flash address?)
flash_wait_ready
();
sysError
(
"past wait"
);
for
(
uint32_t
i
=
0
;
i
<
4
;
i
++
){
if
(
i
<
len
){
dst
[
i
]
=
src
[
i
];
}
else
{
//((uint32_t*)dst)[i] = 0xffffffff; // tail ends write to solid 1's
}
}
// trigger the write
sysError
(
"write: 0x"
+
String
((
uint32_t
)
dst
,
HEX
));
delay
(
100
);
NVMCTRL
->
ADDR
.
reg
=
(
uint32_t
)
dst
;
NVMCTRL
->
CTRLB
.
reg
=
NVMCTRL_CTRLB_CMDEX_KEY
|
NVMCTRL_CTRLB_CMD_WQW
;
// advance thru quad words
dst
+=
len
;
src
+=
len
;
n_words
-=
len
;
}
sysError
(
"quad complete"
);
delay
(
10
);
}
// ok, I think I can try this: I keep a row of vals, 4 of 'em, then on wrap, I write
// using erase / then write, using the lut as the start,
// I'll try to do it once, to start, then read it out...
void
flash_write_init
(
void
){
temp_indice
=
0
;
void
flash_write_value
(
float
val
){
flash_store
.
write
(
val
);
}
void
flash_write_value
(
float
val
){
sysError
(
"flt: "
+
String
(
val
));
temp_quad
[
temp_indice
++
]
=
val
;
if
(
temp_indice
>
3
){
flash_erase_block
(
&
start_addr
);
flash_write_words
(
&
start_addr
,
(
uint32_t
*
)(
&
temp_quad
),
4
);
temp_indice
=
0
;
void
Step_CL
::
print_table
(
void
){
for
(
uint16_t
e
=
0
;
e
<
4
;
e
++
){
float
ra
=
flash_store
.
read
();
sysError
(
"e: "
+
String
(
e
)
+
" ra: "
+
String
(
ra
,
4
));
delay
(
5
);
}
}
// the calib routine
boolean
Step_CL
::
calibrate
(
void
){
flash_write_value
(
100.0
F
);
return
true
;
// (1) first, build a table for 200 full steps w/ encoder averaged values at each step
float
phase_angle
=
0.0
F
;
for
(
uint8_t
i
=
0
;
i
<
200
;
i
++
){
...
...
@@ -285,10 +221,3 @@ boolean Step_CL::calibrate(void){
return
true
;
// went OK
}
void
Step_CL
::
print_table
(
void
){
for
(
uint16_t
e
=
0
;
e
<
4
;
e
++
){
float
ra
=
((
float
*
)
start_addr
)[
e
];
//lut[e];
sysError
(
"e: "
+
String
(
e
)
+
" ra: "
+
String
(
ra
,
4
));
delay
(
5
);
}
}
\ No newline at end of file
log/cl-step-control-log.md
View file @
76447143
...
...
@@ -5,6 +5,7 @@ With 2x A4950s on the DAC, AS5047P on the encoder, etc.
## Do Want
-
magnet alignment print / tool for the glue-in
-
https://www.youtube.com/watch?v=5x73LjZQ21o
## Likely Bugs
...
...
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