DAC.triangle - Wrong frequency generated

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
MCHobby
Posts: 13
Joined: Mon Jan 26, 2015 2:05 pm

DAC.triangle - Wrong frequency generated

Post by MCHobby » Wed Aug 28, 2019 5:06 pm

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?

Online
User avatar
Roberthh
Posts: 1572
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: DAC.triangle - Wrong frequency generated

Post by Roberthh » Sat Aug 31, 2019 7:01 am

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?

User avatar
pythoncoder
Posts: 3543
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: DAC.triangle - Wrong frequency generated

Post by pythoncoder » Sat Aug 31, 2019 8:02 am

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.
Peter Hinch

Online
User avatar
jimmo
Posts: 553
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: DAC.triangle - Wrong frequency generated

Post by jimmo » Tue Sep 03, 2019 3:08 am

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

Post Reply