Generate 12bits resolution analog voltage from Arduino due using simulink/PYTHON/Arduino IDE
4 ビュー (過去 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!