analogWrite issues stm32vldiscovery via DAC

The official STMicroelectronics Arduino core
Post Reply
User avatar
Rick Kimball
Posts: 1038
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

analogWrite issues stm32vldiscovery via DAC

Post by Rick Kimball » Fri Jul 14, 2017 7:20 pm

I'm trying out the DISCO_F100RB from the pull request https://github.com/fpistm/Arduino_Core_ ... erge_Other.

The range of the values doesn't seem to match the VCC voltage.

Measuring the "3.3v" pin on the boards shows a reading of 2.99V

analogWrite(9,0); results in a 59mV reading on PA4.
analogWrite(9,255) results in 2.95V reading on PA4.
analogWrite(9,127) results in 1.49V reading on PA4.
analogWrite(9,63) results in 737mV reading on PA4.

Shouldn't a value of 255 produce the full range of 2.99 and a value of 0 produce a 0 V? The 127 and 63 value seems to be right.

What is the expected behavior?
-rick

User avatar
Wi6Labs
Posts: 25
Joined: Fri Sep 16, 2016 11:39 am
Location: Rennes, France
Contact:

Re: analogWrite issues stm32vldiscovery via DAC

Post by Wi6Labs » Mon Jul 17, 2017 10:42 am

Rick,

It seems your values are good to regards of the datasheet.

DAC ouput range:
  • min = 0.2V
  • max = VDDA - 0.2
So I think you couldn't have better values.
Wi6Labs team

User avatar
Pito
Posts: 1592
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: analogWrite issues stm32vldiscovery via DAC

Post by Pito » Mon Jul 17, 2017 11:59 am

With DiscoVL you have got there an onchip 12bits dual DAC!
So you do not use analogWrite() [PWM based poor's man DAC], but you shoot 12bit numbers into the 12 bit DAC :)
Long time back I did measurements and you get the values from zero to almost Vdd (not sure I had DAC buffer on).
Pukao Hats Cleaning Services Ltd.

User avatar
Rick Kimball
Posts: 1038
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: analogWrite issues stm32vldiscovery via DAC

Post by Rick Kimball » Mon Jul 17, 2017 12:30 pm

The analogWrite() in the official STM core (see link in first post) uses the DAC peripheral if the pin is capable and falls back to PWM if not. I was using PA4 which is DAC CHANNEL 1.
-rick

User avatar
Rick Kimball
Posts: 1038
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: analogWrite issues stm32vldiscovery via DAC

Post by Rick Kimball » Mon Jul 17, 2017 2:44 pm

Wi6Labs wrote:
Mon Jul 17, 2017 10:42 am
Rick,

It seems your values are good to regards of the datasheet.

DAC ouput range:
  • min = 0.2V
  • max = VDDA - 0.2
So I think you couldn't have better values.
Thanks I was reading another document (AN3126) which gave this formula:
DACOutput = VREF x DOR / 4096

Which on some level made no sense as you can only use 0-4095 as values. However it didn't mention the electrical limitations from the data sheet
-rick

Post Reply