how to generate 12bits resolution voltage from DAC pin of arduino due board in simulink
Show older comments
Hi, I am using Arduino due board DAC pin to generate voltage. I want resolution to be 12bits. But when i use in simulink, it generates 8bit resolution voltage from 0.56v to 2.76v. Please let me know how to generate the 12bit resolution voltage from DAC pins in simulink using Arduino due board. Block says it accepts 0-4095 values, but it does not react accordingly. It does Not react for each increament, it reacts only for multiple of 16 (example: 0, 16, 32, 48, 64 ........etc..).
Can you please let me know how to solve this problem.
Can we do this in PYTHON? :)
is there any solution using creating s-block??
Thanks
Answers (1)
Manikanta Aditya
on 20 Mar 2023
0 votes
Hi Aakash,
As per my understanding, you would like to know how to generate 12-bit resolution voltage from DAC pin of Arduino Due boards in Simulink.
To change the output total number of bits to 12, Please follow the steps mentioned below:
- Open the Segmented DAC block by double clicking it.
- Under Segment Settings, click on the ‘New Segment’ option. This allows you to add a new segment.
- Change the number of bits to 4 in the newly added Segment.
- Click on ‘Apply’.
- Then you can see that the total number of bits are changed to 12. Now you can generate the 12-bit resolution voltage from DAC pins in Simulink using Arduino Due board.
For further reference, please check this link to know about Design and Evaluate Segmented DAC:
I hope this resolves the issue you are facing.
12 Comments
aakash dewangan
on 20 Mar 2023
Manikanta Aditya
on 20 Mar 2023
Edited: Manikanta Aditya
on 20 Mar 2023
Hi Aakash,
Simulink supports variable sample times for variable-step solvers only. You can read more about this in the page:
Could you try to use controllable sample times instead?
aakash dewangan
on 21 Mar 2023
aakash dewangan
on 21 Mar 2023
aakash dewangan
on 21 Mar 2023
aakash dewangan
on 21 Mar 2023
Manikanta Aditya
on 21 Mar 2023
Yes, the normal DAC block in Simulink can be used with the Simulink Support Package for Arduino.
The Simulink Support Package for Arduino provides Simulink blocks for reading and writing digital and analog signals to and from Arduino boards.
aakash dewangan
on 21 Mar 2023
Edited: aakash dewangan
on 21 Mar 2023
aakash dewangan
on 22 Mar 2023
Arun Kumar
on 6 Apr 2023
Hi Aakash,
The current implementation of DAC block in Simulink support package has a limited resolution of 8 bits which is why you are seeing only 256 steps. However Arduino due supports 12 bits resolution. We can consider this as an enhancement and update our blocks to support 12 bits resolution. However if you are blocked by this, please let us know, we can share a patch with you that can enable 12 bit resolution.
Thanks,
Arun
aakash dewangan
on 6 Apr 2023
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
Categories
Find more on Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!