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
Experts, Learning and Guidance
  • Technologies
  • More
Experts, Learning and Guidance
Ask an Expert Forum ch32v307
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Experts, Learning and Guidance to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 1 reply
  • Subscribers 284 subscribers
  • Views 597 views
  • Users 0 members are here
Related
See a helpful answer?

Be sure to click 'more' and select 'suggest as answer'!

If you're the thread creator, be sure to click 'more' then 'Verify as Answer'!

ch32v307

luciano1949
luciano1949 over 1 year ago

Hello,

I'm tryng to use a board mounting a RISC-V ch32v307 in developement ambient MounRiver Community.

You can find examples in https://github.com/openwch/ch32v307  and microcontroller RM in https://www.wch-ic.com/downloads/CH32FV2x_V3xRM_PDF.html

Many thank for 120 project examples , but I prefer a GOOD  reference manual.

The example  I try ,in EVT\EXAM\ADC\Internal_Temperature, use the internal temperature sensor  I THINK WITH CALIBRATION.

In fact the system call a Get_CalibrationValue().

Has somebody an Idea what the fonction is doing? there is a reference manual where understand this code?

*********************************************************************
 * @fn      Get_CalibrationValue
 *
 * @brief   Get ADCx Calibration Value.
 *
 * @param   ADCx - where x can be 1 or 2 to select the ADC peripheral.
 *
 * @return  CalibrationValue
 */
int16_t Get_CalibrationValue(ADC_TypeDef *ADCx)
{
    __IO uint8_t  i, j;
    uint16_t      buf[10];
    __IO uint16_t t;

    for(i = 0; i < 10; i++)
    {
        ADC_ResetCalibration(ADCx);
        while(ADC_GetResetCalibrationStatus(ADCx))
            ;
        ADC_StartCalibration(ADCx);
        while(ADC_GetCalibrationStatus(ADCx))
            ;
        buf[i] = ADCx->RDATAR;
    }

    for(i = 0; i < 10; i++)
    {
        for(j = 0; j < 9; j++)
        {
            if(buf[j] > buf[j + 1])
            {
                t = buf[j];
                buf[j] = buf[j + 1];
                buf[j + 1] = t;
            }
        }
    }

    t = 0;
    for(i = 0; i < 6; i++)
    {
        t += buf[i + 2];
    }

    t = (t / 6) + ((t % 6) / 3);

    return (int16_t)(2048 - (int16_t)t);
}

  • Sign in to reply
  • Cancel
Parents
  • koudelad
    0 koudelad over 1 year ago

    I don't have the reference manual and haven't searched for any, but the C code does the following:

    1. The function initializes variables and an array to store some ADC readings in buf[10].

    2. It then enters a loop where it performs ADC calibration and reads the ADC value 10 times. The readings are stored in the buf array.

    3. After obtaining the ADC readings, the function sorts the buf array in ascending order using a simple bubble sort algorithm.

    4. The function then calculates the average of the middle 6 values in the sorted buf array (doesn't count with the first and last two values).

    5. Finally, it calculates the calibration value by subtracting the average from 2048 and returns the result as a 16-bit signed integer (int16_t). This calibrated value is likely used for accurate ADC conversions in subsequent measurements.

    BTW I used a web search to find the function name and got results which indicate that similar API is used in STM32 HAL libraries. Maybe someone got inspired in this.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • koudelad
    0 koudelad over 1 year ago

    I don't have the reference manual and haven't searched for any, but the C code does the following:

    1. The function initializes variables and an array to store some ADC readings in buf[10].

    2. It then enters a loop where it performs ADC calibration and reads the ADC value 10 times. The readings are stored in the buf array.

    3. After obtaining the ADC readings, the function sorts the buf array in ascending order using a simple bubble sort algorithm.

    4. The function then calculates the average of the middle 6 values in the sorted buf array (doesn't count with the first and last two values).

    5. Finally, it calculates the calibration value by subtracting the average from 2048 and returns the result as a 16-bit signed integer (int16_t). This calibrated value is likely used for accurate ADC conversions in subsequent measurements.

    BTW I used a web search to find the function name and got results which indicate that similar API is used in STM32 HAL libraries. Maybe someone got inspired in this.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
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