Thread: Water level sensor

  1. #31
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Posts
    210
    Is all this code in one file...?
    it's ironic considerate rarity patron of love higher knowledge engulfs me...

  2. #32
    Registered User
    Join Date
    Jun 2011
    Posts
    33
    ya its in two different file. The first part is the water level sensor detector which is in the access point .
    Code:
    #include "msp430x22x4.h"
    #include "mrfi.h"
    #define MRFI_RADIO_FAMILY1
    int count=0;
    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;
      BSP_Init();
      MRFI_Init();//initalize 6 pin wire connection between cc2500 & msp430
      MRFI_WakeUp();//wakes radio up
      MRFI_RxOn();//turn radio into receiving mode
      TACCTL0 = CCIE; 
      TACCR0 = 37500; 
      TACTL = TASSEL_2 + MC_1 + ID_3;
      P1DIR |= 0x03; // P1DIR = P1DIR | 0x03 Set P1.0, P1.1 to output direction
      P1OUT &= ~0x03;
      __bis_SR_register(GIE);
      for (;;)
      {
        if(count>=0&&count<=15)
        {
          TACCR0 =37500; // Delay to allow Ref to settle
          TACCTL0 |= CCIE; // Compare-mode interrupt.
          ADC10CTL0 = SREF_0 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;//using Vcc and gnd for reference, 64 clks/sample, turn ADC on and enable interrupts
          ADC10CTL1 = INCH_0;
          ADC10AE0 |= 0x01;
          ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
          __bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
          if (ADC10MEM <0x50)
          {
            P1OUT |= 0x01; 
            P1OUT &= ~0x02;
            mrfiPacket_t packet;
            packet.frame[9]=' ';
            packet.frame[0]=8+20;
            packet.frame[9]='A';
            MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
          }
          else if (ADC10MEM > 0x50)
          {
            P1OUT |= 0x02; 
            P1OUT &= ~0x01;
            mrfiPacket_t packet;
            packet.frame[9]=' ';
            packet.frame[0]=8+20;
            packet.frame[9]='X';
            MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
          }
          ADC10CTL0 &= ~ENC; // Clear ENC to stop conversion
          ADC10CTL0 = 0;
        }
        else if(count>=16&&count<=30)
        {
          TACCR0 = 37500; // Delay to allow Ref to settle
          TACCTL0 |= CCIE; // Compare-mode interrupt.
          ADC10CTL0 = SREF_0 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;//using Vcc and gnd for reference, 64 clks/sample, turn ADC on and enable interrupts
          ADC10CTL1 = INCH_1;
          ADC10AE0 |= 0x02;
          ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
          __bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
          ADC10AE0 |= 0x02; // P2.1 ADC option select   
          if (ADC10MEM <0x50) 
          {
            P1OUT |= 0x01; 
            P1OUT &= ~0x02;
            mrfiPacket_t packet;
            packet.frame[9]=' ';
            packet.frame[0]=8+20;
            packet.frame[9]='W';
            MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
          }
          else if (ADC10MEM > 0x50)
          {
            P1OUT |= 0x02; 
            P1OUT &= ~0x01;
            mrfiPacket_t packet;
            packet.frame[9]=' ';
            packet.frame[0]=8+20;
            packet.frame[9]='Y';
            MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
          }
          ADC10CTL0 &= ~ENC; // Clear ENC to stop conversion
          ADC10CTL0 = 0;
        }
        else if(count>=31&&count<=45)
        {
          TACCR0 = 37500; // Delay to allow Ref to settle
          TACCTL0 |= CCIE; // Compare-mode interrupt.
          ADC10CTL0 = SREF_0 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;//using Vcc and gnd for reference, 64 clks/sample, turn ADC on and enable interrupts
          ADC10CTL1 = INCH_2;
          ADC10AE0 |= 0x04;
          ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
          __bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
          ADC10AE0 |= 0x04; // P2.2 ADC option select
          if (ADC10MEM <0x50) 
          {
            P1OUT |= 0x01; 
            P1OUT &= ~0x02;
            mrfiPacket_t packet;
            packet.frame[9]=' ';
            packet.frame[0]=8+20;
            packet.frame[9]='E';
            MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
          }
          else if (ADC10MEM > 0x50)
          {
            P1OUT |= 0x02; 
            P1OUT &= ~0x01;
            mrfiPacket_t packet;
            packet.frame[9]=' ';
            packet.frame[0]=8+20;
            packet.frame[9]='Z';
            MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
          }
          ADC10CTL0 &= ~ENC; // Clear ENC to stop conversion
          ADC10CTL0 = 0;
        }
      }
    }
    #pragma vector=ADC10_VECTOR
    __interrupt void ADC10_ISR(void)
    {
      __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
    }
    #pragma vector=TIMERA0_VECTOR 
    __interrupt void Timer_A (void)
    {
      if (count == 45)
      {
        count = 1;
      }
      else
      {
        count++;
      }
    }
    void MRFI_RxCompleteISR()
    {
    }
    The second part is the water level sensor alarming which is in the end device.
    Code:
    #include "msp430x22x4.h"
    #include "mrfi.h"
    #define MRFI_RADIO_FAMILY1
    #define P3_set_out P2DIR |=0x01;//set Pin 3 and pin 4 to output
    #define P4_set_out P2DIR |=0x02;
    
    
    
    #define a_set_out P2DIR |=0x04;//set P2.2 output direction 
    #define b_set_out P2DIR |=0x08;//set P2.3 output direction 
    #define c_set_out P2DIR |=0x10;//set P2.4 output direction 
    #define d_set_out P4DIR |=0x08;//set P4.3 output direction 
    #define e_set_out P4DIR |=0x10;//set P4.4 output direction 
    #define f_set_out P4DIR |=0x20;//set P4.5 output direction 
    #define g_set_out P4DIR |=0x40;//set P4.6 output direction 
    
    
    #define a_on P2OUT |=0x04;
    #define a_off P2OUT &=~0x04;
    #define b_on P2OUT |=0x08;
    #define b_off P2OUT &=~0x08;
    #define c_on P2OUT |=0x10;
    #define c_off P2OUT &=~0x10;
    #define d_on P4OUT |=0x08;
    #define d_off P4OUT &=~0x08;
    #define e_on P4OUT |=0x10;
    #define e_off P4OUT &=~0x10;
    #define f_on P4OUT |=0x20;
    #define f_off P4OUT &=~0x20;
    #define g_on P4OUT |=0x40;
    #define g_off P4OUT &=~0x40;
    
    
    int num,num_1,num_2,r_1,count=0;
    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;
      BSP_Init();
      P1REN|=0x04;
      P1IE|=0x04;
      MRFI_Init();//initalize 6 pin wire connection between cc2500 & msp430
      MRFI_WakeUp();//wakes radio up
      MRFI_RxOn();//turn radio into receiving mode
      TBCTL=TBSSEL_2+MC_1+ID_3;
      TBCCTL0=CCIE;
      TBCCR0=150;
      __bis_SR_register(LPM0_bits+GIE);
      P1DIR |= 0x03; // P1DIR = P1DIR | 0x03 Set P1.0, P1.1 to output direction
      P1OUT &= ~0x03;
      /*TBCTL=TBSSEL_2+MC_1+ID_3;
      TBCCTL0=CCIE;
      TBCCR0=150;*/
      __bis_SR_register(GIE);
      for(;;)
      {
      }
    }
    void MRFI_RxCompleteISR()
    {
      mrfiPacket_t packet;
      MRFI_Receive(&packet);
      if(packet.frame[9]=='A')
      {
        P1OUT |= 0x01;
        P1OUT &=~0x02;
        P2OUT &=~0x03;
        P4DIR |=0x20;
        P4OUT |=0x20;
        packet.frame[9]=' ';
        
        a_set_out;//set P2.2->segment A as output pin
        b_set_out;//set P2.3->segment B as output pin
        c_set_out;//set P2.4->segment C as output pin
        d_set_out;//set P4.3->segment D as output pin
        e_set_out;//set P4.4->segment E as output pin
        f_set_out;//set P4.5->segment F as output pin
        g_set_out;//set P4.6->segment G as output pin
        
        num_1=(20/10);
        r_1=20%10;
        num_2=r_1/1;
        if(count>=0&&count<=4)
        {
          P2OUT &=~0x03;
          P2OUT |=0x01;
          num=num_1;
        }
        if(count>=5&&count<=10)
        {
          P2OUT &=~0x03;
          P2OUT |=0x02;
          num=num_2;
        }
        packet.frame[9]=' ';
        switch(num)
        {
        case 0:
          a_on;
          b_on;
          c_on;
          d_on;
          e_on;
          f_on;
          g_off;
          break;
        case 1:
          a_off;
          b_on;
          c_on;
          d_off;
          e_off;
          f_off;
          g_off;
          break;
        case 2:
          a_on;
          b_on;
          c_off;
          d_on;
          e_on;
          f_off;
          g_on;
          break;
        case 3:
          a_on;
          b_on;
          c_on;
          d_on;
          e_off;
          f_off;
          g_on;
          break;
        case 4:
          a_off;
          b_on;
          c_on;
          d_off;
          e_off;
          f_on;
          g_on;
          break;
        case 5:
          a_on;
          b_off;
          c_on;
          d_on;
          e_off;
          f_on;
          g_on;
          break;
    
        case 6:
          a_on;
          b_off;
          c_on;
          d_on;
          e_on;
          f_on;
          g_on;
          break;
        case 7:
          a_on;
          b_on;
          c_on;
          d_off;
          e_off;
          f_off;
          g_off;
          break;
        case 8:
          a_on;
          b_on;
          c_on;
          d_on;
          e_on;
          f_on;
          g_on;
          break;
        case 9:
          a_on;
          b_on;
          c_on;
          d_off;
          e_off;
          f_on;
          g_on;
          break;
        }
      }
      else if(packet.frame[9]=='W')
      {
        P1OUT &= ~0x01;
        P1OUT |= 0x02;
        P2OUT &=~0x03;
        P4DIR |=0x20;
        P4DIR |=0x40;
        P4OUT |=0x20;
        P4OUT |=0x40;
        packet.frame[9]=' ';
        
        a_set_out;//set P2.2->segment A as output pin
        b_set_out;//set P2.3->segment B as output pin
        c_set_out;//set P2.4->segment C as output pin
        d_set_out;//set P4.3->segment D as output pin
        e_set_out;//set P4.4->segment E as output pin
        f_set_out;//set P4.5->segment F as output pin
        g_set_out;//set P4.6->segment G as output pin
        
        num_1=(10/10);
        r_1=10%10;
        num_2=r_1/1;
        if(count>=0&&count<=4)
        {
          P2OUT &=~0x03;
          P2OUT |=0x01;
          num=num_1;
        }
        if(count>=5&&count<=10)
        {
          P2OUT &=~0x03;
          P2OUT |=0x02;
          num=num_2;
        }
        packet.frame[9]=' ';
        switch(num)
        {
        case 0:
          a_on;
          b_on;
          c_on;
          d_on;
          e_on;
          f_on;
          g_off;
          break;
        case 1:
          a_off;
          b_on;
          c_on;
          d_off;
          e_off;
          f_off;
          g_off;
          break;
        case 2:
          a_on;
          b_on;
          c_off;
          d_on;
          e_on;
          f_off;
          g_on;
          break;
        case 3:
          a_on;
          b_on;
          c_on;
          d_on;
          e_off;
          f_off;
          g_on;
          break;
        case 4:
          a_off;
          b_on;
          c_on;
          d_off;
          e_off;
          f_on;
          g_on;
          break;
        case 5:
          a_on;
          b_off;
          c_on;
          d_on;
          e_off;
          f_on;
          g_on;
          break;
    
        case 6:
          a_on;
          b_off;
          c_on;
          d_on;
          e_on;
          f_on;
          g_on;
          break;
        case 7:
          a_on;
          b_on;
          c_on;
          d_off;
          e_off;
          f_off;
          g_off;
          break;
        case 8:
          a_on;
          b_on;
          c_on;
          d_on;
          e_on;
          f_on;
          g_on;
          break;
        case 9:
          a_on;
          b_on;
          c_on;
          d_off;
          e_off;
          f_on;
          g_on;
          break;
        }
      }
    
      else if(packet.frame[9]=='E')
      {
        P1OUT |= 0x01;
        P1OUT |= 0x02;
        P4DIR |=0x20;
        P4DIR |=0x40;
        P4OUT |=0x20;
        P4OUT |=0x40;
        P3_set_out;
        P4_set_out;
        
        a_set_out;//set P2.2->segment A as output pin
        b_set_out;//set P2.3->segment B as output pin
        c_set_out;//set P2.4->segment C as output pin
        d_set_out;//set P4.3->segment D as output pin
        e_set_out;//set P4.4->segment E as output pin
        f_set_out;//set P4.5->segment F as output pin
        g_set_out;//set P4.6->segment G as output pin
        
        num_1=(30/10);
        r_1=30%10;
        num_2=r_1/1;
        if(count>=0&&count<=4)
        {
          P2OUT &=~0x03;
          P2OUT |=0x01;
          num=num_1;
        }
        if(count>=5&&count<=10)
        {
          P2OUT &=~0x03;
          P2OUT |=0x02;
          num=num_2;
        }
        packet.frame[9]=' ';
        switch(num)
        {
        case 0:
          a_on;
          b_on;
          c_on;
          d_on;
          e_on;
          f_on;
          g_off;
          break;
        case 1:
          a_off;
          b_on;
          c_on;
          d_off;
          e_off;
          f_off;
          g_off;
          break;
        case 2:
          a_on;
          b_on;
          c_off;
          d_on;
          e_on;
          f_off;
          g_on;
          break;
        case 3:
          a_on;
          b_on;
          c_on;
          d_on;
          e_off;
          f_off;
          g_on;
          break;
        case 4:
          a_off;
          b_on;
          c_on;
          d_off;
          e_off;
          f_on;
          g_on;
          break;
        case 5:
          a_on;
          b_off;
          c_on;
          d_on;
          e_off;
          f_on;
          g_on;
          break;
     
        case 6:
          a_on;
          b_off;
          c_on;
          d_on;
          e_on;
          f_on;
          g_on;
          break;
        case 7:
          a_on;
          b_on;
          c_on;
          d_off;
          e_off;
          f_off;
          g_off;
          break;
        case 8:
          a_on;
          b_on;
          c_on;
          d_on;
          e_on;
          f_on;
          g_on;
          break;
        case 9:
          a_on;
          b_on;
          c_on;
          d_off;
          e_off;
          f_on;
          g_on;
          break;
        }
      }
       
     
      else if(packet.frame[9]=='X')
      {
        //P1OUT |= 0x02;
        P1OUT &=~0x01;
        P4OUT &=~0x20;
        P4OUT &=~0x40;
        packet.frame[9]=' ';
      }
      else if(packet.frame[9]=='Y')
      {
        //P1OUT |= 0x02;
        P1OUT &=~0x01;
        P4OUT &=~0x20;
        P4OUT &=~0x40;
        packet.frame[9]=' ';
      }
      else if(packet.frame[9]=='Z')
      {
        //P1OUT |= 0x02;
        P1OUT &=~0x01;
        P4OUT &=~0x20;
        P4OUT &=~0x40;
        packet.frame[9]=' ';
      }
    }
    #pragma vector =PORT1_VECTOR 
    __interrupt void Port_1(void)
    {
      P1IFG&=~0x04;
      //BUZZER
    }
    #pragma vector=TIMERB0_VECTOR 
    __interrupt void TB0_ISR(void)
    {
      if (count == 10)
      { 
        count = 0;
      }
      else
      {
        count++;
      }
    }

  3. #33
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Posts
    210
    Yeah, I worked that out a bit later.

    Did you try my code from post #29?
    it's ironic considerate rarity patron of love higher knowledge engulfs me...

  4. #34
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by bivhitscar View Post
    Yeah, I worked that out a bit later.

    Did you try my code from post #29?
    Of course he didn't. Everything is exactly the same in his last two posts. He's not listening to anything anyone says. He just wants it done for him.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #35
    Registered User
    Join Date
    Jun 2011
    Posts
    33
    hey pls quzah can you stop it. If you do not want to help , pls u can just to do your own work.Don complain about others effort. I am trying out what bivhitscar state in #29.

  6. #36
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Aneesha View Post
    pls u can just to do your own work.
    That is hilarious.
    Quote Originally Posted by Aneesha View Post
    Don complain about others effort.
    What effort?
    Quote Originally Posted by Aneesha View Post
    I am trying out what bivhitscar state in #29.
    No you aren't. I ran a diff on your two last codes you've shown, and they are identical. I'm sure if I looked at the first one, that would be the same too.


    Quzah.
    Last edited by quzah; 06-22-2011 at 07:49 PM.
    Hope is the first step on the road to disappointment.

  7. #37
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So look at your code on the sensor. So far as I can tell you send 15 time units of 'A', then 15 time units of 'W', then 15 time units of 'E' -- since the distinction is based on count, which as far as I can tell is just your timer. Perhaps you should be checking your ADC10MEM instead? (Or at least checking for something other than 80.)

  8. #38
    Registered User
    Join Date
    Jun 2011
    Posts
    33
    bivhitscar: I just tried out code from post #29. But its not working. It does not show anything when it reaches 10cm in 7 segment.

  9. #39
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Posts
    210
    I agree with tabstop, I'm pretty sure the problem is in the transmitter side.
    it's ironic considerate rarity patron of love higher knowledge engulfs me...

  10. #40
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Code:
    #define P3_set_out P2DIR |=0x01;//set Pin 3 and pin 4 to output
    #define P4_set_out P2DIR |=0x02;
    This code enables what I think is the 7 segments digit control pins;
    You only do this for "E".
    Code:
        P3_set_out;
        P4_set_out;
    My best guess of all the output pins
    Code:
    Water level sensor output pins
        P1.0    Led
        P1.1    Led
        P2.0    Select 7 Segment Tens Digit
        P2.1    Select 7 Segment Ones Digit 
        P2.2    segment A
        P2.3    segment B
        P2.4    segment C
        
        P4.3    segment D
        P4.4    segment E
        P4.5    segment F
        P4.6    segment G
    Tim S.
    Last edited by stahta01; 06-22-2011 at 08:18 PM.

  11. #41
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Posts
    210
    Quote Originally Posted by stahta01 View Post
    This code enables what I think is the 7 segments digit control pins;
    You only do this for "E".
    Code:
        P3_set_out;
        P4_set_out;
    Pretty sure that's the buzzer.
    it's ironic considerate rarity patron of love higher knowledge engulfs me...

  12. #42
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by bivhitscar View Post
    Pretty sure that's the buzzer.
    I think not because of below code; implies P2.0 and P2.1 has to do with high and low digits
    Code:
        num_1=(30/10);
        r_1=30%10;
        num_2=r_1/1;
        if(count>=0&&count<=4)
        {
          P2OUT &=~0x03;
          P2OUT |=0x01;
          num=num_1;
        }
        if(count>=5&&count<=10)
        {
          P2OUT &=~0x03;
          P2OUT |=0x02;
          num=num_2;
        }

  13. #43
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Right -- they get set in those statements, so setting them (or not) above doesn't do a great deal one way or the other.

    EDIT: Oh right, OUT and DIR are not the same thing, as pointed out below. What I'd really like to see is "where is the test for >30" (or 20, or 10) -- maybe that's what INCH_0 and INCH_1 and INCH_2 are supposed to represent, although why you can only have 30 during the first 15 ms (or whatever) and only 20 during the next, I don't know.
    Last edited by tabstop; 06-22-2011 at 08:33 PM.

  14. #44
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Posts
    210
    Well, P2OUT and P2DIR are different statements. Either way, the OP has a fairly considerable problem with the logic in the transmitter.
    it's ironic considerate rarity patron of love higher knowledge engulfs me...

  15. #45
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by bivhitscar View Post
    Well, P2OUT and P2DIR are different statements. Either way, the OP has a fairly considerable problem with the logic in the transmitter.
    I have not looked at the transmitter code(detector); just the receiver code (alarming). The receiver code needs a lot of work, too.

    Tim S.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SRF02 ultrasonic sensor
    By quachtinh in forum C Programming
    Replies: 1
    Last Post: 11-13-2009, 06:51 AM
  2. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 10:13 AM
  3. Creating a array sensor
    By mikeprogram in forum C++ Programming
    Replies: 1
    Last Post: 12-01-2005, 05:44 PM
  4. OS sensor
    By Queatrix in forum Windows Programming
    Replies: 1
    Last Post: 07-11-2005, 07:00 PM