Generate 12bits resolution analog voltage from Arduino due using simulink/PYTHON/Arduino IDE
조회 수: 6 (최근 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!