Open tanthua opened 8 years ago
When you call analogWrite() it sets the frequency overwriting the settings you have just made. The latest version of the core has a function to set the frequency properly - #253
analogWriteFrequency(12000);
Thanks so much for the answer. Would it change the frequencies of all the OC1-5 or just one specific pin?
All pins together - they all run off timer 2.
I got the test you provided in another post working. But when I put them in setup() in StandardFirmataChipKit, it was back to 500Hz again. So weird. I tried put them in both setup() and loop() but none worked.
Firmata uses SoftPWMServo for the PWM to allow PWM on every pin on the board. That always runs at 500Hz regardless.
void servoWrite(byte pin, int value)
{
SoftPWMServoPWMWrite(PIN_TO_PWM(pin), value);
}
Oh darn....It's very good to know. It's going to be tough :(. Thanks so much!!!
Can you elaborate it a bit more? I'm not sure I get that.
How did that get there?!
In chipKIT we have two PWM systems - hardware, which can only go on the OCx pins, and software, driven by the Core Timer, which can be on any pin. Firmata, to give PWM on all pins, uses the software one. There's no way of changing the frequency for the software PWM.
I kind of get it now. So do you think it's possible if I use MPLAB to change the pwm frequency and then use firmata to do the rest of the work? Or the firmata will override the pwm frequency regardless of the changes?
If you want a different frequency in Firmata you will have to change Firmata to use the hardware PWM (analogWrite()) instead of the software PWM (SoftPWMServoPWMWrite()) in the function I showed you above. Then you will be able to use analogWriteFrequency().
Got it! Will give it a try. Thanks so much! :D
So when I do analogChangeFrequency(val), how would the resolution change along without touching analogChangeResolution(val)? Would there be any conflict cases?
Hi. I'm using chipkit uc32. I picked this code up from another issue that was resolved here, and it was compiled and uploaded successfully. However, when I measured the frequency of pin 3 or pin 5, they remained the same around 498 Hz. I would like to change the frequency up to 12 kHz but never got it working. I tried both timer2 and timer3.
Also, I used the Arduino IDE with chipkit library. When I uploaded the sketch from "StandardFirmataForChipkit", the frequency of pwm dropped from 498Hz to 398Hz constantly.
Can you give me explanations for those incidents and also provide me a complete example how to change the frequency of pin 3 or 5 of the chipkit on Arduino IDE?