This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SM470R1B1M-HT: How to detect 273KHz and 254KHz square wave input?

Part Number: SM470R1B1M-HT

Hi,

I have a square wave signal whcih can be either 273KHz or 254KHz connected to an SM470R1B1M input pin,  The frequency switches back and forth.  How do I detect the different frequency on this pin?  For instance, if it is 273KHz, I set another output pin, if it is 254KHz, I reset another output pin.

Is there an example code for that?  I am using IAR EWARM.

Thanks, Jian 

  • Jian,
    I do not have code to do exactly what you desire.
    However, the HET is well suited for this task.
    It can be used to start/stop counting when events occur on your clock. The count value can then be used to determine frequency based on your specific settings in the HET.
    There is a demo project using the HET in the IAR project examples for this device.

    If this answers your question, please click "This Resolved My Question"
    Regards,
    Wad
  • Where is demo project?

  • It can be downloaded from IAR ewarm. To download examples go the the IAR information center. It should be accessible from the "Help" drop down.

    If this answers your question, please click "This Resolved My Question"
    Regards,
    Wade
  • The demo project has pwm.het file.  The project says the .het file document can be requested from TI.  How do I create.het file?

  • The .het file is provided as part of the project.
    The Readme for the project says:
    "Documentation on the HET assembler can be requested from Texas instruments."
    See this e2e post for some additional information.
    e2e.ti.com/.../69094

    Regards,
    Wade
  • Wade,

    The .het file only has one PWM frequency for each port.  How do I switch 2 PWM frequency on the same HET pin?

    Thanks, Jian

  • Jian,
    You do not want to create a PWM frequency. You want to use the HET to count a timer between edges of your clock. This count will represent the period (or half the period depending on your start/stop conditions).
    There is not an example of exactly this for the R1B1M.

    You would likely use the PCNT instruction to trigger on rising to rising edge. During this time, the PCNT instruction will increment a counter on each timer resolution. The count between the rising edges can be read by CPU and calculate the frequency. The timer resolution will need to be high enough to distinguish between your two frequencies.

    Regards,
    Wade
  • Wade,

    I understand using a timer to count on the rising edges. How to use HET to count timer between edges of clock. Do I need to change the .het files to set HET as input pin? I don't know how to set up HET for this.

    Also I need another HET pin to output 250KHz and 270Khz square wave back and forth. I only see how to set up one frequency PWM from the demo project, so how to switch two frequencies?

    Jian
  • You can change the count value while operating to change the frequency of output.
    You can reference the HET users guide for more information. Unfortunately, there are not any elaborate examples for this generation of HET. There may be some better examples from newer generations of HETs, that may be useful to review. However, they have more capabilities than this version of the HET.
    Regards,
    Wade
  • Wade,

    Can you provide at least the psedo code on how to change the frequency of PWM output.  From what I can tell from the demo project, the frequency is set up at pwm.het.  How how to change it when condition rises( for instance, another pin changes state)?

    Thanks, Jian

  • Any answers for my previous question?  I am waiting to work on this PWM output frequency switch.

  • Any answers for my previous question? I need to work on the PWM output frequency switch.
  • Jian,

    Unfortunately, there is very little expertise on this device family left within TI.  However, I was able to locate some example code for a workshop from back in 2005.  

    Unfortunately, I do not have the workshop instructions.  

    It is not complete, but it does show how to configure and update PWM frequencies.   This should be very helpful along with the HET users guide.

    Note, this example was intended to be used with LCD screen.  These aspects can be ignored so you can evaluate HET operation only.

    Key to updating, is writing into the HET memory from the CPU.

          HET_L01_0.memory.data_word = data;

    This command will update the PWM frequency.

    Once you get PWM setup, you can write to the HET with the 2 different frequencies.

    -------------------------MAIN.c--------------------------------------
    /* TMS470 High End Timer Workshop Exercise */

    #include "gio470.h"
    #include "het470.h"     
    #include "pwm.h"

    void Read_and_update();

    #define  WAC  100000
    #define  STEP 32

    const ULONG C_PLLClkOut_UL = 15000000 * 8;   /* define PLL output clock */
                                           /* (here needed for SCI drivers) */
    unsigned int  data , count ;
    volatile unsigned int  * p;

    /***********************************************************************/
    main()
    {

      e_GIO_ST.Port_ST[2].Dir_UL = (1 <<2)  ; /* Set GIO pin C.2 to output */
             /* This is the pin, which determines to rotational direction */
     
      e_HET0_ST.gcr_UN.gcr_UL  =  
                         (1<<16) /* 1: HET is configured as a master */
                        |(1<<1)  /* 1: HET continues at breakpoint */
                        |(0<<0); /* 0: HET is stopped */
       
      Display_Reset();
      Init_LCD_HET();
     
      /* copy HET instructions to HET ram*/
      memcpy((void *) &e_HETPROGRAM0_UN, HET_INIT0_PST, sizeof(HET_INIT0_PST));
        
      e_HET0_ST.pfr_UN.pfr_UL  =  0x00000301;   /* Set PFR register    */

      e_HET0_ST.CCDir_UL       =  0x00000001;   /* Set pin directions */

      HET_L01_0.memory.data_word = 6000;   

      e_HET0_ST.gcr_UN.gcr_UL |=  0x00000001;   /* Start HET          */

      #define B30   5600   /* <-- FILL THIS */
      #define B50   4000   /* <-- FILL THIS */
     
       
    #if 1 /*---------------------------------------------------*/          
         
      for(count=0;count<2;count++) {
     
        for(data=B30 ; data >= B50; data-= STEP)  /* from 30 % to 50 % */
        {
          HET_L01_0.memory.data_word = data;

          Read_and_update();
          Wait(WAC);
        }
        
        for(data=B50; data <= B30; data+= STEP)   /* from 50 % to 30 % */
        {
          HET_L01_0.memory.data_word = data;

          Read_and_update();
          Wait(WAC);
        }
      }    
      HET_L01_0.memory.data_word = 0x01FFFFFF;
        
    #else /*---------------------------------------------------*/    

      p = &  (HET_L01_0.memory.data_word);
     
    #endif /*---------------------------------------------------*/
     
      for(;;)
      {
        Read_and_update();
        Wait(0x8FFFF);
      }
    }
    /***********************************************************************/
    void Read_and_update()
    {
       unsigned int pulsewidth, pcnt, n_rpm, direction;
       signed   int dc;

       /* read out PWM compare value and calculate duty cycle */
       pulsewidth = HET_L01_0.memory.data_word;
       dc = (100-100*pulsewidth/8000);    /* Note: 8000= 250<<5 */
       if (dc < 0) dc=0;
         
       /* read out period from toothed wheel speed sensor */
       /* i.e. read out PCNT data field (and control field)  */
       if((HET_L04_0.memory.control_word & 0xFFFFF)==0xFFFFF) /* for rpm=0 */
           pcnt = 0xffffffff;
       else
           pcnt = (HET_L04_0.memory.data_word)>>2;      


       #define ENUMERATOR  50000000   /* <-- FILL THIS */

       /* calculate rotational speed */
       n_rpm = ENUMERATOR / (pcnt * 3);   
            
       direction= (e_GIO_ST.Port_ST[2].Dout_UL) & (1<<2);
       /*if direction==0 then rotation clockwise else anti-clockwise */
           
       Update_LCD_HET(dc, n_rpm, direction);
           
    }
    /******************************************************************************/


    --------------------------------PWM.het----------------------------------


    L00   CNT   {  reg=A,  max= 249 }

    L01   MCMP  {  en_pin_action=ON, order=reg_ge_data, pin=CC0,
                   action=PULSEHI, reg=A,  data= 75,  hr_data=0x4 }

              ; duty cycle 69,95 %

    L02   MCMP  {  en_pin_action=ON, order=reg_ge_data, pin=CC7,
                   action=PULSEHI, reg=A,  data= 0,   hr_data= 0 }

              ; duty cycle 100 %

    L03   MCMP  {  en_pin_action=ON, order=reg_ge_data, pin=CC8,
                   action=PULSEHI, reg=A,  data= 250, hr_data= 0 }

              ; duty cycle 0 %

    L04   PCNT  {  next= L00, type=FALL2FALL, pin=CC3 }

              ; This gives the rotational speed
    ----------------------------------------------------------------------------------------

    If this answers your question, please click "This Resolved My Question"
    Regards,
    Wade

  • Thanks for the information.  I will try it.

    To detect input with 2 different frequency, I decide to set input as GPIO external interrupt pin and use RTI regular counter to read the count value between 2 falling edges to distinguish two different frequencies.  If the counter overflow interrupt happens, that means the input is idle.  Do you  have any sample project for setting up counter overflow interrupts?  It is very difficult to find any example from TI SM470 website.

    Thanks, Jian

  • Jian,
    I do not have any example code using RTI. I will check some other sources, and maybe will get lucky.
    However,
    I believe the HET will be better suited to do this, as it will not be as dependent on cpu availability. If you are using CPU to respond to interrupt to grab the RTI timer value, there will be some delay before the value is obtained. The delay could also be somewhat variable if you are servicing other interrupts. This still may work out okay, but using the HET will not have this same issue.

    Regards,
    Wade
  • Wade,

    If using HET for input, does "L04   PCNT  {  next= L00, type=FALL2FALL, pin=CC3 }" in your example set up the timer for input?
    If so, how to read the counter between 2 falling edges?  Do I read counter in the main while loop or some interrupts?

    Thanks, Jian

  • Any updates on my previous question? I am working on this but no luck.

  • Jian,
    I have not been able to locate any examples of input timing setups.
    I suspect this could be handled multiple ways depending on your system needs.
    I believe that an interrupt can be generated each time the input captures rise to rise or fall to fall.
    This may generate quite a few interrupts.
    Alternatively, the cpu can go grab the register value containing the count periodically.

    I will send you an email with some other ideas shortly.
    Regards,
    Wade
  • Wade,

    In your het example, L04 PCNT {  next= L00, type=FALL2FALL, pin=CC3 } in PWM.het is for counter.  To distinguish 250Hz and 270Hz input, I plan to generate a 270*2Hz timer interrupt and read HET_L04_0.memory.data_word to get counter value.  It should be the counter value of 250Hz or 270Hz.

    Is this correct?

  • Wade, I got the problem solved.  Thanks!