Code: Select all
HAL_DAC_SetValue(&DAC_Handle, self->dac_channel, DAC_ALIGN_12B_R, mp_obj_get_int(val));
Code: Select all
# place jumper between X6 and X19
a = pyb.ADC(pyb.Pin.board.X19)
d = pyb.DAC(2)
d.write(0)
assert(a.read() < 10)
d.write(4095)
assert(a.read() > 4085)
d.write(4096)
assert(a.read() < 10)
Code: Select all
[ul5255@speedy-gonzales micropython]$ pwd
/home/ul5255/sandbox/micropython
[ul5255@speedy-gonzales micropython]$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: stmhal/dac.c
no changes added to commit (use "git add" and/or "git commit -a")
[ul5255@speedy-gonzales micropython]$ git diff
diff --git a/stmhal/dac.c b/stmhal/dac.c
index e8ed752..545078f 100644
--- a/stmhal/dac.c
+++ b/stmhal/dac.c
@@ -223,7 +223,7 @@ STATIC mp_obj_t pyb_dac_triangle(mp_obj_t self_in, mp_obj_t freq) {
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_triangle_obj, pyb_dac_triangle);
/// \method write(value)
-/// Direct access to the DAC output (8 bit only at the moment).
+/// Direct access to the DAC output. Resolution is 12 bit.
STATIC mp_obj_t pyb_dac_write(mp_obj_t self_in, mp_obj_t val) {
pyb_dac_obj_t *self = self_in;
@@ -235,7 +235,7 @@ STATIC mp_obj_t pyb_dac_write(mp_obj_t self_in, mp_obj_t val) {
self->state = 1;
}
- HAL_DAC_SetValue(&DAC_Handle, self->dac_channel, DAC_ALIGN_8B_R, mp_obj_get_int(val));
+ HAL_DAC_SetValue(&DAC_Handle, self->dac_channel, DAC_ALIGN_12B_R, mp_obj_get_int(val));
HAL_DAC_Start(&DAC_Handle, self->dac_channel);
return mp_const_none;