Loading ...
Sorry, an error occurred while loading the content.
 

at91sam7x ADC polling

Expand Messages
  • karthik
    Hello All, I am attempting to write a simple adc polling function (the atmel examples use interrupts which I don t want to use), and it s not working. Here s
    Message 1 of 3 , Oct 10, 2011
      Hello All,

      I am attempting to write a simple adc polling function (the atmel examples use interrupts which I don't want to use), and it's not working. Here's essentially what I am doing

      <code>
      uint32 adc_get_data(uint32 channel)
      {
      uint32 data;
      ADC_EnableChannel(AT91C_BASE_ADC, channel);
      ADC_StartConversion(AT91C_BASE_ADC);
      while((adc->ADC_SR & (1 << channel)) != (1 << channel)); // wait for conv to finish

      data = ADC_GetConvertedData(AT91C_BASE_ADC, channel);
      ADC_DisableChannel(AT91C_BASE_ADC, channel);
      return data;
      }

      int main()
      {
      /** all inits and configs **/
      while(TRUE)
      {
      data = adc_get_data(ADC_CHANNEL_5);
      printf("%d\n\r", data); // serial dbgu port configured
      }
      }

      </code>

      However, on the serial port, I'm reading all zeros. what am I doing wrong?

      I appreciate your help!
    • S Santoshi Singh ssantoshi
      Hi Karthik, After ADC initialization , please check whether your pio s are configured in input mode or not. -- Original Message -- From: karthik
      Message 2 of 3 , Oct 10, 2011
        Hi Karthik,

        After ADC initialization , please check whether your pio's are configured in input mode or not.

        -- Original Message --
        From: "karthik" <karthik.m.bharadwaj@...>
        To: AT91SAM@yahoogroups.com
        Date: Mon, 10 Oct 2011 16:21:45 -0000
        Subject: [AT91SAM] at91sam7x ADC polling

        Hello All,

        I am attempting to write a simple adc polling function (the atmel examples use interrupts which I don't want to use), and it's not working. Here's essentially what I am doing

        <code>
        uint32 adc_get_data(uint32 channel)
        {
        uint32 data;
        ADC_EnableChannel(AT91C_BASE_ADC, channel);
        ADC_StartConversion(AT91C_BASE_ADC);
        while((adc->ADC_SR & (1 << channel)) != (1 << channel)); // wait for conv to finish

        data = ADC_GetConvertedData(AT91C_BASE_ADC, channel);
        ADC_DisableChannel(AT91C_BASE_ADC, channel);
        return data;
        }

        int main()
        {
        /** all inits and configs **/
        while(TRUE)
        {
        data = adc_get_data(ADC_CHANNEL_5);
        printf("%d\n\r", data); // serial dbgu port configured
        }
        }

        </code>

        However, on the serial port, I'm reading all zeros. what am I doing wrong?

        I appreciate your help!


        ::DISCLAIMER::
        -----------------------------------------------------------------------------------------------
        
        The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
        It shall not attach any liability on the originator or ECIL or its affiliates. Any views or opinions presented in
        this email are solely those of the author and may not necessarily reflect the opinions of ECIL or its affiliates.
        Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of
        this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have
        received this email in error please delete it and notify the sender immediately. Before opening any mail and
        attachments please check them for viruses and defect.
        
        THIS MAIL IS SCANNED BY ECIL IMSS FOR VIRUS AND SPAMS.
        ::DISCLAIMER::
        -----------------------------------------------------------------------------------------------
        
        The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
        It shall not attach any liability on the originator or ECIL or its affiliates. Any views or opinions presented in
        this email are solely those of the author and may not necessarily reflect the opinions of ECIL or its affiliates.
        Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of
        this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have
        received this email in error please delete it and notify the sender immediately. Before opening any mail and
        attachments please check them for viruses and defect.
        
        THIS MAIL IS SCANNED BY ECIL IMSS FOR VIRUS AND SPAMS.
      • S Santoshi Singh ssantoshi
        Hi Karthik, After ADC initialization , please check whether your pio s are configured in input mode or not. -- Original Message -- From: karthik
        Message 3 of 3 , Oct 10, 2011
          Hi Karthik,

          After ADC initialization , please check whether your pio's are configured in input mode or not.

          -- Original Message --
          From: "karthik" <karthik.m.bharadwaj@...>
          To: AT91SAM@yahoogroups.com
          Date: Mon, 10 Oct 2011 16:21:45 -0000
          Subject: [AT91SAM] at91sam7x ADC polling

          Hello All,

          I am attempting to write a simple adc polling function (the atmel examples use interrupts which I don't want to use), and it's not working. Here's essentially what I am doing

          <code>
          uint32 adc_get_data(uint32 channel)
          {
          uint32 data;
          ADC_EnableChannel(AT91C_BASE_ADC, channel);
          ADC_StartConversion(AT91C_BASE_ADC);
          while((adc->ADC_SR & (1 << channel)) != (1 << channel)); // wait for conv to finish

          data = ADC_GetConvertedData(AT91C_BASE_ADC, channel);
          ADC_DisableChannel(AT91C_BASE_ADC, channel);
          return data;
          }

          int main()
          {
          /** all inits and configs **/
          while(TRUE)
          {
          data = adc_get_data(ADC_CHANNEL_5);
          printf("%d\n\r", data); // serial dbgu port configured
          }
          }

          </code>

          However, on the serial port, I'm reading all zeros. what am I doing wrong?

          I appreciate your help!


          ::DISCLAIMER::
          -----------------------------------------------------------------------------------------------
          
          The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
          It shall not attach any liability on the originator or ECIL or its affiliates. Any views or opinions presented in
          this email are solely those of the author and may not necessarily reflect the opinions of ECIL or its affiliates.
          Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of
          this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have
          received this email in error please delete it and notify the sender immediately. Before opening any mail and
          attachments please check them for viruses and defect.
          
          THIS MAIL IS SCANNED BY ECIL IMSS FOR VIRUS AND SPAMS.
          ::DISCLAIMER::
          -----------------------------------------------------------------------------------------------
          
          The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
          It shall not attach any liability on the originator or ECIL or its affiliates. Any views or opinions presented in
          this email are solely those of the author and may not necessarily reflect the opinions of ECIL or its affiliates.
          Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of
          this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have
          received this email in error please delete it and notify the sender immediately. Before opening any mail and
          attachments please check them for viruses and defect.
          
          THIS MAIL IS SCANNED BY ECIL IMSS FOR VIRUS AND SPAMS.
        Your message has been successfully submitted and would be delivered to recipients shortly.