4 independant pwm channels
Mauvai
Posts: 45
Looking to get 4 independent pwm channels running, preferably one core (even though I'm reasonably sure that's impossible. Checked the object exchange to find everything is in spin (which I don't speak), tried checking the servo lib, couldn't find what i was looking for. My solution was to launch a function into a new cog and run pwm from inside that cog, but it didn't work. Is there an easy way around this?
Code I tried:
Code I tried:
/* Blink Light.c Blink light circuit connected to P26. http://learn.parallax.com/propeller-c-simple-circuits/blink-light */ #include "simpletools.h" // Include simpletools void pwm2(); int main() // main function { unsigned int stack[40+40]; //print("Hello"); high(0); pause(500); low(0); pause(500); high(0); pwm_start(20000); pwm_set(26, 0, 10000); pwm_set(27, 1, 100); int i = 100; int j = 10000; cogstart(&pwm2, NULL, stack, sizeof(stack)); //cogstart(&adder, NULL, stack, sizeof(stack)); while(1) // Endless loop { //print("loop start"); pwm_set(26, 0, i); pwm_set(27, 1, 10000); i = i + 10; j = j + 10; if (i == 19000) { i = 100; } if (j == 19000) { j = 100; } pause(1); } } void pwm2() { pause(250); pwm_start(20000); pwm_set(24, 0, 10000); pwm_set(25, 1, 100); int i = 100; int j = 10000; while(1) // Endless loop { //print("loop start"); pwm_set(24, 0, i); pwm_set(25, 1, j); i = i + 10; j = j + 10; if (i == 19000) { i = 100; } if (j == 19000) { j = 100; } } }
Comments
I found that odd too. There are a few C/C++ libraries floating around for the Propeller, but they seem to all reside on GitHub instead of in the OBEX (my library - PropWare - is on GitHub as well)
Can you provide a little clarification? Presumably if i need 4 pwm channels, i need the 32-channel version? Which bits do i need specifically?
Can i download the h file and simply include it?
- #include <stdint.h>
- #include <propeller.h>
As a Propeller-C[++] user, you'll quickly recognize that propeller.h is part of PropGCC, so that's already included. You can do the searching yourself, or just trust me when I say that stdint is part of PropGCC too . In general, most anything that follows the "std*.h" pattern will be part of the "standard" library.What does that mean? That means no dependencies. When looking at a header file (*.h), make sure you also look for a source file (*.c or *.cpp or *.cxx) with a matching name. In this case, there is none - all code is contained within the header.
So, it's real simple! Just grab pwm32.h and put it in your project folder . You'll need to add "#include "pwm32.h" on top of any file that needs access to it.
For examples on how to use it, I'd recommend poking through the PWM32 unit test or asking SRLM (the author). I can answer some basic questions about but have never used it myself.
As I would with any C/C++ project - however when i tired to build this, without calling any functions from the file, I got the following error:
./pwm32.h:21:1: error: unknown type name 'namespace'
./pwm32.h:22:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
Done. Build Failed!
I got the code compiling by changing the compiler in the simple IDE to c++ - as the project is in a .h file, it cannot be changed to cpp so easily. I think.
The code I am running is as follows: The code compiles and runs, but doesn't do anything. My 4 LEDs sit there dark :-/
Glad to hear it!
Assuming you're referring to this:
#ifdef __GNUC__
#define INLINE__ static inline
#define Yield__() __asm__ volatile( "" ::: "memory" )
#define PostEffect__(X, Y) __extension__({ int tmp__ = (X); (X) = (Y); tmp__; })
#else
#define INLINE__ static
static int tmp__;
#define PostEffect__(X, Y) (tmp__ = (X), (X) = (Y), tmp__)
#define Yield__()
#endif
It's called preprocessor macros. What these macros do is beyond me. But #define just creates a variable that is, for all intents and purposes, copied and pasted later. So:
would be turn into
before being compiled.