You are not using clkset() correctly. You are using a #define to redefine it. Notice that the compiler is giving a warning about this. You should call clkset() at the beginning of your program by adding the line clkset(0x6b,5000000);" at the beginning of the main routine.
You have a typo where you declare freq, and initialize it to "CLKFREQ>>!". You probably meant "CLKFREQ>>1".
After fixing these problems the program compiles OK. I don't get an error about an "else" without a previous "if".
Can you attach your *.c file instead of including it in a code block? Maybe you have some weird character in your file that isn't visible in the code block.
Corrected the mistakes and it builds now and loads, however the outputs are not right. If I hold the button down the output pins should remain active flashing continuously until I release the button, but it doesn't. If I depress the button the corresponding led stays lit for approximately 2 seconds and then shuts off and doesn't reactivate for a second or two.
That is clearly not the program you were running. That code doesn't even compile. If you'd like some help, please attach your current code. Otherwise, we're just guessing at what changes you made that may be causing the current problem.
I ran the program on my propeller development board, and it works OK for me. Of course, I had to fix the call to clkset first. It was missing the right parenthesis.
What board are you using for the propeller? Did you build it yourself, or are you using a pre-built one? Have you run any other programs on this board?
Flip from parallax running at 5MHz. I changed the pause amounts to a range of 20 to 70 and they flash much faster now. Now I want to generate a slow PWM to run my motors. I will include my next program. It doesn't produce the desired results, please check it out. It turns on but no PWM pulse.
I looked at int pwm_start(unsigned int cycleMicroseconds ) and void pwm_set( int pin, int channel, int tHigh ), but I guess I don't understand
how to setup and use them. can someone please show me an example
with multiple outputs . all I got was a multitude of errors.
Here's an example taken from the Propeller C tutorials. This tutorial also shows how to use a remote joystick to control a robot using X-Bee radios to send the joystick data to the motor control. The tutorial starts here:
/*This application uses PWM to drive two DC motors. Maximum PMW is set at 1000 with command "pwm_start(1000)". This application program is entended
for use with a two H-bridges in this case the Pololu Motor Driver Carrier Board(28820). Also used in this application two DC gear motors(28819)
P3 and P4 are used to drive the motors in a forward motion(includes turning). P2 and P5 are used to move in reverse. If you want to use only one
motor comment out or remove pins 3 and 4 OR pins 2 and 5 from the code.
*/
#include "simpletools.h"
#include "fdserial.h"
#include "abdrive.h"
int main() // Main function
{
pause(250);
// Keep pins low if unused.
set_outputs(5, 2, 0b0000);
set_directions(5, 2, 0b1111);
fdserial *xbee;
{
xbee = fdserial_open( 9, 8, 0, 9600 ); // Begin the serial connection ( this is why we
// needed the jumper cables connected to pins 8 and 9 )
char data;
// Create the variable that will be used to hold incoming data
pwm_start(1000);
while ( 1 ) // Repeat this forever or until loss of power
{
data = fdserial_rxChar( xbee ); // Set data to the data received from the XBee board
if ( data == 'f' ) // If the data incoming is telling the robot to move forward
{
//(pin, pwm channel, 800/1000) // Move forward 80 percent speed (800 of 1000)
pwm_set(3, 1,800); // left wheel command set
pwm_set(4, 0,800); // right wheel command set
}
//(pin, pwm channel, 800/1000)
else if ( data == 'b' ) // If the data incoming is telling the robot to move backward, move backwards
{
// Move backwards 80 percent speed (800 of 1000)
pwm_set(2, 0,800); // left wheel command
pwm_set(5, 1,800); // right wheel command
}
else if ( data == 'l' ) // If the data incoming is telling the robot to turn left, turn left
{ // Turn right motor faster than left motor to make a right turn
pwm_set(4, 0,850); // right wheel command
pwm_set(3, 1,550); // left wheel command
}
else if ( data == 'r' ) // If the data incoming is telling the robot to turn right, turn right
{ // Turn left motor faster than right to make a right turn
pwm_set(3, 0, 850);
pwm_set(4, 1, 550);
}
else if ( data == 's' ) // If the data incoming is telling the robot to stop, then stop
{
pwm_set(2, 0, 0);
pwm_set(5, 1, 0);
pwm_set(3, 0, 0);
pwm_set(4, 1, 0);
}
}
}
}
I use the statement "if (button1 == 1)
{
pwm_set(17, 0, 500);
}
else if( button2 == 1)
{ I get an error: :'else' without a previous 'if'. Why is the IDE unable to recognize the previous'if'.?
There were a number of errors in the program. Here is a corrected version showing the errors in comments.
#include "simpletools.h"
#include "propeller.h"
int main()
{
clkset(0x6b, 5000000); // **** error was "clkset = 0x6b, 5000000"
int mask = 0xff0000;
int freq = CLKFREQ>>1;
DIRA = mask; // **** error was no ";" atend of statement
int button1 = input(3);
int button2 = input(4);
pause(250);
pwm_start(2000);
while(1)
{
if (button1 ==1)
{
pwm_set(17, 0, 500);
}
else
{
pwm_set(17, 0, 0);
}
if(button2 == 1)
{
pwm_set(18, 0, 500);
}
else
{
pwm_set(18, 0, 0);
}
if((button1 == 0) && (button2 == 0)) // **** error was wrong syntax of if statement
{
pwm_set(17, 0, 100); // **** error was no ";" at end of statement
}
}
}
Note, I don't know if the program does what you want since I don't have your hardware. But it compiles.
When debugging a SimpleIDE program, look at the errors and start with the one on top. Look at the numbers in the error statement. The first number is the line number. Correct that error, rebuild, and if there are errors handle the next in order from the top down.
bbrien, something doesn't make sense here. Every time you paste code into your responses it is missing characters that would cause obvious compiler errors. However, you never mention those errors. You always mention other errors, such as an else without if. The errors that we get from your posted code are completely different from the errors that you get. I can only conclude that the code you are posting is not the same as the code you are compiling.
PLEASE ATTACH YOUR SOURCE FILES INSTEAD OF PASTING THEM INTO YOUR POST!!!
'else' without a previous 'if' statement
expected statement before ')' token
Did you copy the code I put into my post and then just paste it into a blank Simple IDE screen? Or are you typing it in?
In your previous code where you got 'else' without a previous 'if' statement error, the if statement had incorrect syntax so the following 'else' statement resulted in the 'else' without a previous 'if' statement.
That is why it is important to scroll to the top of the error listing and correct errors from the top down.
Be sure that you have ";" at the end of each statement
Also check the line number for the error and look for the error on the same numbered line in the SimpleIDE listing.
bbrien,
SimpleIDE lets you copy the error text so you can paste it in to the forum. Please use the Code 'C' (Ctrl-O) command within the forum post to include your text in a nice code-style format. I've added an error to the following code just to get the error text to display as an example:
Error code example as copied from SimpleIDE's "Build Error Code" menu item:
This allows other forum posters to help you in solving your error.
You can also create a .zip file of your whole project too attach to your posting (As I've done in this post). Look in the Project menu for the "Zip" command. See an attached .zip of a shortened (& repaired) version of your code, below...
Had a semicolon where it shouldn't have been and it took a long time before I saw it and it compiles now, now I have another problem. I get 13 rapid pulses and then no pulses for about 1 second + and then another group of pulses. What causes this and how do I correct. please refer to earlier post for revised program . thanks
IIC (aka I2C) is relatively simple at the hardware signalling level. It basically consists of 2 signals, a data signal (low or high) and a clock signal that indicates when a valid data bit is available. The communication protocols range from dead simple to fairly complex. See this page for a desription.
"This page" lost me. What I want to do is have the Flip read a signal from the Arduino which uses a single digit(4) as the address for I2C. What is the I2C address for the flip. My old sketch for the I2C read is as follows
I am using an arduino as the master which uses an address of 4 and I want to use a propeller flip as a slave but I don't know what to use for the address to pass to the arduino, and what parts of simplei2c.h do I use to read the bytes from the above arduino code into the outputs of the 'flip'.
I'm going to have to give up on the idea of using I2C to communicate with the propeller Flip board. The Spin language has an assignment operator(:=) which copies the input directly to the output. Is the propeller C (==) the same or equivalent. I would prefer to use I2C so I wouldn't have to design a new board , but I cannot find any understandable examples. Is it possible to add spin code to the propeller C code.
Comments
thank you
You have a typo where you declare freq, and initialize it to "CLKFREQ>>!". You probably meant "CLKFREQ>>1".
After fixing these problems the program compiles OK. I don't get an error about an "else" without a previous "if".
I have accidentally created errors like that in the past when I added a debug print after the if statement, but before the "{".
Try holding the button down for 20 seconds. I'm guessing that you'll see it toggle at a very low rate.
What board are you using for the propeller? Did you build it yourself, or are you using a pre-built one? Have you run any other programs on this board?
how to setup and use them. can someone please show me an example
with multiple outputs . all I got was a multitude of errors.
learn.parallax.com/tutorials/language/propeller-c/dc-motor-control-project
{
pwm_set(17, 0, 500);
}
else if( button2 == 1)
{ I get an error: :'else' without a previous 'if'. Why is the IDE unable to recognize the previous'if'.?
Note, I don't know if the program does what you want since I don't have your hardware. But it compiles.
When debugging a SimpleIDE program, look at the errors and start with the one on top. Look at the numbers in the error statement. The first number is the line number. Correct that error, rebuild, and if there are errors handle the next in order from the top down.
expected statement before ')' token
PLEASE ATTACH YOUR SOURCE FILES INSTEAD OF PASTING THEM INTO YOUR POST!!!
Use the "Attach a file" link to attach a file.
Did you copy the code I put into my post and then just paste it into a blank Simple IDE screen? Or are you typing it in?
In your previous code where you got 'else' without a previous 'if' statement error, the if statement had incorrect syntax so the following 'else' statement resulted in the 'else' without a previous 'if' statement.
That is why it is important to scroll to the top of the error listing and correct errors from the top down.
Be sure that you have ";" at the end of each statement
Also check the line number for the error and look for the error on the same numbered line in the SimpleIDE listing.
SimpleIDE lets you copy the error text so you can paste it in to the forum. Please use the Code 'C' (Ctrl-O) command within the forum post to include your text in a nice code-style format. I've added an error to the following code just to get the error text to display as an example:
Error code example as copied from SimpleIDE's "Build Error Code" menu item:
This allows other forum posters to help you in solving your error.
You can also create a .zip file of your whole project too attach to your posting (As I've done in this post). Look in the Project menu for the "Zip" command. See an attached .zip of a shortened (& repaired) version of your code, below...
dgately