<< 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

How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
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
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
How can I make nanorobot?
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
how can I make nanorobot?
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
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?