Page 1 of 1

DAC.triangle - Wrong frequency generated

Posted: Wed Aug 28, 2019 5:06 pm
by MCHobby
Hi There,
I wanted to generate a triangle at 60 Hz on my original Pyboard 1.1 (firmware v1.11-126... on 2019-07-05)
After documentation read, I did wrote this small snip of code:

Code: Select all

>>> import pyb
>>> dac = pyb.DAC(1, bits=12)
>>> triangle_freq = 60
>>> sample_freq = triangle_freq * 2048
>>> dac.triangle( sample_freq )
And use my scope (Rigol DS1054) to capture it.
As result, I have a Triangle @ 14.79 Hz (4 times less than expected 60 Hz triangle ).
Image

Did I miss something obvious?

Re: DAC.triangle - Wrong frequency generated

Posted: Sat Aug 31, 2019 7:01 am
by Roberthh
Is it always off by a factor of 4? So do you get 60 Hz if you ask for 240? Or does it seem to hit a maximum step frequency?

Re: DAC.triangle - Wrong frequency generated

Posted: Sat Aug 31, 2019 8:02 am
by pythoncoder
I can confirm this. Setting the frequency to 240Hz produces a 60Hz triangle. Setting the DAC to 8 bit resolution makes no difference.

This is surely a firmware bug. @MCHobby I suggest you raise an issue, otherwise I can do it.

Re: DAC.triangle - Wrong frequency generated

Posted: Tue Sep 03, 2019 3:08 am
by jimmo
pythoncoder wrote:
Sat Aug 31, 2019 8:02 am
This is surely a firmware bug. @MCHobby I suggest you raise an issue, otherwise I can do it.
Looks like this was broken when this method was changed to use full-scale. So now the multiplier is 8192 (12-bit DAC, so 4096 samples up and 4096 down).

Unfortunately to retain the existing behavior we'd have to set the scale back to quarter-range. So I think we probably need to fix the documentation -- https://github.com/micropython/micropython/pull/5062