Propeller C Manual?
Beavis3215
Posts: 229
I'm fairly proficient at SPIN, trying to teach myself PropC. Is there a manual of some kind explaining usage of PropC code? I cant find anything and am trying to rely on start simple examples which don't contain everything that I am looking for.
Comments
http://learn.parallax.com/tutorials/language
Otherwise it follows the C/C++ spec.
http://learn.parallax.com/support/C/propeller-c-reference
Near the middle of the page is a link, "Open the latest Simple Library Reference release". It takes you here:
https://cdn.rawgit.com/parallaxinc/propsideworkspace/master/Learn/Simple Libraries Index.html
That's been my go-to reference for Propeller stuff in C.
Clear a pin: DIRA = DIRA & ~(1<<pin);
Each bit in the register corresponds to a pin on the Prop. Using standard bitwise operators you manipulate the bits:
OR is | (vertical bar)
AND is &
NOT is ~
XOR is ^
These are bitwise operators, not logical operators - they perform their actions on individual bits.
But gcc does not allow throwing underscores between the bits... :-(
Indeed it does. It is what is known as a "Hardware Abstraction Layer" (HAL) which is a buzzphrase that just means it provides a lot of low-level functions/objects/classes/whatever to interface with the physical world. The idea is that you should be able to use a HAL without knowing anything (or at least, not very much) about the hardware that is executing your code. Talking about pins again, simpletools provides the functions "high(1)" and "low(1)" to set a pin high or low. You don't have to know anything about how pins are controlled on the Propeller hardware to use these functions, so these are two excellent examples of functions that belong in a HAL. There are other HALs designed for the Propeller that are written in C and C++, but for someone that is still learning C, SimpleIDE and simpletools is a great place to start.
It does, but there is a speed cost. In the thread below, I compared simply transitioning a pin from high to low and found a great difference in number of clocks to do that based on the method used.
PASM was the fastest at 6 clocks.
Spin took over 500 clocks (depending on method)
Prop C had a wide range depending on method and memory model. For example using SimpleIDE with CMM memory model was slowest at over 700 clocks, while using propeller.h with LMM took only 17 clocks.
The detailed results are in this thread:
https://forums.parallax.com/discussion/164271/solved-with-timing-results-problem-with-pasm-counters-ctra
Tom
https://cdn.rawgit.com/parallaxinc/propsideworkspace/master/Learn/Simple Libraries/Utility/libsimpletools/Documentation simpletools Library.html
The simpletools.h reference is one of many simple libraries references. The rest can be found below:
https://cdn.rawgit.com/parallaxinc/propsideworkspace/master/Learn/Simple Libraries Index.html
3 button calculator
*/
#include "simpletools.h" // Include simple tools
int main() // Main function
{
set_directions(9,4,111111); // Output Lights
set_directions(23,21,000); // Input Buttons
int button1 = input(21); // Enter operand one at a time
int button2 = input(22); // Plus and clear
int button3 = input(23); // Equals
while(1)
{
int a = 0;
int b = 0;
int c = 0;
while(button2 == 0) // Enter first operand
{
if (button1 == 1)
{
a = a + 1;
set_outputs(9,4,a);
pause(100);
}
}
while(button3 == 0) // Enter second operand
{
if (button1 == 1)
{
b = b + 1;
set_outputs(9,4,b);
pause(100);
}
c = a + b;
set_outputs(9,4,c);
}
while(button2 == 0) //Clear when button 2 pushed
{
}
}
}
Any Idea why this doesn't work?
Enter first operand using button number 1, shown on leds. Hit button number 2 for plus. Enter second operand using button number one shown on leds. Add result using button number 3 and display on leds as long as it is not too big. Clear and start over using button number 2. Problem is not hardware as I have written an equivalent program in spin that works.
These statements are identical as far as the runtime code is concerned:
int a = 16;
int a = 0x10;
int a = 0b10000;
They just look different to you as the user. The different ways of representing number constants are for human readability only.
pub waitbutton(button,frac)
If ina[button] == 1
outa[9..4] := outa[9..4] + 1
waitcnt(clkfreq/frac + cnt)
3 Button Calculator
obj wait : "waitbutton2"
var byte a,b,x,y
PUB Calc
dira[9..4]~~
dira[23..21] := %000
outa[9..4] := %000000
x := 0
y := 0
repeat
repeat while x == 0
wait.waitbutton(21,3)
if ina[22] == 1
x := 1
a := outa[9..4]
outa[9..4] := %000000
repeat while y == 0
wait.waitbutton(21,3)
if ina[23] == 1
y := 1
b := a + outa[9..4]
outa[9..4] := b
The spin version does not have a "clear", but otherwise the logic "should be" the same.
It makes it much easier for the forum people to read your code and help you, particularly in Spin because the indenting itself controls much of the program flow.