<< Chapter < Page Chapter >> Page >
This module contains the C code for the Force Sensor example.

The following link contains all of the files necessary to compile the project using IAR Embedded Workbench. The zip file contains main.c lcd.c and lcd.h Code Listing.zip
To view the code listings for lcd.c and lcd.h please download the zip file and open them in any text editor. /************************************************* * EEL3111 Student Project - Force Sensor Group* Code by: Michael Toth * Questions: totm0001@unf.edu*************************************************/ #include "msp430x44x.h"#include "lcd.h" #include "math.h"#define Average 4 // This value controls the number of samples // to be taken before an average is computed// and the LCD is updated. #define Vref 3.3 // Don't change this unless you know what you are doingvolatile unsigned int x=1; long int ADC0;float ADC0Averaged; float ADC0temp;float Voltage; float Converted;unsigned int hundreds, tens, ones, tenths; /************************************* Function Prototypes ************************************/void clock_config(void); void adc12_config(void);//void opamp_enable(int); void update_lcd(void);float convert_value(float); void extract_digits(float);/************************************ * Main Loop************************************/ void main(void){ clock_config(); // Configure clockadc12_config(); // Configure ADC12 // opamp_enable(1); // 1=enabled 0=disabledsetupLCD(); // Called from lcd.c, performs LCD setup lcd_all(0); // clear the LCD// Enable interrupts and go to sleep forever _EINT();while(1){_NOP(); // loop forever but still servicing interrupts }} /************************************* Clock Configuration Subroutine ************************************/void clock_config(void){ WDTCTL = WDTPW + WDTHOLD; // Stop WDTFLL_CTL0 |= XCAP10PF; // Configure load caps BTCTL = BT_ADLY_250; // 250ms InterruptIE2 |= BTIE; // Enable BT interrupt }/************************************ * ADC12 Configuration Subroutine************************************/ void adc12_config(void){ADC12IE |= 0x01; // Enable ADCMEM0 interrupt ADC12CTL1 = ADC12SSEL_2 | SHP; // ADCCLK = mCLK, pulse modeADC12MCTL0 = SREF_0 | INCH_0; // Vr+=AVcc and Vr-=AVss // warm-up the ADCADC12CTL0 = REFON | ADC12ON; // turn on ref and ADC ADC12CTL0 |= ENC; // enable conversions} /************************************* Opamp Enable Subroutine: * The project board includes a place for* a surface mounted opamp. The opamp has * a pin that must be set high for the opamp* to function. The pin is connected to P2.7 * by setting P2.7 high the opamp is enabled,* low the opamp is disabled ************************************//* void opamp_enable(int x){P2DIR |= BIT7; // Set P2.7 to output direction if(x==1){P2OUT |= BIT7; // set P2.7 high. Enables Opamp }*/ /*************************************** Update LCD Subroutine **************************************/void update_lcd(void){ lcd_char(0,ones + '0');lcd_char(1,tens + '0'); lcd_char(2,hundreds + '0');} /*************************************** Convert Value Subroutine: * Convert from voltage to sensor value.* Formulas usually available in datasheet * for specific sensors.***************************************/ float convert_value(float voltage){float value; value = 14.609*pow(voltage,4)-38.65*pow(voltage,3)+47.017*pow(voltage,2)+10.847*voltage-0.2188;return value; }/*************************************** * Extract Digits Subroutine:* The LCD driver requires that each digit * be presented to the LCD individually. i.e.* if you want to display 3.14 on the LCD 3, 1, * and 4 must be held in seperate variables.* This algorithm assumes only positive values.... * xxx.xx can be represented****************************************/ void extract_digits(float converted){hundreds = (int)converted / 100; // extract hundreds digit tens = (int)((converted - (hundreds*100)) / 10); // extract tens digitones = (int)converted - hundreds*100-(tens * 10); // extract ones digit }/************************************ * Interrupt Subroutines************************************/ // Basic Timer interrupt service routine#pragma vector=BASICTIMER_VECTOR __interrupt void basic_timer(void){ // start a conversion// when conversion is complete ADC12 interrupt will take place ADC12CTL0 |= ADC12SC;} // ADC12 Interrupt Service Routine#pragma vector=ADC12_VECTOR __interrupt void ADC12ISR (void){ ADC0 = ADC12MEM0; // IFG is clearedADC0temp+=ADC0; // accumulate values to average if(x==Average){ // test if enough values have been collectedADC0Averaged=ADC0temp/Average; // compute the average value Voltage=ADC0Averaged*Vref; // multiply by Vref to obtain voltage representaionVoltage=Voltage/4095; // divide by #quantization levels Converted=convert_value(Voltage); // Convert voltage to appropriate unitsextract_digits(Converted); // Extract individual digits update_lcd(); // Update the LCD displayx=1; // Reset the averaging loop ADC0temp=0;} else{x++; }}

Questions & Answers

where we get a research paper on Nano chemistry....?
Maira Reply
what are the products of Nano chemistry?
Maira Reply
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
learn
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
learn
Google
da
no nanotechnology is also a part of physics and maths it requires angle formulas and some pressure regarding concepts
Bhagvanji
Preparation and Applications of Nanomaterial for Drug Delivery
Hafiz Reply
revolt
da
Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
Jyoti Reply
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
Nasa has use it in the 60's, copper as water purification in the moon travel.
Alexandre
nanocopper obvius
Alexandre
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
Hafiz
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Eel3111 force sensor group july 2010. OpenStax CNX. Aug 23, 2010 Download for free at http://cnx.org/content/col11221/1.2
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Eel3111 force sensor group july 2010' conversation and receive update notifications?

Ask