Author Topic: Adjusting PWM frequency  (Read 5021 times)

MikeZ

  • RFduino Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Adjusting PWM frequency
« on: December 02, 2013, 05:08:51 PM »

Matt

  • RFduino Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: Adjusting PWM frequency
« Reply #1 on: February 26, 2014, 07:33:10 PM »
+1

I'm also looking for a way to change the pwm frequency.

edorphy

  • RFduino Full Member
  • ***
  • Posts: 86
  • Karma: +0/-0
    • View Profile
Re: Adjusting PWM frequency
« Reply #2 on: February 27, 2014, 06:30:42 PM »
Modify line 405 in wiring_analog.c?

Code: [Select]
NRF_TIMER2->PRESCALER = 0; // Source clock frequency is divided by 2^6 = 64
do a find in that file and you can theoretically modify the pwm prescaler for timer 1 too.

Not sure what the valid values are though.

Hope that helps.

ruben_vleuten

  • RFduino Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Adjusting PWM frequency
« Reply #3 on: April 14, 2014, 12:52:12 PM »
Did anyone have any success with the adjusting (increasing) of the PWM? I need to increase the PWM value too.

Cheers,

R.

notsolinear

  • RFduino Jr. Member
  • **
  • Posts: 52
  • Karma: +3/-0
    • View Profile
Re: Adjusting PWM frequency
« Reply #4 on: May 19, 2014, 09:53:59 PM »
This is a slight hijack, but could someone tell me what the default PWM frequency is?

leo

  • RFduino Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Adjusting PWM frequency
« Reply #5 on: September 04, 2014, 02:21:37 AM »
The default freq is about 245Hz

Hi, i also need to speed up PWM frequency to about 20Khz.

 i played with the timer values in wiring_analog.c but only manged to slow down the frequency  to some Hz by setting
 NRF_TIMER1->PRESCALER = 4;
 NRF_TIMER1->CC[0] = 1;


(and with NRF_TIMER1->PRESCALER = - 4  down to even 480mHz)

any hint what to do, or how Timer 1 and 2 work together?



thx leo

tytouf

  • RFduino Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: Adjusting PWM frequency
« Reply #6 on: December 06, 2015, 01:38:08 AM »
I believe you need to edit file cores/arduino/wiring_analog.c and uncomment the BITMODE and PRESCALER lines.

The ref manual specifies the clock frequency to be equal to 16MHZ/PRESCALER and using BITMODE you can define the timer precision.

So with PRESCALER = 1 and BITMODE = 16bits (the default values) you get Ftimer = 16MHZ/1/2^16 ~= 244Hz

If you use the commented values PRESCALER=6 and BITMODE=8bits you get Ftimer = 16MHZ/64/2^8 ~=976Hz

Hope this helps person looking for an answer to this somewhat old thread.

tolson

  • Global Moderator
  • *****
  • Posts: 806
  • Karma: +18/-0
    • View Profile
    • Thomas Olson Consulting
Re: Adjusting PWM frequency
« Reply #7 on: December 06, 2015, 11:30:35 AM »

Hope this helps person looking for an answer to this somewhat old thread.

As far as I am concerned, it is never too late to add to an 'old' thread when the answer is useful and valid.
It beats hunting around for numerous similiar unresolved topics having to have links back and forth.

Good job!

AKA

  • RFduino Jr. Member
  • **
  • Posts: 49
  • Karma: +2/-0
    • View Profile
Re: Adjusting PWM frequency
« Reply #8 on: December 22, 2015, 10:07:28 AM »
Hi, I'm following the advice of this thread (although I gather the location of wiring_analog.c has changed since the thread began) in the hopes of maximizing PWM frequency.

Does anyone have any tips? Is it really the case that around 900Hz is the maximum possible PWM frequency? I was hoping for functionality like the Teensy series of boards, where PWM can be set up to around 400kHz...

Thanks for any help anyone might be able to offer!

AKA

KerPop42

  • RFduino Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Adjusting PWM frequency
« Reply #9 on: April 16, 2016, 09:37:02 AM »
I don't know about how to program the PWM to use different frequencies (that's what I was trying to use the forums to find), but mathematically speaking there's an upper limit to how fast the board can output a signal. The clock operates at 16 MHz, or 1.6*10^10 Hz. The PWM has a minimum resolution of 8 bits, which requires an 8-bit timer. If the timer counted the clock directly the highest frequency the board could output would be (in theory) 1.6*10^10 / 2^8, or 62.5 kHz. If you can configure the timer to be 8 bits instead of 16, you can use prescalers and gain values in the same area of the code to drop the frequency from there.

Del Tapparo

  • RFduino Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Adjusting PWM frequency
« Reply #10 on: July 11, 2016, 09:36:52 AM »
Has anyone had success with this pwm.h library?
link: http://code.google.com/p/arduino-pwm-frequency-library/downloads/list

It was originally written for Arduino Uno and Mega. I can't get it to work on the RFDuino. The error I get is "unidentified reference to InitTimerSafe(), which is the first call used for this library.

tolson

  • Global Moderator
  • *****
  • Posts: 806
  • Karma: +18/-0
    • View Profile
    • Thomas Olson Consulting
Re: Adjusting PWM frequency
« Reply #11 on: July 11, 2016, 04:24:39 PM »
Isn't that library written for Atmel AVR. You want to find a library written for ARM Cortex M0 at least to have a chance of porting it. Best if for Nordic nRF51 chips.
« Last Edit: July 11, 2016, 05:58:54 PM by tolson »

Del Tapparo

  • RFduino Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Adjusting PWM frequency
« Reply #12 on: July 11, 2016, 08:04:55 PM »
I have confirmed from several sources, now, it will not run on an RFDuino/Simblee. Sure would like to find a software solution to get 20KHZ on my Simblee. I need it for motor control (quietly).

 

anything