Like Tree24Likes

Water level sensor

This is a discussion on Water level sensor within the C Programming forums, part of the General Programming Boards category; I just amended the code and was able to see changes. Now the 7 segment can display 10 when the ...

  1. #46
    Registered User
    Join Date
    Jun 2011
    Posts
    33
    I just amended the code and was able to see changes. Now the 7 segment can display 10 when the water level reaches 10cm, 20 when the water level reaches 20cm and 30 when the water level reaches 30 cm . Now the problem is that when the water level reaches 10cm it shows 10 , when the water level reach 20cm its show 10 than 20 continously in the 7 segment. When it reaches 30cm the 7 segment shows 10 then 20 then 30 continously. How to solve this pro?

  2. #47
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    Didn't you read the thread? Tabstop explained why
    Quote Originally Posted by tabstop View Post
    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.)
    Your code doesn't make much sense..
    You have the sensor hooked up to the ADC so I'm guessing the sensor sends an analogue value for the water level.. But you aren't using that value anywhere, you are just looping over a timer interrupt that goes 1..45
    What sensor are you using?

    Edit: and wtf happened to the default font size?

  3. #48
    Registered User
    Join Date
    Jun 2011
    Posts
    33
    Can u help me on what are the changes that i have to make in order to have the correct reading accordingly. What should be the right ADC value for this? Thanks
    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 <0x30)
          {
            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 > 0x30)
          {
            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 <0x45) 
          {
            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 > 0x45)
          {
            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 <0x25) 
          {
            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 > 0x25)
          {
            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()
    {
    }

  4. #49
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Posts
    210
    The main problem is the logic, not specific values. I think you can work it out though, just read the code and modify small things to see how they effect the whole system. If we give you all the answers you won't learn anything - the best way to learn is by trying things and seeing what happens.
    it's ironic considerate rarity patron of love higher knowledge engulfs me...

  5. #50
    Registered User
    Join Date
    May 2009
    Posts
    2,683
    Analog-to-Digital Conversion for 2 Sensors

    I worked on the rcvr code just to see; If, I could understand it; no desire to work on the xmtr.
    Edit: But, posted link that helps to understand the xmtr code; decided it was generic enough that it might not be based off of it.

    Tim S.
    Last edited by stahta01; 06-23-2011 at 07:27 AM.

  6. #51
    Registered User
    Join Date
    Jun 2011
    Posts
    33
    Now i want to send SMS Using AT Commands for the EMERGENCY level of water level. I have tried Hyperterminal to send and recieve SMS. It works well. I can send and receive SMS in Hyperterminal. But Now I am not sure how to apply that in my C code on water level sensor project? The AT Code that i used for hyperterminal was

    at
    ok
    at+cmgf=1
    ok
    at+csca="+65--------"
    ok
    at+cmgs="+65--------"
    >HELLO
    Press Ctrl and Z

    Now how to Send SMS from my project?

  7. #52
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Aneesha View Post
    Now i want to send SMS Using AT Commands for the EMERGENCY level of water level. I have tried Hyperterminal to send and recieve SMS. It works well. I can send and receive SMS in Hyperterminal. But Now I am not sure how to apply that in my C code on water level sensor project? The AT Code that i used for hyperterminal was

    at
    ok
    at+cmgf=1
    ok
    at+csca="+65--------"
    ok
    at+cmgs="+65--------"
    >HELLO
    Press Ctrl and Z

    Now how to Send SMS from my project?
    Those are modem commands... open the modem's comport as a file and send them with standard C file read and write commands...

  8. #53
    Registered User
    Join Date
    Jun 2011
    Posts
    33
    Sry, how am i suppose to do that? Can u pls elaborate ? I do not understand by the phrase "open the modem's comport as a file and send them with standard C file read and write commands... ".

  9. #54
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    You can open ports just like you open files in C ... The syntax is a little different for each operating system, but the concept is the same... it's all just streams of data.

    It's been a while but I believe it's like this, for Windows...
    Code:
    comport = fopen("COM1:", "w+");

  10. #55
    Registered User
    Join Date
    Jun 2011
    Posts
    33
    comport = fopen("COM1:", "w+"); This command i need to add in the beginning or the part that the EMERGENCY level occurs? AND i still don't understand which C code am i suppose to type under the Emergency level where the water reaches 30cm.

  11. #56
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    I thought this is for embedded? Why are we talking Windows?

    Read the datasheet on how to configure and use the UART.

  12. #57
    Registered User
    Join Date
    Jun 2011
    Posts
    33
    My question is how to send SMS in C code in my project water level sensor? What is the code can be used?

  13. #58
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    Yes, you have to write the code. Read the datasheet on UART.

  14. #59
    Registered User
    Join Date
    Jun 2011
    Posts
    33
    what is that to do with my problem?

  15. #60
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    Your problem is you don't know how to write to the serial port. The datasheet tells you how.

    Or do you expect people to write the code for you?

Page 4 of 7 FirstFirst 1234567 LastLast
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, 05: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, 09:13 AM
  3. Creating a array sensor
    By mikeprogram in forum C++ Programming
    Replies: 1
    Last Post: 12-01-2005, 04:44 PM
  4. OS sensor
    By Queatrix in forum Windows Programming
    Replies: 1
    Last Post: 07-11-2005, 07:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21