m4 tc output works. Watch out for the PAC!

This commit is contained in:
Scott Shawcroft 2018-02-12 23:41:26 -08:00
parent 0397202288
commit cc616aea4e
3 changed files with 17 additions and 6 deletions

7
main.c
View File

@ -153,6 +153,10 @@ bool start_mp(safe_mode_t safe_mode) {
serial_write(MSG_DOUBLE_FILE_EXTENSION);
}
}
reset_port();
reset_board();
reset_mp();
reset_status_led();
if (result.return_code & PYEXEC_FORCED_EXIT) {
@ -314,9 +318,6 @@ int __attribute__((used)) main(void) {
}
first_run = false;
skip_repl = start_mp(safe_mode);
reset_port();
reset_board();
reset_mp();
} else if (exit_code != 0) {
break;
}

View File

@ -330,10 +330,16 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
tc->COUNT16.CC[0].reg = top;
#endif
#ifdef SAMD51
tc->COUNT16.CTRLA.bit.SWRST = 1;
while (tc->COUNT16.CTRLA.bit.SWRST == 1) {
}
tc_set_enable(tc, false);
tc->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16 | TC_CTRLA_PRESCALER(divisor);
tc->COUNT16.CTRLBSET.bit.LUPD = true;
//tc->COUNT16.CTRLBSET.bit.LUPD = true;
tc->COUNT16.WAVE.reg = TC_WAVE_WAVEGEN_MPWM;
tc->COUNT16.CCBUF[0].reg = top;
tc->COUNT16.CCBUF[1].reg = top / 2;
#endif
tc_set_enable(tc, true);
@ -404,7 +410,10 @@ extern void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self,
tc_insts[t->index]->COUNT16.CC[t->wave_output].reg = adjusted_duty;
#endif
#ifdef SAMD51
tc_insts[t->index]->COUNT16.CCBUF[t->wave_output].reg = adjusted_duty;
while (tc_insts[t->index]->COUNT16.SYNCBUSY.bit.CC1 != 0) {
// Wait for a previous value to be written.
}
tc_insts[t->index]->COUNT16.CCBUF[1].reg = adjusted_duty;
#endif
} else {
uint32_t adjusted_duty = ((uint64_t) tcc_periods[t->index]) * duty / 0xffff;

View File

@ -46,6 +46,7 @@
#include "common-hal/analogio/AnalogIn.h"
#include "common-hal/analogio/AnalogOut.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/pulseio/PWMOut.h"
#include "tick.h"
extern volatile bool mp_msc_enabled;
@ -206,8 +207,8 @@ void reset_port(void) {
// pdmin_reset();
// pulsein_reset();
// pulseout_reset();
// pwmout_reset();
// #endif
pwmout_reset();
analogin_reset();