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
Freedom development platform
  • Products
  • Dev Tools
  • Freedom development platform
  • More
  • Cancel
Freedom development platform
Blog Displaying 12-bit ADC value on hyperterminal by connecting a potentiometer and indicating through LED [Implementing 12-bit ADC using KSDK on FRDM-KL28Z freedom board by polling method]
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Freedom development platform to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: bheemarao
  • Date Created: 4 Oct 2016 12:01 PM Date Created
  • Views 824 views
  • Likes 0 likes
  • Comments 0 comments
  • kds+ksdk
  • frdm-kl28z
Related
Recommended

Displaying 12-bit ADC value on hyperterminal by connecting a potentiometer and indicating through LED [Implementing 12-bit ADC using KSDK on FRDM-KL28Z freedom board by polling method]

bheemarao
bheemarao
4 Oct 2016

This blog gives an overview on implementing 12-bit ADC by polling method and displaying the digital values over hyper terminal. Corresponding to the digital values the Red Green and Blue LED’s are indicated.

 

For 12-bit resolution ADC the digital value ranges from 0 to 4095 (0 - 2^12), if the value is in between 0 to 1200 RED led is switched on and  if the value is in between 1200 and 2500 Green led is switched on, if the value is in between 2500 and 4095 Blue led is switched on.

 

ADC port is assigned to ADC0-SE23 -> PTE-30 which is located on jumper J2-11as shown below:

image

The potentiometer connection is done as shown below

image

 

RGB led’s are connected as shown below

image

image

Software code for this project is given below:

  Add below lines in main.c file

#include"fsl_debug_console.h"
#include "board.h"
#include "fsl_adc16.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "fsl_port.h"
#include "fsl_gpio.h"
#include "fsl_common.h"
#include "pin_mux.h"
#include "clock_config.h"

#define DEMO_ADC16_BASE ADC0
#define DEMO_ADC16_CHANNEL_GROUP 0U
#define DEMO_ADC16_USER_CHANNEL 23U /* PTE30, ADC0_SE23 */

int main(void)
{
 adc16_config_t adc16ConfigStruct;
 adc16_channel_config_t adc16ChannelConfigStruct;

 BOARD_InitPins();
 BOARD_BootClockRUN();
 BOARD_InitDebugConsole();

 CLOCK_EnableClock(kCLOCK_PortE);
 CLOCK_EnableClock(kCLOCK_PortC);

 PORT_SetPinMux(PORTE, 29U, kPORT_MuxAsGpio); //RED
 PORT_SetPinMux(PORTC, 4U, kPORT_MuxAsGpio); //Green
 PORT_SetPinMux(PORTE, 31U, kPORT_MuxAsGpio); // Blue

 LED_RED_INIT(LOGIC_LED_OFF);
 LED_GREEN_INIT(LOGIC_LED_OFF);
 LED_BLUE_INIT(LOGIC_LED_OFF);

 int val,i;

 PRINTF("\r\nADC16 polling Example.\r\n");

 ADC16_GetDefaultConfig(&adc16ConfigStruct);
 ADC16_Init(DEMO_ADC16_BASE, &adc16ConfigStruct);
 ADC16_EnableHardwareTrigger(DEMO_ADC16_BASE, false); /* Make sure the software trigger is used. */
 #if defined(FSL_FEATURE_ADC16_HAS_CALIBRATION) && FSL_FEATURE_ADC16_HAS_CALIBRATION
 if (kStatus_Success == ADC16_DoAutoCalibration(DEMO_ADC16_BASE))
 {
 PRINTF("ADC16_DoAutoCalibration() Done.\r\n");
 }
 else
 {
 PRINTF("ADC16_DoAutoCalibration() Failed.\r\n");
 }
#endif /* FSL_FEATURE_ADC16_HAS_CALIBRATION */

 adc16ChannelConfigStruct.channelNumber = DEMO_ADC16_USER_CHANNEL;
 adc16ChannelConfigStruct.enableInterruptOnConversionCompleted = false;
#if defined(FSL_FEATURE_ADC16_HAS_DIFF_MODE) && FSL_FEATURE_ADC16_HAS_DIFF_MODE
 adc16ChannelConfigStruct.enableDifferentialConversion = false;
#endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */

 while (1)
 {
 //GETCHAR();
 for(i=0;i<=1000000;i++);
 ADC16_SetChannelConfig(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP, &adc16ChannelConfigStruct);
 while (0U == (kADC16_ChannelConversionDoneFlag &
 ADC16_GetChannelStatusFlags(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP)))
 {
 }

 val = ADC16_GetChannelConversionValue(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP);

         if((val >= 0) && (val <= 1200))
         {
            LED_RED_ON();
            LED_GREEN_OFF();
            LED_BLUE_OFF();
         }

         if((val >= 1200) && (val <= 2500))
                {

                   LED_GREEN_ON();
                   LED_RED_OFF();
                   LED_BLUE_OFF();
                }

         if((val >= 2500) && (val <= 4095))
            {

               LED_BLUE_ON();
               LED_GREEN_OFF();
               LED_RED_OFF();
            }

 PRINTF("ADC Value: %d\r", val);
 }
}

 

The project has been implemented using KDS+KSDK

image

 

Code Explanation:

 

For ADC part:

Structure adc16_config_t has the parameters like reference voltage, input clock source, divider of input clock source, sample resolution mode, long sample mode, high-speed mode, low power and continuous conversion mode.

Resolution is defined by the variable:

config->resolution = kADC16_ResolutionSE12Bit;

Channel configuration is done by the structure adc16_channel_config_t

 

Below are the configuration done for this project:

ADC16_GetDefaultConfig(&adc16ConfigStruct);

adc16ConfigStruct->referenceVoltageSource = kADC16_ReferenceVoltageSourceVref;

adc16ConfigStruct->clockSource = kADC16_ClockSourceAsynchronousClock;

adc16ConfigStruct->enableAsynchronousClock = true;

adc16ConfigStruct->clockDivider = kADC16_ClockDivider8;

adc16ConfigStruct->resolution = kADC16_ResolutionSE12Bit;

adc16ConfigStruct->longSampleMode = kADC16_LongSampleDisabled;

adc16ConfigStruct->enableHighSpeed = false;

adc16ConfigStruct->enableLowPower = false;

adc16ConfigStruct->enableContinuousConversion = false;

 

Interrupts are disabled by below function

adc16ChannelConfigStruct.enableInterruptOnConversionCompleted = false;

 

ADC channel number is located at

adc16ChannelConfigStruct.channelNumber = DEMO_ADC16_USER_CHANNEL;

(In my case it is define as  DEMO_ADC16_USER_CHANNEL = 23U)

  1. i.e ADC channel-0,  ADC0_SE23

 

Differential conversion is disabled

adc16ChannelConfigStruct.enableDifferentialConversion = false;

 

ADC16_SetChannelConfig will start the ADC to perform its task

ADC16_GetChannelConversionValue will get the converted value

 

Port pin settings

 

PORT_SetPinMux(PORTE, 29U, kPORT_MuxAsGpio); //RED

 

The above function set the portE-29 pin as output and similar with PortE-31 and PortC-4

 

LED_RED_INIT(LOGIC_LED_OFF);

 

The above function initialises the red led in off condition

Similar the case with Green and Blue led initialisation

 

The digital value is stored in variable ‘val’ and compared as below

If the value is in between 0 to 1200 RED led is switched on

 

if((val >= 0) && (val <= 1200))
         {
            LED_RED_ON();
            LED_GREEN_OFF();
            LED_BLUE_OFF();
         }

If the value is in between 1200 and 2500 Green led is switched on

 

         if((val >= 1200) && (val <= 2500))
          {
           LED_GREEN_ON();
           LED_RED_OFF();
           LED_BLUE_OFF();
           }

 

 

If the value is in between 2500 and 4095 Blue led is switched on

 

         if((val >= 2500) && (val <= 4095))
            {
                LED_BLUE_ON();
                LED_GREEN_OFF();
                LED_RED_OFF();
            }

 

The video output execution of this project is shown below:

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

The project folder is attached here for quick evaluation and reference.

Attachments:
ADC-POT-Val-polloing.rar
  • 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