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

Using the counters with simple ide

pilot0315pilot0315 Posts: 913
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

«1

Comments

  • iseriesiseries Posts: 1,495

    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: 9,155
    edited 2024-07-20 16:57

    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 vs SimpleIDE). The person who created SimpleIDE has long left the Parallax forums.

  • dgatelydgately Posts: 1,630

    @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

  • pilot0315pilot0315 Posts: 913
    edited 2024-07-17 08:46

    @dgately
    Just saw your post.
    I will look further to see if I have an error.
    I have checked the auto include simple libraries which is already checked.
    Where is this:?

    Looked all over SimpleIde and could not find it.
    The code example is from @iseries ,
    Direct copy and paste.

    Thanks for the help.
    Martin

  • dgatelydgately Posts: 1,630

    @pilot0315 said:
    Where is this:?

    If you mean how to show file & compiler info...

    dgately

  • @dgately
    @JonnyMac

    Sorry family isues intervened.

    O.K. I am back trying to get this issue solved with SimpleIde.

    I copied your above code and get the errors below. Just a small portion to see if it would compile.

    Tried adding " >>> "include cog.h" <<<< phrase and get the same error.
    Found that cog.h has the counter functions. Same error. Now I am totally unsure that is happening. As yo see I have the include simple libraries checked.
    This does not change things. Also have reinstalled the SimpleIde a couple of times no changes.

    Any ideas would be appreciated.
    Thanks Martin.

  • iseriesiseries Posts: 1,495

    SimpleIDE was designed for people that want to do C programming on the Propeller and not SPIN.

    C programs are case sensitive and lower case will not work.

    Mike

  • pilot0315pilot0315 Posts: 913
    edited 2024-08-14 04:43

    @iseries
    @JonnyMac , See above please.

    I am using Propeller C. The @dgately example is in Prop C using the cogs and ctra etc in Prop C. The current propeller tool GUI is
    corrupted. I reloaded that several times. It will not print, cannot change the
    interface skins and other problems. I have used Prop C for several years in the SimpleIde platform C++ for SimpleIde and Spin on the Propeller tool.
    So, I do not understand when I copied code that apparently works in Prop C, using just simpletools inclusion, and even in being more specific with inclusion of Cog.h, I get errors about declarations.
    Again thanks for the help in advance.
    Martin> @iseries said:

    SimpleIDE was designed for people that want to do C programming on the Propeller and not SPIN.

    C programs are case sensitive and lower case will not work.

    Mike

    Even changing one letter to upper case does not change the error.

  • iseriesiseries Posts: 1,495

    You don't need cog.h included, but CTRA, FRQA, PHSA must be all caps. These are special values.

    Mike

  • @iseries said:
    You don't need cog.h included, but CTRA, FRQA, PHSA must be all caps. These are special values.

    Mike

    I will try that.

    Thanks.
    Martin

  • @pilot0315 said:

    @dgately

    @iseries
    Would you be so kind to send me this code please. I continue to get errors even with all caps and with
    and without "include" cog.h.

    >

    >

    Any ideas would be appreciated.
    Thanks Martin.

  • iseriesiseries Posts: 1,495

    Compiles for me.

    Zip of the folder that contains the source.

    Mike

  • @iseries

    Thank you I will try it tonight.
    Martin

  • pilot0315pilot0315 Posts: 913
    edited 2024-08-27 10:48

    @iseries

    Sorry it took so long,
    I ran your code exactly as I unzipped it.
    Here is the error:

    I think that SimpleIde is screwed up. Cannot fix. I have reinstalled it 5 times same screwed error. .
    Going to try flexprop and see if I can get it to work.
    Flexprop, was able to compile but no square wave on the scope.
    used these to get it to compile: #include "propeller.h"

    include "simpletools.h"

    Thanks
    Martin

  • Do you have any rogue header files in your project directory with the same names as system headers but different contents (perhaps a newer or older version) that are confusing the compiler?

  • JonnyMacJonnyMac Posts: 9,155
    edited 2024-08-30 13:04

    I wondered what that [uncommented] demo did so I translated it (back) to Spin. It generates a 1ms bursts of 38kHz square waves. Along with the lack of comments, that demo is bad for not setting phsa when the output is off -- leaving phsa untouched can leave the output high or low; for an active-high output one probably doesn't want to do that.

    Anyway, here's my Spin version and the output on a logic analyzer.

    I can confirm that the program compiles and runs under FlexProp 6.9.10 with P1 defaults selected.

    The up-shot with FlexProp is you can co-mingle languages. A friend of mine prefers BASIC in FlexProp but uses a bunch of my Spin libraries. The other thing is that @ersmith is actively part of the community and working on FlexProp all the time. The person who created SimpleIDE hasn't been around the forums in years.

  • @Electrodude

    Rogue files? Please elaborate. Not sure what you are looking for.
    I have completely killed SimpleIde several times with all files that I can find on the drive. Everywhere I can look. Reinstalled and get the same issue.
    Thanks
    Martin.
    @JonnyMac
    Will be looking ito what you posted shortly.
    Thanks
    Martin

  • ElectrodudeElectrodude Posts: 1,660
    edited 2024-08-30 14:53

    @pilot0315 said:
    @Electrodude

    Rogue files? Please elaborate. Not sure what you are looking for.
    I have completely killed SimpleIde several times with all files that I can find on the drive. Everywhere I can look. Reinstalled and get the same issue.
    Thanks
    Martin.

    If you e.g. copy a system or library header into your work directory and then upgraded the compiler, or if you create your own header with a name that conflicts with that of a system header, the header that gets used might not be the one you expect. Reinstalling won't fix this, since the problem is in your work directory. The solution is to never make copies of system headers, to use #include "..." vs. #include <...> appropriately, and to be aware of system header names when naming your own headers.

  • @Electrodude
    @iseries
    @JonnyMac
    I understand but I do not remember making a change like that. Have not upgraded the compiler. The version of SimpleIde I have been using is the same one I have had for a very long time. Never until now tried to use the cogs. Do you have any suggestions as to for me to again completly clean the drive of any vestiges of the program and rein stall and see if that fixes the issue. Also since I have trying to use Flexprop, and am on a new learning curve, which library to include to try to get this working. Looks like I have to give up on SimpleIde and move on to a different GUI.
    Thanks to all.
    Martin

  • @iseries

    Howdy,
    Sorry I took so long. I attempted to use your simpleide code after meticulously removing all remenants of simpleide and starting completly from scratch. I got the same results. I am now searching for an earlier version and will see what happens. I also tried your version FlexProp but nothing happened. Pin 0 on my scope did nothing. Is there something I missed?
    Thaks again for the attempt for the help.
    Martin

  • @iseries

    Loaded version 1.1.0 ran the program and got the same error.

  • iseriesiseries Posts: 1,495

    This is a mystery; we have a lot of people using this tool without issues.

    It seems that the compiler cannot find files in this folder: C:\Program Files (x86)\SimpleIDE\propeller-gcc\propeller-elf\include

    This folder has the definitions for those special registers in the COG.H file.

    Why your setup cannot find these files is a mystery.

    Mike

  • pilot0315pilot0315 Posts: 913
    edited 2024-09-23 07:29

    @iseries
    @"Ken Gracey"
    @cgracey

    I tried again to delete, erase and eradicate simpleide. Reloaded. Same errors. Now trying to use the Epaper module.
    It says that it cannot load the #include "il3820.h" file. It gives me a .elf file error also.
    Total mystery to me. I have used this gui for ages without problems.

    Ken please review the above issue. I have been told that simpleide is no longer supported.
    Thanks for the help in advance
    Martin
    Finally got it to see the il3820.h file. Had to update the workspace several times. Still have issues with the counters. It does not see the cog.h file properly.

  • iseriesiseries Posts: 1,495

    I just built a virtual windows 11 machine in the cloud.

    I then downloaded the simpleIDE installer and installed it.

    Then I downloaded the example file "Test360.zip" and unzipped it into the Documents\SimpleIDE folder.

    Ran SimpleIDE and opened the Test360 sample program and pushed the Hammer and it compiled normally.

    I then download the latest Learn folder and renamed the current one and unzipped and copied in the new Learn folder.

    Ran SimpleIDE and pushed the Hammer button and it also compiled normally.

    There is something going on with your setup.

    Mike

  • iseriesiseries Posts: 1,495

    Install flexprop on the virtual server and compiled the Test360 program and it compiled normally as well.

    If you would like to see the environment or try it for yourself, I can give you access to the Virtual Windows system in the cloud. You will need to use RDP(Remote Desktop Client) to access this machine.

    Mike

  • @iseries

    Never done that before. (RDP) access. Do you have a link that has the explanation for Dummies?
    Something new to learn. Then I would try.
    Thanks for the offer and the lesson.
    Martin

  • Looks like the the writer of SimpleIde did not write a library for full access to the counters. I dug around and discovered this. I am atempting
    to write some code to access the counters from scratch independant of the libraries. Any suggestions would be appreciated.
    Thanks
    Martin

Sign In or Register to comment.