Using the counters with simple ide — Parallax Forums

# Using the counters with simple ide

Posts: 885
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

• Posts: 1,480

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

• Posts: 885

@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'

• Posts: 885

@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.

• Posts: 9,050
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.

• Posts: 1,629

@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

• Posts: 885
edited 2024-07-17 08:46

@dgately
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

• Posts: 1,629

@pilot0315 said:
Where is this:?

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

dgately

• Posts: 885

@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.

• Posts: 1,480

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

• Posts: 885
edited 2024-08-14 04:43

@iseries

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.

• Posts: 885

• Posts: 1,480

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

Mike

• Posts: 885

@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

• Posts: 885

@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.

• Posts: 1,480

Compiles for me.

Zip of the folder that contains the source.

Mike

• Posts: 885

@iseries

Thank you I will try it tonight.
Martin

• Posts: 885
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

• Posts: 1,648

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?

• Posts: 9,050
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.

• Posts: 885

@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

• Posts: 1,648
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.

• Posts: 885

@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