Generate 12bits resolution analog voltage from Arduino due using simulink/PYTHON/Arduino IDE

18 views (last 30 days)
Hi,
I want to generate 12bits resolution analog voltage from Arduino due board. 12bit resolution generation is not possible from DAC pin using simulink.
Please let me know how can I do that?
I can do that in arduino IDE and Python, but is it possible to do in simulink?
Please share the solution :)

Answers (1)

Arun Kumar
Arun Kumar on 14 Apr 2023
Edited: Arun Kumar on 14 Apr 2023
Hi Aakash,
Please modify the MW_analogWriteDAC.cpp file by running the following command:
edit(fullfile(fileparts(codertarget.arduinobase.internal.getSpPkgRootDir),'arduinobase','src','MW_analogWriteDAC.cpp'))
This will opoen the MW_analogWriteDAC.cpp file in the MATLAB editor.
Replace the existing MW_DACWrite function with the following function:
extern "C" void MW_DACWrite(uint8_T channelFlag, uint32_T value)
{
#if defined(_ROTH_DUE_)
static int init_12bitDac = 0;
if(init_12bitDac==0){
analogWriteResolution(12); /* set the resolution of the Arduino analogWrite() function to 12 bits */
init_12bitDac = 1;
}
analogWrite(((channelFlag == 0)? DAC0 : DAC1), value);
#elif defined(_ROTH_MKR1000_) || defined(_ROTH_NANO33_IOT_)
/* dividing the data by 4 to adjust for upscaling by 4 in Arduino analogWrite API */
analogWrite(DAC0, (value>>2));
#elif defined(_ROTH_MKRZERO_) || defined(_ROTH_MKRWIFI1010_)
/* dividing the data by 4 to adjust for upscaling by 4 in Arduino analogWrite API */
analogWrite(15u, (value>>2));
#elif defined(_ROTH_ESP32_)
dacWrite(((channelFlag == 1)? DAC1 : DAC2), value);
#endif
}
This will change the resolution of DAC to 12 bit on Arduino due board. Please note that this change will only work for Arduino due. Other arduino boards are not affected by this change.
Hope this helps!
Thanks,
Arun
  1 Comment
Daniel Puentes
Daniel Puentes on 12 Mar 2024
I tried this solution and it wroked, the signal from DAC1 pin worked, but my DAC0 stoped working, i don't know why. When a try to use it with simulink or arduino ide, i only have a 0V signal. Do you know how can i fix that?

Sign in to comment.

Categories

Find more on Arduino Hardware in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!