lancaster-university / codal-stm32

MIT License
1 stars 3 forks source link

timers problems #6

Closed mmoskal closed 5 years ago

mmoskal commented 5 years ago

The following makecode program

jacdac.stop()

let st = false
while (true) {
   // let end =control.millis() + 20
   // while (control.millis() <end);

   let pre = control.millis()
   pause(20)
   let len = control.millis() - pre
   control.dmesg("" + len)

   pins.D1.digitalWrite(true)
   pins.D1.digitalWrite(false)
   st = !st
   pins.D2.digitalWrite(st)
}

produces something like the following:

screen shot 2019-01-11 at 20 44 45

It's quite irregular. More importantly, control.millis() returns bogus data - many periods are reported to be way over 20ms even though it's clearly not the case on the scope.

# 21
# 20
# 73
# 78
# 21
# 20
# 20
# 73
# 23
# 20
# 87
# 21
# 77
# 23
# 20
# 20
# 87
# 21
# 20
# 20
# 20
# 20
# 73
# 74

If instead of pause() we do the delay loop, and disable jacdac (as in the program), we get nice 25Hz wave. With jacdac it's a complete mess.

It should be easy to replicate in C++.

jamesadevine commented 5 years ago

😢

mmoskal commented 5 years ago

@pelikhan tells me something is wrong with the clock on the SAMD51 as well, so maybe it's in the common code - ducks runs twice too fast or so