Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

myDVM Done Dirt Cheap - Part 2: Time to add a DAC

myDVM Done Dirt Cheap - Part 2: Time to add a DAC

ScottKerstein
Employee
Employee
5 solutions authored 10 likes received 25 sign-ins

I remember when I got my first toolbox and I had to fill it up with tools.  Okay, most of them were my dad’s tools, nevertheless they were useful tools, and each tool solved a different problem.

ModusToolbox is no different.  It’s a toolbox containing useful tools to configure and generate code for Infineon MCU peripherals.  These tools can be used within the ModusToolbox framework or launched separately as standalone tools for use with IAR, uVision or Visual Studio.

In Part 1 of my blog “myDVM Done Dirt Cheap”, I made a DVM to measure battery cells using the CY8CPROTO-063-BLE proto board.  Those batteries have since been depleted in game controllers.  I still want to measure other analog sources. though.  Hey, what about using the 12-bit Continuous Time Digital to Analog Converter (CTDAC) in CY8C6347BZI-BLD53 MCU?  I could create an analog output and feed it to the ADC configured in Part 1. 

January is cold in Michigan and instead of playing with electronics, I probably should be cleaning the basement.  That’s not fun, though.

PSoc 6 DAC code examples are not available.  I will use a tool found in ModusToolbox 3.0.  Device Configurator will generate the needed configuration code for me using the Peripheral Driver Library (PDL.)  The PSoC 6 PDL documentation will provide examples for the API calls needed to initialize and set the output voltage – another useful tool.

I mentioned in Part 1 of this blog, that the ADC code example uses Hardware Abstraction Layer (HAL) drivers.  I could continue using PSoC 6 HAL drivers for the DAC, but it is easier to let the Device Configurator tool do the work for me.  Fortunately, ModusToolbox allows me to mix and match HAL and PDL within the same application code.

PDL vs. HAL?  I’ll let you decide.  The answer depends on your goals.  For me, I have enough Flash to support the extra code that HAL brings.  Remember, I like tools.  If you want to learn more, Infineon has plenty of ModusToolbox training located on our GitHub for PSoC 6, PSoC 4, XMC, AIROC Bluetooth, WiFi and Machine Learning.  Read “Chapter 2: Peripherals” in “ModusToobox Software Training Level 2 – PSoC MCUs” for more on PDL and HAL.

Software Actions

The link found in lower left “Quick Panel” takes me to the CY8CPROTO-063-BLE BSP documentation.  The DAC has a VDDA reference, so my DAC output will be 0V to 3.3V.   Important to know when I go to configure the DAC.

ScottKerstein_0-1674479348096.png

 

Memory recall…

I will use the ADC to measure the DAC.  I remember in Blog Part 1, I had change the ADC Vref from “VDDA” to “VDDA/2” in the myDVM code .  Since my DAC can output up to 3.3V, I need to change the ADC Vref back to “VDDA” in main.c on Line 145 so I can measure full scale (0 to 3.3V.)

 

ScottKerstein_1-1674479348117.png

 

The Device Configurator can be found in the ModusToolbox “Quick Panel”, too.  I can also launch the tool standalone from your OS (i.e. Windows Start menu.)  I will need this tool to add and configure the DAC.

ScottKerstein_2-1674479348129.png

 

Launching the tool prompts me with configuration options.  Outlined are the steps I took:

ScottKerstein_3-1674479348156.png

 

Step 1:  Select the 12-bit Continuous Time DAC 0.  I changed the default name.

Step 2:   I chose “0xBEE” for my initial DAC output.  It’s not boring like 0xFFF (3.3V) or 0x7FF (1.65V) and seems good to me.

From the BSP documentation, the maximum output range of the DAC is 3.3V, which is 0xFFF.  Converting 0xFFF yields 4095 decimal.  Converting 0xBEE yields 3054 decimal.  Converting 0xBEE to a voltage is straightforward using proportional math skills. 

ScottKerstein_4-1674479348157.png

 

Solving for X:

X (4095) = 3.3 (3054)

X = 3.3 (3054) / (4095)

X = 2.46 Volts

Math teachers always like to markdown for missing units.  Not this time, Mr. Wilson!

If my ADC measures 2.46 V, then I will know my DAC is functioning.

Step 3:  I need to drive the DAC with a clock.  Does not matter which one at this point.

Step 4:  The PSoC 63 BLE datasheet indicates the DAC output is internally routed to the P9(6) analog pin, so I will select P9(6).

ScottKerstein_5-1674479348160.png

 

  First, I have to add software functions to make the DAC work in hardware, else it will not work.

Step 5:  Save and generate the constants for the DAC register within cycfg_peripherals.c.  Saving replaces any previously generated files, so I must be care making code changes outside the configurator and returning to the tool.  Returning tools is not my nature.

ScottKerstein_6-1674479348184.png

 

 

Just because I generated some configuration code, it doesn’t mean the DAC is going to work after I build.  I need to initialize and enable the DAC.  Back to the PSoC 6 PDL documentation

Yep, it has API functions for the DAC with example code on how it works.

ScottKerstein_7-1674479348209.png

 

 

ScottKerstein_8-1674479348230.png

I will add this code to “main.c” starting at line 240 through line 248 keeping in mind to change the name of the ‘&config’ pointer if I copy and paste from the documentation.  I will get an ‘undeclared’ error if I don’t.

ScottKerstein_9-1674479348232.png

 

myDVM_dac_0_config is the pointer to the structure containing CTDAC configuration data.  The pointer name is found in the code I generated above in ‘cycfg_peripherals.c’.

ScottKerstein_10-1674479348235.png

 

Always good to build and look for any errors. 

Yep, I have some. 

ScottKerstein_11-1674479348241.png

CTBM0’ not being declared started the error chain.  I really do not know how to fix this, though, or the function of CTBM0.

I see Section 37.2 of the PSoC 63 with BLE Architecture Technical Reference Manual that the CTBm means Continuous Time Block mini, and it is not directly part of the CTDAC, only related.  The CTBm block has two identical opamps: a switch routing matrix and a sample and hold circuit for the CTDAC output.   

Clicking the error sends me to ‘the bug’ at Line 33 in ‘cycfg_routing.c’.   Maybe the Resource Library on Infineon’s Developer Community has more information on the operation at Line 33.  My search led me to this page and I found out that Line 33 enables the CTBm.   I do not have a need for the opamps at this time.  Maybe I can comment out Line 33 and it would build just fine. 

ScottKerstein_12-1674479348242.png

Okay, commenting Line 33 does remove this error.  How do I fix this if I wanted to use the opamps?  Hmm.

First, I’ll search the Infineon Community to see if other developers saw this same issue.  Didn’t find anything.  I know Infineon Application Engineers monitor the community and will help.  Other developers can help if they see my posting and know the answer.  I will post my own question.

Woo-Hoo!  The community helped me out and it will help someone else out in the future.

https://community.infineon.com/t5/ModusToolbox-General/PSoC-63-error-CTBM0-undeclared/td-p/392382

Adding the include below in the ‘cyconfig_routing.c” file and building again results with 0 errors. 

The solution makes sense because the CY8CPROTO-063-BLE board uses a CYBLE-416045-02 certified module containing PSoC 63-BLE silicon.  Adding the include could help me later in development when adding other functions.  I would not learn from commenting.

ScottKerstein_13-1674479348247.png

 

ScottKerstein_14-1674479348247.png

I could have searched for ‘CTBM0’ using the ModusToolbox search feature also:

ScottKerstein_15-1674479348249.png

 

I would have found the device header file which uses ‘CTBM0’ associated with the dev board, in the ‘mtb_shared’ folder.  Don’t know why the mtb_shared folder is here?  Look in the ModusToolbox User Guide Section 1.3.4 found in the ModusToobox install documentation directory or on Infineon.com.

ScottKerstein_16-1674479348259.png

 

Think I got this now.  It’s time to launch my Terminal program (CoolTerm), find the COM port assigned to the CY8CPROTO-063-BLE board and set the baud rate to 115200.

Hardware Actions

The myDVM positive probe soldered in Blog Part 1 needs to be connected to the DAC output (P9.6) so it can be measured by the ADC (P10.0.)  Ground the ground probe.

ScottKerstein_17-1674479348364.png

 

Sure enough, the initial 0xBEE DAC setting measures approximately 2.46V.

ScottKerstein_18-1674479348366.png

Wow! I learned a lot about the technical resources and tools available for the PSoC 63 with BLE and its certified module.  Makes me want to go back to Lines 49 and 50 in ‘main.c’ and modify the initial hex value for a different DAC output. 

Instead, I think I will set my sight on the BLE radio found in the device for Part 3 of this Blog and avoid cleaning my basement – again. 

255 Views
Authors