Generate 12bits resolution analog voltage from Arduino due using simulink/PYTHON/Arduino IDE
12 次查看(过去 30 天)
显示 更早的评论
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 :)
0 个评论
回答(1 个)
Arun Kumar
2023-4-14
编辑:Arun Kumar
2023-4-14
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 个评论
Daniel Puentes
2024-3-12
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?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Arduino Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!