datapassion 0 Posted July 9, 2015 Share Posted July 9, 2015 Hi all, I am trying to use the PWM at different frequency wrt to the default one (490Hz right?). i tried to use the function analogFrequency(20000) but I got a problem when compliling: (.text.setup+0xb6): undefined reference to `analogFrequency' collect2.exe: error: ld returned 1 exit status Is this function implemented for the CC3200? If not, how can I change the PWM frequency? Thanks! Quote Link to post Share on other sites
Fmilburn 445 Posted July 9, 2015 Share Posted July 9, 2015 Hi @@datapassion There is a thread here: http://forum.43oh.com/topic/5765-analogwrite-precision-question/ that discusses your question. The sketch that is presented in that thread compiles for the CC3200. The function used is PWMWrite(). Quote Link to post Share on other sites
datapassion 0 Posted July 10, 2015 Author Share Posted July 10, 2015 Thanks @@Fmilburn a lot it seems to compile now. Can I change the frequency and the duty cycle running in the loop with this single command? Without any glitches? Thanks Quote Link to post Share on other sites
Fmilburn 445 Posted July 10, 2015 Share Posted July 10, 2015 @@datapassion - I don't know what your application is or how you are using it (also I don't normally use PWM with the CC3200).... I played with this sketch a bit just to see what it did: #include <wiring_analog.c> #include <wiring_private.h> int PWMpin = 29; // red LED int numberOfSteps = 100; int dutyCycle = 50; int frequency = 60; void setup() { // put your setup code here, to run once: pinMode(PWMpin, OUTPUT); PWMWrite(PWMpin,numberOfSteps,dutyCycle,frequency); } void loop() { // put your main code here, to run repeatedly: } It seems to dim and brighten the red LED on the LaunchPad more or less as expected at least down to 30 Hz or so. Much higher values seem to behave but I don't have an oscilloscope. At some point it is going to have limitations. The code for PWMWrite() is in wiring_analog.c as is analogWrite(). analogWrite() calls PWMWrite so Energia is using the function. That is about the depth of my knowledge. Have you tried playing with it to see if it does what you want? bluehash 1 Quote Link to post Share on other sites
Fmilburn 445 Posted July 25, 2015 Share Posted July 25, 2015 OK - now that I have an oscilloscope I played with this a bit more to see what it did. I essentially used the code in my post above. Here is what I found.... It doesn't seem to work below about 20 Hz - for some reason it gives really spurious (high) results down there. For example at 10Hz I measured 21.6 Hz on the oscilloscope. Above 20 Hz it is pretty much spot on until it gets to 100 KHz or so where it starts to deviate a little. Here are some examples.... CC3200 Oscilloscope ---------- --------------- 51,200 51.20 KHz 102400 102.3 KHz 5000000 497.0 KHz 1000000 988.1 KHz 2000000 1.95 MHz And here are a couple of screenshots: Looking good at 1 KHz Not too bad at 500 KHz Pretty sloppy at 4 MHz datapassion 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.