CrazyEngineers
  • Configuring adc of tms470r1b1m controller

    resmyanand

    resmyanand

    @resmyanand-HFRA4d
    Updated: Oct 11, 2024
    Views: 1.1K
    im using #-Link-Snipped-# controller for my project.i need an ADC for processing the analog input.
    in iar workbench,i had configured the registers but the code is not working.
    code is given below.plz give me a solution..........
    #include <intrinsics.h>
    #include "iotms470r1b1m.h"
    #include "tms470r1b1m_bit_definitions.h"
    #include <stdio.h>
    
    void main(void)
    {
      int result;
      PCR = CLKDIV_3;                         // ICLK = SYSCLK / 3
      GCR = ZPLL_CLK_DIV_PRE_1;               // SYSCLK = 8 x fOSC
      PCR = PENABLE;                         // Enable peripherals
    
    
      PLR = (PLOC3&0);                      //peripheral selects, The peripheral is internal
      PPROT = (PPROT3&0);             // peripheral selects,The peripheral is accessible in all modes
      CLKCNTL = 0x00000020;
      
    
      ADCR1 = PS_8;                          // ADCLK prescaler = 8
      ADCR1 = COS; 
      ADCR2 |= G1_MODE;                       // Continuous Conversion
      ADSR =0x0000;                    // Clears flag 
      ADEISR=0x0000;    // event disabled
      ADISR1 = 0x0020;   // Convert group 1 = channel 5
      ADISR2 = 0x0000;  //grp2 disabled
      ADCALR = 0x000;    //no Calibration
      ADSAMPEV = SEN;                        // ADCSAMP1 controls SW
      ADSAMP1 = 62;                           // SW = 62+2
      ADCR1 = ADC_EN;                        // Enable ADC
      
      
      for (;;)
      {
        
       while (!GP1_END);             // Wait for conversion to complete
       {
       }
        result = ADDR5;
        printf("RESULT is %d",result);
        ADSR =0x0000;  
      
      }
    }
    when this code is executed in iar workbench, the ADC is not activated nor does it sets GP1_END bit to indicate the completion signal.hence the code never exits from the while loop.here input is given to channel 5.i couldn't identify the problem..
    plz give me a solution.............
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Harshad Italiya

    MemberOct 12, 2010

    Have you tried a sample code given on the TI site?

    i had used ADC but it was on MSP series controller.
    Are you sure? This action cannot be undone.
    Cancel
  • resmyanand

    MemberOct 17, 2010

    yes i tried the code...but its not working because the device is not selected
    Are you sure? This action cannot be undone.
    Cancel
  • shreyasm89

    MemberOct 17, 2010

    Your 2nd error is because ADC isn't activated(obviously!)Also are you sure that the 'for' loop condition shouldn't have a bracket ending?Have you eliminated all syntactical errors?Also you have rewritten the value in ADCR1 twice in successive instructions. How come?
    Are you sure? This action cannot be undone.
    Cancel
  • resmyanand

    MemberOct 18, 2010

    shreyasm89
    Your 2nd error is because ADC isn't activated(obviously!)Also are you sure that the 'for' loop condition shouldn't have a bracket ending?Have you eliminated all syntactical errors?Also you have rewritten the value in ADCR1 twice in successive instructions. How come?


    it is for(;😉 unconditional for loop.there was no syntax error.
    i need ADCR1 to set -
    -COS(BIT15),CONTINUE ON SUSPEND ENABLE to continue channel conversion till completion when suspend mode is entered,
    -ADCEN(BIT5)to enable the ADC and
    -3 prescalar bits(bits 2,1,0).
    For this i had set ADCR1=8027 instead of the successive instructions.
    but the problem persists.....
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register