Shop OBEX P1 Docs P2 Docs Learn Events
Using the counters with simple ide — Parallax Forums

Using the counters with simple ide

pilot0315pilot0315 Posts: 858
edited 2024-07-09 06:57 in C/C++

I am searching for examples as well as a HOW TO using the counters for P1 in SimpleIde.
Thanks in advance for any help.
Martin

Comments

  • iseriesiseries Posts: 1,475

    Here you go,

    /**
     * @brief Test 360 Servo library
     * @author Michael Burmeister
     * @date February 4, 2018
     * @version 1.0
     * 
    */
    
    #include "simpletools.h"
    
    void square_wave_setup(int pin, int freq, int* ctr, int* frq);
    
    #define SP 15
    #define FP 12
    
    int Pin = 0;
    int i;
    
    
    int main()
    {
      CTRA = 4 << 26 | 1;
      FRQA = 0;
      PHSA = 0;
    
      low(1);  
      while(1)
      {
        FRQA = 0x1f212d;
        pause(1);
        FRQA = 0;
        pause(1);
      }  
    }
    
    int fraction(int a, int b, int shift)
    {
      if (shift > 0)
      {
        a <<= shift;
      }
      if(shift < 0)
      {
        b <<= -shift;
      }
      int f = 0;
      int i;
      for(i = 0; i < 32; i++)
      {
        f <<= 1;
        if(a >= b)
        {
          a -= b;
          f++;
        }
        a <<= 1;
      }
      return f;
    }
    
    void fout(int pin, int msTime, int frequency)
    {
      int ctr, frq, channel;
      //char s[32];
      square_wave_setup(pin, frequency, &ctr, &frq);
      if(!CTRA)
      {
        channel = 0;
        FRQA = frq;
        CTRA = ctr;
        low(pin);
      }
      else
      {
        channel = 1;
        FRQB = frq;
        CTRB = ctr;
        low(pin);
      }
      pause(msTime);
      if(!channel)
      {
        FRQA = 0;
        CTRA = 0;
        input(pin);
      }
      else
      {
        print("%x \n", CTRB);
        FRQB = 0;
        CTRB = 0;
        input(pin);
      }
    }
    

    You can also look at any of the library functions to see other examples.

    Mike

  • @iseries

    Thank you ever much.
    I will try this this evening. I am porting over Spin for the X-Band detector.

    Again thanks for helping the 'DUMMY'
    :D:#

  • @iseries

    Hello sir,
    Question. I ran your code and was getting the same issues which you will see.
    I am trying to find which library supports the counters. Does not seem to be
    in "Simple tools"
    Thanks again. If I find it I will let you know. Too bad SimpleIde appears to be
    no supported.

  • JonnyMacJonnyMac Posts: 8,988

    I am trying to find which library supports the counters. Does not seem to be

    SimpleTools.h uses propeller.h (where the register definitions exist) -- propeller.h uses cog.h.

    You might consider FlexProp (very popular) or Catalina (less popular, but seems to be more standard) over SimpleIDE. The person who created SimpleIDE has long left the Parallax forums.

  • @pilot0315 said:
    I am trying to find which library supports the counters. Does not seem to be
    in "Simple tools"
    Thanks again. If I find it I will let you know. Too bad SimpleIde appears to be
    no supported.

    I was able to compile the code in SimpleIDE, without issue. Are you sure your settings are correct?

    Are you Auto including Simple Libraries in Properties?

    dgately

Sign In or Register to comment.