element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Connected Cloud Challenge
  • Challenges & Projects
  • Design Challenges
  • Connected Cloud Challenge
  • More
  • Cancel
Connected Cloud Challenge
Blog The Bio Highway – Making SAR ADC working with Cypress ModusToolbox (MTB)
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: vlasov01
  • Date Created: 26 Apr 2020 1:39 AM Date Created
  • Views 910 views
  • Likes 2 likes
  • Comments 0 comments
  • oocd
  • cypress psoc 6
  • debug
  • hal
  • modustoolbox
  • adc
Related
Recommended

The Bio Highway – Making SAR ADC working with Cypress ModusToolbox (MTB)

vlasov01
vlasov01
26 Apr 2020

Exploring Cypress ModusToolbox Device Configurator (MTB DC) 2.1

The last two weeks I've spent learning how to use MTB Device Configurator 2.1. In my previous post I've described my initial journey with MTB. I was able to fix Device Configurator 2.1 errors by enabling AREF and populating SAR ADC mandatory parameters. I've configured 12-bit SAR ADC  and AREF in Peripherals tab:

image

As well I connected Thermistor pins to SAR ADC in Pins tab:

image

And I was able to build the code and deploy it to my board without errors. But I was not able to find the way to initialize and use ADC components produced by the tool.

 

MTB Debuger

 

Than I've decided to verify with MTB Debugger if  SAR ADC has been initialized successfully.

While I was trying to do it I've got an error Open On-Chip Debugger:

image

I've reset the board and it started debug process without errors. So I was able to verify that there was no errors in cycfg_peripherals.c init_cycfg_peripherals().

 

Hardware Abstraction Layer (HAL) ADC

At this point I've realized that I need to move forward as time goes fast. So I switched my focus to a more simple option as it was suggested by saicheong . It is not as versatile and less precise, but allows a simple ADC read from a single channel. I've used a sample code provided in the document. I've added required headers to my Hello World program.

#include "cyhal_hw_types.h"
#include "cyhal_adc.h"

 

and created a function to initialize and read the analog output from the thermistor.

cy_rslt_t rslt;
cyhal_adc_t adc_obj;
cyhal_adc_channel_t adc_chan_0_obj;
void read_my_adc(cy_rslt_t rslt, cyhal_adc_t* adc_obj,
        cyhal_adc_channel_t* adc_chan_0_obj) {
    /* 16 bit ADC conversion result */
    uint16_t adc_out;
    /* Initialize ADC. The ADC block which can connect to pin 10[0] is selected */
    rslt = cyhal_adc_init(&*adc_obj, P10_1, NULL);
    /* Check the return of cyhal_adc_init to confirm whether initialization was successful */
    if (rslt == CY_RSLT_SUCCESS) {
        /* Initialize ADC channel, allocate channel number 0 to pin 10[0] as this is the first channel initialized */
        rslt = cyhal_adc_channel_init(&*adc_chan_0_obj, &*adc_obj, P10_1);
        /* Check the return of cyhal_adc_channel_init to confirm whether channel initialization was successful */
        if (rslt == CY_RSLT_SUCCESS) {
            /* Read the 16 bit ADC conversion result for corresponding ADC channel */
            adc_out = cyhal_adc_read_u16(&*adc_chan_0_obj);
            printf("ADC OUT:%i \r\n", adc_out);
        }
        /* Release ADC channel object after use */
        cyhal_adc_channel_free(&*adc_chan_0_obj);
    }
    /* Release ADC object after use */
    cyhal_adc_free(&*adc_obj);
}

 

It was giving me an error in the initialization. I've realized that it is conflicting for the same resources as used by the code generated by MTB DC. I've commented section of the code in cycfg.c

#include "cycfg.h"

void init_cycfg_all(void)
{
    init_cycfg_system();
    init_cycfg_clocks();
    init_cycfg_routing();
    //TODO fix
    //init_cycfg_peripherals();
    //init_cycfg_pins();
}

After this change I've started getting results from the thermistor:

ADC OUT:19104
ADC OUT:19280 
ADC OUT:19232
ADC OUT:65520 
ADC OUT:65520
ADC OUT:65520
ADC OUT:19280 
ADC OUT:19088
ADC OUT:65520 
ADC OUT:65520
ADC OUT:63632 
ADC OUT:65520 
ADC OUT:65520
ADC OUT:65520 
ADC OUT:18896
ADC OUT:4656 
ADC OUT:19136

I've tested it by touching the thermistor on the board. When it happened the ADC reading was going from ~19000 to 65520, which is equal to 1111 1111 1111 0000 in a binary format. As ADC is 12 bit, so I assume it reached the maximum value. I think the reason for this is that thermistor provides output in range 0-3.3v and HAL ADC configured to a maximum of 1.2v using internal reference voltage.

 

Next Steps

I'm going to work to connect ICSG007A ICStation Heartbeat Sensor to the board and start reading it.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube