Jump to content

iragdoll

Members
  • Content Count

    45
  • Joined

  • Last visited

  1. Hey Guys, I need some help again. I need to read the ADC on an interrupt basis so basically when the vibration sensor is hit, it should send an interrupt to run a function. Otherwise it should stay in LPM0. Any ideas? Currently my code looks like this: #define __MSP430G2231__ #include #define PHOTOCELL BIT0 #define LED BIT6 int analogRead(unsigned int pin); void main() { volatile int val; int threshold = 45; WDTCTL = WDTPW + WDTHOLD; P1DIR |= LED; P1OUT = 0; ADC10CTL0 = ADC10ON + ADC10SHT_0 + SREF_0; for (; { val = analogRead(PHOTOCELL); if(val + 10 > threshold){ P1OUT |= LED; __delay_cycles(1000000); P1OUT &= ~LED; } } } int analogRead(unsigned int pin) { ADC10CTL1 = ADC10SSEL_2 + pin; ADC10CTL0 |= ENC + ADC10SC; while (1) { if ((ADC10CTL1 ^ ADC10BUSY) & ((ADC10CTL0 & ADC10IFG)==ADC10IFG)) { ADC10CTL0 &= ~(ADC10IFG +ENC); break; } } return ADC10MEM; }
  2. Hey Guys, Somebody probably already solved this issue and I wanted to learn. What is the best way to connect a battery to the LaunchPad? It has those 3 pins on the board. I specifically want to use a 9 volt battery and I already know how to use the voltage regulator but how do I make it look nice on connecting some sort of 3-prong cable to the power source of the board. Thanks!
  3. Okay, so right now, it looks like there is some noise issues. I have the vibration sensor connected just like this: Except I have a 3.3v zener diode. I have the transistor hooked up exactly like the schematic shown here: http://processors.wiki.ti.com/index.php ... _Drive_LED I first tested out the transistor by it self, and it works. My main problem right now is when I put this code for the vibration sensor (Please check the code if I messed up anything) #define __MSP430G2231__ #include #define PHOTOCELL BIT0 int analogRead(unsigned int pin); void main() { volatile unsigned int val; int threshold = 90; int delay; WDTCTL = WDTPW + WDTHOLD; P1DIR |= BIT6; //P1OUT = 0; ADC10CTL0 = ADC10ON + ADC10SHT_0 + SREF_0; // ACD10 on, 4 clock cycles per sample, Use Vcc/Vss references // change frequency to ~15.25mhz (DCO(15,3)) BCSCTL1 |= (BIT0 + BIT1 + BIT2 + BIT3); DCOCTL &= ~(BIT7); DCOCTL |= (BIT6 + BIT5); for (; { val = analogRead(PHOTOCELL); if(val > threshold){ P1OUT |= BIT6; delay = 0; while(delay < 1000) delay++; P1OUT &= ~BIT6; } } } int analogRead(unsigned int pin) { ADC10CTL1 = ADC10SSEL_2 + pin;// Select MCLK and pin ADC10CTL0 |= ENC + ADC10SC; // enable and start conversion while (1) { if ((ADC10CTL1 ^ ADC10BUSY) & ((ADC10CTL0 & ADC10IFG)==ADC10IFG)) { // ensure conversion is complete ADC10CTL0 &= ~(ADC10IFG +ENC); // disable conversion and clear flag break; } } return ADC10MEM; } When i get close to any ground wires, the LED starts flickering. The main goal for this project is to be able to detect vibration while comparing the value to a set threshold. If it hits that threshold, the LED must stay on for a specified amount of time. If it does not hit the threshold, the LED should stay off. The vibration sensor seems to be working because when I shake it, it blinks the LED. (Its hard to see because if you get close to a ground wire it starts blinking by itself) Thanks!
  4. I still see something messed up. When I hook up the transistor to the LED connected to P1.6, the LED does not turn off. Its very strange. Also, whenever I put my finger close to the ground wires, the LED lights up. Any ideas? NatureTM: Are you sure that the code is working the way it is? It seems like it is while turning on the on-board LED's. Also, Do I need to configure the timers on the pins in my code? I need to input a value on P1.0 and output an LED signal on P1.6. The code that I am currently using: #define __MSP430G2231__ #include #define PHOTOCELL BIT0 int analogRead(unsigned int pin); void main() { volatile unsigned int val; int threshold = 90; int delay; WDTCTL = WDTPW + WDTHOLD; P1DIR |= BIT6; //P1OUT = 0; ADC10CTL0 = ADC10ON + ADC10SHT_0 + SREF_0; // ACD10 on, 4 clock cycles per sample, Use Vcc/Vss references // change frequency to ~15.25mhz (DCO(15,3)) BCSCTL1 |= (BIT0 + BIT1 + BIT2 + BIT3); DCOCTL &= ~(BIT7); DCOCTL |= (BIT6 + BIT5); for (; { val = analogRead(PHOTOCELL); if(val > threshold){ P1OUT |= BIT6; delay = 0; while(delay < 1000) delay++; P1OUT &= ~BIT6; } } } int analogRead(unsigned int pin) { ADC10CTL1 = ADC10SSEL_2 + pin;// Select MCLK and pin ADC10CTL0 |= ENC + ADC10SC; // enable and start conversion while (1) { if ((ADC10CTL1 ^ ADC10BUSY) & ((ADC10CTL0 & ADC10IFG)==ADC10IFG)) { // ensure conversion is complete ADC10CTL0 &= ~(ADC10IFG +ENC); // disable conversion and clear flag break; } } return ADC10MEM; }
  5. Wait did you connect a Piezo Vibration Sensor to it? Yea I know it works now, thanks tho, but I am still trying to figure out how to read the Vibration Sensor... Any ideas?
  6. #define __MSP430G2231__ #include #define PHOTOCELL INCH_0 // photocell divider on P1.0/A0 int analogRead(unsigned int pin); void main() { volatile unsigned int val; WDTCTL = WDTPW + WDTHOLD; // kill wdt+ P1OUT = 0x00; ADC10CTL0 = ADC10ON + ADC10SHT_0 + SREF_0; // ACD10 on, 4 clock cycles per sample, Use Vcc/Vss references // change frequency to ~15.25mhz (DCO(15,3)) BCSCTL1 |= (BIT0 + BIT1 + BIT2 + BIT3); DCOCTL &= ~(BIT7); DCOCTL |= (BIT6 + BIT5); for (; { val = analogRead(PHOTOCELL); } } int analogRead(unsigned int pin) { ADC10CTL1 = ADC10SSEL_2 + pin;// Select MCLK and pin ADC10CTL0 |= ENC + ADC10SC; // enable and start conversion while (1) { if ((ADC10CTL1 ^ ADC10BUSY) & ((ADC10CTL0 & ADC10IFG)==ADC10IFG)) { // ensure conversion is complete ADC10CTL0 &= ~(ADC10IFG +ENC); // disable conversion and clear flag break; } } return ADC10MEM; }
  7. Wait I hope that means that you are going to help me?!?
  8. Man I dont think so... I need to get this working by tomorrow... I underestimated the complexity of MSP430 Programming. I made tons of projects with the Arduino, but the LaunchPad coding is much more confusing... Yea I know how to read it, sort of. Can you guys sort of edit the code and I will test it out and sort of guide me through it?
  9. Yea I am really confused man... I think Ill need some serious help please. Any help? The problem is I cant read the voltage levels on the Local Debug window. It keeps saying 86...
  10. Im actually having trouble reading val... once second please.
  11. Umm... 1. C 2. B As far as I know, for number two, you can constrain the values any way you want. I have seen both 0 to 255 and 0 to 1023 used.
  12. Okay, How do I know if I am reading the voltage correctly?
  13. Okay, so all I need to do is call analogRead() on the pin that I am reading the Vibration Sensor, make an if statement comparing it with a threshold, and turn on an LED if it passes it? Is the rectifier/capacitor necessary? Is it required? Oh and sorry about the two posts. I actually was in a hurry in the beginning and forgot about my previous post. Wont happen again!
×
×
  • Create New...