|
Introduction to Microcontroller Programming * Course Index * Introduction * About the Author * About this Course * Feedback * Course Navigation * Quick Course Navigation * How to use this Course * Acronyms Used and Course Conventions About PICmicro Chips * What is a PICmicro? * Microcontrollers * Digital versus Analogue * Inputs and Outputs * Memory * Programming * 16F1937 Architecture Clocking Your PICmicro Devices * Introduction * The Clock Circuit * Clock Settings * Clock Confusion E-Blocks * Introduction to E-blocks * Using E-blocks * E-blocks Boards Flowcode Step By Step * Introduction to Flowcode * Basic Flowcode Functions * Digital Outputs * Digital Inputs * Basic Loops * The LCD Display * Binary Numbers * Decisions * Goto (Connection Point) * 7-Segment Displays * Software Macro * Strings and Memory * A Simple Hi-Fi ## Introduction ## Set up the Equipment ## Port B Interrupts ## Setting up the LCD ## Using the ADC ## Finishing Touches PICmicro Projects * Introduction to PICmicro Projects * Construction Methods * Choosing a Power Source * Adding Inputs * Input Conditioning * Adding Outputs * Adding Drivers Labs * Introduction and Lesson Plan * 1. Output * 2. Delay * 3. Connection Point * 4. Calculations * 5. Loop * 6. Input * 7. Decision * 8. LCD * 9. Keypad * 10. Analogue + EEPROM * 11. Software Macro * 12. External Interrupt * 13. Timer Interrupt |
(:Summary:Contains the 'action' links (like Browse, Edit, History, etc.), placed at the top of the page, see site page actions:) (:comment This page can be somewhat complex to figure out the first time you see it. Its contents are documented at PmWiki.SitePageActions if you need help. :) * Print (:comment (:if group Site,SiteAdmin,Cookbook,Profiles,PmWiki*:) (:comment delete if and ifend to enable backlinks:) * %item rel=nofollow class=backlinks accesskey='$[ak_backlinks]'% [[{*$Name}?action=search&q=link={*$FullName} | $[Backlinks] ]] (:ifend:) :) * Login Using the ADC<^< Setting up the LCD | Course Index | Finishing Touches >^>(:nl:) So far you have set up two interrupts, and three macros which are called from the main routine. In this next part of the project you will set up a further macro that will measure the signal on an analogue input. # Add an ADC component onto your project panel. Alter the connection so that it is connected to ADC 1 - this is the potentiometer on the Sensor board. # Add a new macro and call it 'ADCmeasure'. # Add a Component macro to the 'ADCmeasure' macro. Set it to 'GetInt' to read the value of the ADC into the variable 'ADCreading' that you set up previously. # Drag a Calculation icon into the macro and enter 'volume = ADCreading / 10' into the Calculation field. You should have something like this: ![]() The process of sampling the ADC is a two stage one: first sample the value and then read the value into a variable. The PICmicro we are using here actually has up to 8 ADC inputs - AN0 to AN8. Internally however the PICmicro only has one Analogue to Digital Converter. Each of the 8 inputs can be switched to the ADC using internal analogue switches. This gives you a clue as to why the process of getting an analogue input into your program is a two stage process: internally Flowcode sets up the analogue switch to connect to the relevant input, then it takes a reading. The ADC inside the PICmicro has a resolution of 10 bits. This means that to make use of the full range of the ADC you need to use a variable of type Int: a 16 bit variable. The value you read will vary between 0 and 1023. However we are used to seeing Volume presented as 0 to 10, or 0 to 100. Because of this we can quickly divide the ADC reading by 10 to get a scale of 0 to 102 as our volume setting. You should by now be able to think of programming techniques to cap the value at 100. (:nl:)(:table style="clear:both":)
| |
(:Summary: Website page footer:)
Print - (:comment (:if group Site,SiteAdmin,Cookbook,Profiles,PmWiki*:) (:comment delete if and ifend to enable backlinks:) %item rel=nofollow class=backlinks accesskey='$[ak_backlinks]'% [[{*$Name}?action=search&q=link={*$FullName} | $[Backlinks] ]] (:ifend:) :) Search - Login
Page last modified on May 02, 2013, at 02:27 PM