Jump to content

SamSMK

Members
  • Content Count

    5
  • Joined

  • Last visited

About SamSMK

  • Rank
    Noob Class

Profile Information

  • Location
    USA
  1. MSP 430 We need to edit it and make it read a battery voltage and we can't use normal c or c++
  2. I have made this code with my group now we want to edit it and make the code read voltage of a battery but we're not sure how to edit it because the professor want it in the same form as below and by the simple C Please don't forget to put comments so I would know what you actually changed float ThresholdExceeded = 0; char x[] = " out of 3.3v \n"; volatile unsigned int i=2001; void setup() { ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on ADC12CTL1 = ADC12SHP; // Use sampling timer ADC12IE = 0x01; // Enable interrupt ADC12CTL0 |= ADC12ENC; P6SEL |= 0x01; // P6.0 ADC option select P1DIR |= 0x01; // P1.0 output P4DIR |= 0x80; // P4.7 output Serial.begin(9600); } void loop() { ADC12CTL0 |= ADC12SC; // Start sampling/conversion __bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit __no_operation(); // For debugger /* Serial.println(ThresholdExceeded); */ if(i<1000) // continuous loop { P1OUT |= BIT0; // P1.0=1 /* for(i=50000;i>0;i--); */ // Delay } else { P1OUT &= ~BIT0; } // P1.0 = 0 Serial.println(i); i=i+1; } #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector = ADC12_VECTOR __interrupt void ADC12_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12_ISR (void) #else #error Compiler not supported! #endif { switch(/*__even_in_range(ADC12IV,34)*/ADC12IV) { case 0: break; // Vector 0: No interrupt case 2: break; // Vector 2: ADC overflow case 4: break; // Vector 4: ADC timing overflow case 6: // Vector 6: ADC12IFG0 if (ADC12MEM0 >= 0xFA0) // ADC12MEM = A0 > 0.5AVcc? {i=0;} /* {P4OUT &= ~BIT7; // P4.7 = 0 P1OUT &= ~BIT0; } // P1.0 = 0 /* else if (ADC12MEM0 <= 0x6d6) {P4OUT &= ~BIT7; // P4.7 = 0 P1OUT |= BIT0; } // P1.0 = 1 else if (ADC12MEM0 <= 0x794) {P4OUT |= BIT7; // P4.7 = 0 P1OUT |= BIT0; } /*else {P4OUT &= ~BIT7; // P4.7 = 1 P1OUT &= ~BIT0; } // P1.0 = 1 */ __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU case 8: break; // Vector 8: ADC12IFG1 case 10: break; // Vector 10: ADC12IFG2 case 12: break; // Vector 12: ADC12IFG3 case 14: break; // Vector 14: ADC12IFG4 case 16: break; // Vector 16: ADC12IFG5 case 18: break; // Vector 18: ADC12IFG6 case 20: break; // Vector 20: ADC12IFG7 case 22: break; // Vector 22: ADC12IFG8 case 24: break; // Vector 24: ADC12IFG9 case 26: break; // Vector 26: ADC12IFG10 case 28: break; // Vector 28: ADC12IFG11 case 30: break; // Vector 30: ADC12IFG12 case 32: break; // Vector 32: ADC12IFG13 case 34: break; // Vector 34: ADC12IFG14 default: break; } ThresholdExceeded = ADC12MEM0; }
  3. Hi guys, So, we are making a project where we use 3 UV sensors. We want to get the readings of 3 sensors connected together but we want the serial monitor to show only the readings of the highest intensity of the sensors. So whenever one of the sensor is been directed towards the sun we want only that sensor's readings to show up. And we are not sure how to make the 3 sensors all in one code Thanks! This is the original code of one sensor //Hardware pin definitions int UVOUT = A0; //Output from the sensor int REF_3V3 = A1; //3.3V power on the Arduino board void setup() { Serial.begin(9600); pinMode(UVOUT, INPUT); pinMode(REF_3V3, INPUT); Serial.println("ML8511 example"); } void loop() { int uvLevel = averageAnalogRead(UVOUT); int refLevel = averageAnalogRead(REF_3V3); //Use the 3.3V power pin as a reference to get a very accurate output value from sensor float outputVoltage = 3.3 / refLevel * uvLevel; float uvIntensity = mapfloat(outputVoltage, 0.99, 2.8, 0.0, 15.0); //Convert the voltage to a UV intensity level Serial.print("output: "); Serial.print(refLevel); Serial.print("ML8511 output: "); Serial.print(uvLevel); Serial.print(" / ML8511 voltage: "); Serial.print(outputVoltage); Serial.print(" / UV Intensity (mW/cm^2): "); Serial.print(uvIntensity); Serial.println(); delay(100); } //Takes an average of readings on a given pin //Returns the average int averageAnalogRead(int pinToRead) { byte numberOfReadings = 8; unsigned int runningValue = 0; for(int x = 0 ; x < numberOfReadings ; x++) runningValue += analogRead(pinToRead); runningValue /= numberOfReadings; return(runningValue); } //The Arduino Map function but for floats //From: http://forum.arduino.cc/index.php?topic=3922.0 float mapfloat(float x, float in_min, float in_max, float out_min, float out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } This is the original code of the Sensor
  4. So we are doing a project where we gonna use 3 UV sensors. I was just wondering how can we use the code more than one time? Like how can we triple it? this is the code. /* AnalogReadSerial Reads an analog input on pin A3, prints the result to the serial monitor. Attach the center pin of a potentiometer to pin A3, and the outside pins to ~3V and ground. Hardware Required: * MSP-EXP430G2 LaunchPad * 10-kilohm Potentiometer * hook-up wire This example code is in the public domain. */ // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); // msp430g2231 must use 4800 } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin A3: int sensorValue = analogRead(A1)* (3.3/4096.0); // print out the value you read: Serial.println(sensorValue); delay(1); // delay in between reads for stability }
×
×
  • Create New...