joao
New Member
Posts: 31
|
Post by joao on Jan 11, 2017 15:42:39 GMT
Hello,
I am implementing now pwm Outputs in Core 0;
I need to set the pwm frequency to a lower frequency. The manual refers that the use of ArduinoPwmFreq() function should lower the freq to 1.5kHz.
I am not being able to apply the function.
I am running it inside the setup() but i get this error:
exit status 1
'ArduinoPwmFreq' was not declared in this scope
How do i use this function? is there a special place to call it? do i need to add any library to call it?
Thank you
|
|
|
Post by drolli on Jan 11, 2017 16:56:30 GMT
Hello joao,
there is a little bug in the manual. The function name is "useArduinoPwmFreq();"
However, I would it find better to set a custom frequency :-)
Bye Reiner
|
|
|
Post by Admin on Jan 11, 2017 19:45:35 GMT
Yes, apologies, we will correct the manual!
|
|
joao
New Member
Posts: 31
|
Post by joao on Jan 12, 2017 7:31:38 GMT
Hi, thanks for the help, useArduinoPwmFreq() seems to work, i am getting no error now. I called it in Setup() but now my PWMs are not working. I have no outputs on them.
Do the function needs an argument? I need to control valves and motors with my PWMs and i can not use a very high frequency for that.
|
|
|
Post by mjb on Jan 12, 2017 8:20:15 GMT
Hi,
Here is an example!
/* * main_analog.c * */
uint8 period;
void setup() {
int i;
useArduinoPwmFreq(); // Use 1.5kHz PWM carrier like Arduino Uno
SerialASC.begin(9600); SerialASC.println("\nGreetings!"); SerialASC.print("Type in your desired duty ratio(0/256): ");
for(i = 0 ; i < 13 ; i++) { analogWrite(i,256); }
analogWrite(3, 128); analogWrite(4, 128); analogWrite(5, 128); analogWrite(6, 128); analogWrite(7, 128); analogWrite(8, 128); analogWrite(9, 128); analogWrite(10, 128); analogWrite(11, 128); analogWrite(12, 128);
}
int PinState = 0;
void loop() {
char num; int i;
if(SerialASC.available() > 0) {
num = SerialASC.read(); SerialASC.print(num); if(num == '\n' || num == '\r'){ period = period < 255 ? period : 255; period = period > 0 ? period : 0;
for(i = 0 ; i < 13 ; i++) { analogWrite(i, period); }
SerialASC.print("\n\rType in your desired duty ratio(0/256): "); period = 0; } else if(isdigit(num)){ period = period*10 + (num - '0'); }
}
}
void setup1() {
}
void loop1() {
}
void setup2() {
}
void loop2() {
}
|
|
|
Post by drolli on Feb 12, 2017 16:11:50 GMT
Hi, is it possible to use my own pwm frequency without using "useArduinoPwmFreq()"?
Bye Reiner
|
|
|
Post by mjb on Feb 12, 2017 17:57:06 GMT
Yes but it is not very easy right now as you would have to access the GTM period SFRs directly. What PWM frequency do you want? We can add a function to do this, if that would be useful.
|
|
|
Post by drolli on Feb 12, 2017 19:22:09 GMT
Hi, yes it would be useful. I need a PWM frequency of 3.9kHz. Maybe you can implement this in the "useArduinoPwmFreq()" function.
Bye Reiner
|
|
raaz
New Member
Posts: 6
|
Post by raaz on Feb 15, 2017 1:54:58 GMT
Hi, Can I use Servo.h library of arduino with shieldbuddy, Its working but I am getting very low frequency which is 33hz, which is not sufficient to drive the servo. any help what i can do.
Thanks
|
|
raaz
New Member
Posts: 6
|
Post by raaz on Feb 15, 2017 7:06:39 GMT
To add on to my last post, I have tried changing "#define REFRESH_INTERVAL" // which is minimum time to refresh servos in microseconds , but this variable is not making any change to the output signal where as in arduino is does.
|
|
|
Post by Admin on Feb 15, 2017 7:10:23 GMT
What PWM frequency do you need? 40Hz or 50Hz? How many channels?
|
|
raaz
New Member
Posts: 6
|
Post by raaz on Feb 15, 2017 8:56:20 GMT
50Hz on 4 channels. It is to drive servo for quad copte. Thanks
|
|
|
Post by mjb on Feb 15, 2017 9:13:21 GMT
OK, it is now running at 50Hz on up to 8 channels. We will put this in the next release which should be this week.
In the meantime, try copying this file into:
Servo.h (4.88 KB)
C:\Program Files (x86)\Arduino\hardware\aurduino\aurix\libraries\Servo\src
Copy this file into:
Servo.cpp (8.63 KB)
C:\Program Files (x86)\Arduino\hardware\aurduino\aurix\libraries\Servo\src\aurix
and rebuilding.
|
|
raaz
New Member
Posts: 6
|
Post by raaz on Feb 15, 2017 23:26:36 GMT
Thanks mjb, It worked. you are awesome.
|
|
|
Post by awwwwwwsome on Apr 10, 2019 8:52:43 GMT
I'm looking for "useArduinoPwmFreq" function. Someone knows that .cpp or .h file locations?
|
|