• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Microcontrollers » C2000™ Microcontrollers » C2000 32-bit Microcontrollers Forum » Need help in setting the GPIO pins for generating a pulse
Share
C2000™ Microcontrollers
  • Forums
  • Announcements
  • E2E Wiki
Options
  • Subscribe via RSS
C2000 Resources
  • Product Folder
  • C2000 Training Portal
  • C2000 Technical Training Catalog
  • C2000 Datasheets, App Notes, User Guides
  • C2000 Hardware Design Kits
  • controlSUITE for C2000 Software Library


  • InstaSPIN Resources
  • What is InstaSPIN?
  • Videos and Support


  • InstaSPIN-FOC and InstaSPIN-MOTION Resources
  • What is InstaSPIN-FOC?
  • What is InstaSPIN-MOTION?
  • Product Folder: F28069F, F28068F, F28062F, F28068M, F28069M
  • User’s Guide
  • Technical User’s Manual
  • Tools
  • Forums

    Need help in setting the GPIO pins for generating a pulse

    This question has suggested answer(s)
    Jaya Balakrishnan102264
    Posted by Jaya Balakrishnan102264
    on Apr 11 2012 09:01 AM
    Prodigy70 points

    Hai,

       I am working on TMS320F28335. I need to generate a pulse when the sampled value through ADC is less than a specified value. Following is the piece of code I am trying to use. Kindly help me in getting the proper output.

    #include "DSP2833x_Device.h"

    extern void InitAdc(void);
    extern void InitSysCtrl(void);
    extern void InitPieCtrl(void);
    extern void InitPieVectTable(void);

    void Gpio_select(void);

    #define AVG        100  // Average sample limit
    #define BUF_SIZE   100  // Sample buffer size

    Uint16 SampleTable1[BUF_SIZE];

    float Output1[BUF_SIZE];

    void main(void)
    {
           Uint16 i;
             
        InitSysCtrl();    // Basic Core Init from DSP2833x_SysCtrl.c  
          DINT;                // Disable all interrupts    
          Gpio_select();        // GPIO9, GPIO11, GPIO34 and GPIO49 as output
                            // to 4 LEDs at Peripheral Explorer)
        InitPieCtrl();        // basic setup of PIE table; from DSP2833x_PieCtrl.c
            
        // Disable CPU interrupts and clear all CPU interrupt flags:
           IER = 0x0000;
           IFR = 0x0000;
        
        InitPieVectTable();    // default ISR's in PIE

        InitAdc();            // Basic ADC setup, incl. calibration
        
        AdcRegs.ADCTRL1.all = 0;       
        AdcRegs.ADCTRL1.bit.ACQ_PS = 7;     // 7 = 8 x ADCCLK    
        AdcRegs.ADCTRL1.bit.SEQ_CASC =1;     // 1=cascaded sequencer
        AdcRegs.ADCTRL1.bit.CPS = 1;        // divide by 2
        AdcRegs.ADCTRL1.bit.CONT_RUN = 1;    // Continous run mode
        
        AdcRegs.ADCTRL2.all = 0;            
        AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1;    // 1=Software trigger
        AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 =0;    // 0=SEQ1 cannot be started by ePWMx SOCA trigger.
        AdcRegs.ADCTRL2.bit.INT_MOD_SEQ1 = 0;    // 0= interrupt after every end of sequence
        
        AdcRegs.ADCTRL3.bit.ADCCLKPS = 3;    // ADC clock: FCLK = HSPCLK / 2 * ADCCLKPS

        AdcRegs.ADCMAXCONV.all = 0x0000;   
        AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0;
       
           
           for (i=0; i<AVG; i++)
         {
            while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // Wait for interrupt
            AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
            SampleTable1[i] =((AdcRegs.ADCRESULT0>>4) );
         
             if(SampleTable1[i]<685)
            { 
                GpioDataRegs.GPASET.bit.GPIO12 = 1;
            }
            else
            {           
                GpioDataRegs.GPASET.bit.GPIO12 = 0;
            }
            }  
           
         }
     
    void Gpio_select(void)
    {
        EALLOW;
        GpioCtrlRegs.GPAMUX1.all = 0;        // GPIO15 ... GPIO0 = General Puropse I/O
        GpioCtrlRegs.GPAMUX2.all = 0;        // GPIO31 ... GPIO16 = General Purpose I/O
        GpioCtrlRegs.GPBMUX1.all = 0;        // GPIO47 ... GPIO32 = General Purpose I/O
        GpioCtrlRegs.GPBMUX2.all = 0;        // GPIO63 ... GPIO48 = General Purpose I/O
        GpioCtrlRegs.GPCMUX1.all = 0;        // GPIO79 ... GPIO64 = General Purpose I/O
        GpioCtrlRegs.GPCMUX2.all = 0;        // GPIO87 ... GPIO80 = General Purpose I/O
        
        GpioCtrlRegs.GPADIR.all = 0;
            
        GpioCtrlRegs.GPBDIR.all = 0;        // GPIO63-32 as inputs

        GpioCtrlRegs.GPCDIR.all = 0;        
     
        GpioCtrlRegs.GPAMUX1.bit.GPIO12= 0; 
         GpioCtrlRegs.GPADIR.bit.GPIO12 = 1;  
     
        
           
        EDIS;
        
    }


    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • Trey German
      Posted by Trey German
      on Apr 11 2012 09:28 AM
      Genius14470 points

      Jaya,

      Your code looks good for the most part.  What exactly isn't working?


      Trey

      Trey German

      C2000 Applications

      If a post answers your question, please mark it with the "verify answer" button.
      Visit these helpful C2000 Links!
      C2000 TI Wiki Pages
      TI Forum Sitemap
      ControlSUITE
      C2000 Getting Started
      CLA FAQs
      Workshop Material!
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jaya Balakrishnan102264
      Posted by Jaya Balakrishnan102264
      on Apr 11 2012 12:08 PM
      Prodigy70 points

      Trey,

         I want to see the output using a DSO or CRO. When I try that, I am not getting any wave instead I am getting some signal which looks like some noise. Is the code what I have written  is sufficient to generate a square wave?

      if(SampleTable1[i]<685)
              {
                  GpioDataRegs.GPASET.bit.GPIO12 = 1;
              }
              else
              {
                  GpioDataRegs.GPASET.bit.GPIO12 = 0;
              }
             
      Now if I take output from GPIO pin number 12 will I get a proper signal?

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Trey German
      Posted by Trey German
      on Apr 11 2012 12:33 PM
      Genius14470 points

      Jaya,

      Ooops, when I looked at your code earlier it didn't click that you are using the set register.  The set register can only be used to set the pin.  Instead I think you want to use the dat register which can be used to set or clear the pin.

      You shouldn't ever really see noise on a pin (other than thermal noise).  How big is the voltage swing on the noise?  If its a few millivolts, this is nothing to worry about, but if its bigger than a volt something very wrong is happening.

      Trey

      Trey German

      C2000 Applications

      If a post answers your question, please mark it with the "verify answer" button.
      Visit these helpful C2000 Links!
      C2000 TI Wiki Pages
      TI Forum Sitemap
      ControlSUITE
      C2000 Getting Started
      CLA FAQs
      Workshop Material!
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jaya Balakrishnan102264
      Posted by Jaya Balakrishnan102264
      on Apr 11 2012 22:48 PM
      Prodigy70 points

      Trey,

          Thanks for the quick reply. I think The noise signals what I am getting is similar to what you have mentioned. It is coming in millivolts only. So as per your view, I can ignore that. But my actual issue is how can I get a proper signal Will the code I mentioned is sufficient enough to get a proper signal which I can view through a DSO or CRO?

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jaya Balakrishnan102264
      Posted by Jaya Balakrishnan102264
      on Apr 11 2012 22:48 PM
      Prodigy70 points

      Trey,

          Thanks for the quick reply. I think The noise signals what I am getting is similar to what you have mentioned. It is coming in millivolts only. So as per your view, I can ignore that. But my actual issue is how can I get a proper signal Will the code I mentioned is sufficient enough to get a proper signal which I can view through a DSO or CRO?

      I replaced my code where I am using the SET bit with DAT bit. 

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Trey German
      Posted by Trey German
      on Apr 12 2012 07:45 AM
      Genius14470 points

      Jaya,

      Did it start working when you changed the code to use the "DAT" bit?  If not, is execution making its way into the "IF" statement where you change the pin state?  If not, then why is that happening?  You may have to do some debug work here.  Just walk through your code and see what is happening.  If something specific isn't happening as expected, try to figure out why.

      Trey

      Trey German

      C2000 Applications

      If a post answers your question, please mark it with the "verify answer" button.
      Visit these helpful C2000 Links!
      C2000 TI Wiki Pages
      TI Forum Sitemap
      ControlSUITE
      C2000 Getting Started
      CLA FAQs
      Workshop Material!
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jaya Balakrishnan102264
      Posted by Jaya Balakrishnan102264
      on Apr 29 2012 12:23 PM
      Prodigy70 points

      Hai Trey,

      I did as you have suggested. ie to use DAT in place of SET. Below is the code I am using, but still I am not getting proper pulses.

      if((SampleTable1[i-1]==0)&&(SampleTable1[i]<0))
              
              {
                  GpioDataRegs.GPASET.bit.GPIO9 = 1;
                 
              }
              else
              {
                  GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;
               
              }

      My idea is to do Zero Crossing Detector. When ever sampled signal does ZCD, I want to generate pulse. Please guide me in completing this. Another point I would like to clarify is whether I can control the sampling rate any way? If I need only 60 samples per cycle, what should be my code?

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Trey German
      Posted by Trey German
      on Apr 30 2012 08:26 AM
      Suggested Answer
      Genius14470 points

      Jaya,

       That code should toggle the pin, so there must be something else going on.  Are you sure the GPIO registers are getting set as you have commanded in your code?  Take a look at the GPIO register memory to ensure this is happening.  In controlSUITE we provide several examples which show how to use the GPIOs.  Take a look at these and see if there are any major differences between the examples and your code.  If you run one of the examples does it successfully toggle the pin on your board?

      I can only provide so much support.  My job is not to write your code, that being said the best way to do zero crossing detection is with one of the on chip comparators.  This will give you an instantaneous indication that zero crossing has occurred.  You could also potentially use an external interrupt.  There are examples of both of these in controlsuite.  Read the user guides for these peripherals.

      Yes you can control the sample rate.  I would use a timer to generate an interrupt at the sample rate you desire and force a start of conversion in the timer interrupt service routine.  Once again, I cannot write this code for you, but there is more than enough information in the user guides and examples for you to learn and write this code yourself.

      Best of luck,

      Trey German

      Trey German

      C2000 Applications

      If a post answers your question, please mark it with the "verify answer" button.
      Visit these helpful C2000 Links!
      C2000 TI Wiki Pages
      TI Forum Sitemap
      ControlSUITE
      C2000 Getting Started
      CLA FAQs
      Workshop Material!
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    TI E2E™ Community
    • Support Forums
    • Blogs
    • Videos
    • Groups
    • Site Support & Feedback
    • Settings
    TI E2E™ Community Groups
    • TI University Program
    • Make the Switch
    • Microcontroller Projects
    • Motor Drive & Control
    Other Communities
    • Deyisupport
    • Designsomething.org
    • beagleboard.org
    • TI on Element 14
    • TI on TechXchangeSM
    Other Technical & Support Resources
    • WEBENCH® Design Center
    • Product Information Centers
    • Technical Documents
    • TI Design Network
    • TI Technical Articles
    • TI Training

    All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

    Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

    Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
    TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

    TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
    embedded processors, along with software, tools and the industry’s largest sales/support staff.

    © Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
    Trademarks | Privacy Policy | Terms of Use