Shop OBEX P1 Docs P2 Docs Learn Events
Problem with "square_wave" — Parallax Forums

Problem with "square_wave"

Paul OPaul O Posts: 3
edited 2014-07-21 12:43 in Learn with BlocklyProp
Hi, new to this forum. Using the QuickStart board, SimpleIDE.

Want to flash two LEDs to simulate a RR crossbuck flasher.
I'm using "square_wave" from 'simple_tools'h'.

The first time I call "square_wave / delay / square_wave it works properly.
Then I call "square_wave_stop" -- stops both LEDs.
The next call to square_wave causes both LEDs to blink in sync.

Sample code is below; any suggestions?

Thanks, Paul O
/*
Flash two crossbuck lamps at a 1 Hz. rate.
*/
#include "simpletools.h" // Include simple tools


int main() // Main function
{
while(1)
{
square_wave(10, 0, 1); // 1 Hz. flash rate - first LED
pause (500); // Delay 1/2 second
square_wave(11, 1, 1); // 1 Hz. flash rate - second LED
pause(6000);
square_wave_stop(); // Stop both LEDs
pause(4000); // Delay for 4 seconds


} // Do it again
}

Comments

  • kwinnkwinn Posts: 8,697
    edited 2014-07-21 06:18
    Not familiar with Propeller C but I suspect the "while (1)" is exiting after the pause(4000). Try copying the 6 lines that flash the leds and paste them in after the first 6. If it flashes the leds twice my suspicion is confirmed.
  • Paul OPaul O Posts: 3
    edited 2014-07-21 06:33
    Thanks kwinn, but I put that "while" there to make it easy to duplicate the problem.
    The full C code program checks sensors for a train, flashes the lights, lowers the gates, waits for the end of train,
    raises the gates, stops the lights then goes back to the beginning to wait for the next train.
    I have the same problem as the test code I posted when the second train comes by.

    Paul O
  • kwinnkwinn Posts: 8,697
    edited 2014-07-21 07:15
    A typical problem for a subroutine that works the first time only is that some variable is not reset to it's initial value after the subroutine is called. Do the rest of the actions (lowering gate, waiting for end of train, and raising gate) work the second time around?
  • kwinnkwinn Posts: 8,697
    edited 2014-07-21 07:20
    BTW, I often put print statements at the beginning and end of routines for debugging (Got to xxxx routine, Exit xxxx routine). That can be a big help for something like this.
  • edited 2014-07-21 09:53
    Sorry, this looks like a bug in the library. This is a busy week, but I'll add this to the list and try to fix. If not, hopefully next week. For any of you interested in examining the library who haven't done it before, try these pages first: http://learn.parallax.com/propeller-c-library-studies

    Andy
  • Paul OPaul O Posts: 3
    edited 2014-07-21 12:43
    Thanks Andy.
    I've also noticed that it only fails if the frequency is the same value in both calls to the routine.

    Paul O
Sign In or Register to comment.