Today I made some tests with my BLMC's. With a 50 Hz PWM Signal they work fine, but connected with the MP32 they don't start, so I had a look with my Osziloscope and found out that my MP32 sends it's PWM with 550 Hz. That's maybe to much for my Turnigy 25A Basic. They should work with 400 Hz, I read, so I would like to reduce the frequency a little.

Has anybody an idea where I can change this.

You need to be a member of FOXTEAM UAV CLAN to add comments!

Join FOXTEAM UAV CLAN

Email me when people reply –

Replies

  • Hi all,

     

    Here a code extension for motor PWM frequency adjustment.

    Replace the value behind the MOTOR_PWM_FREQ with your desired frequency (between 50 Hz and around 500 Hz). My Turnigy Basic seemed to work best with 350 Hz.

     

    In wirish.c

     

    #ifndef MOTOR_PWM_FREQ

      #define MOTOR_PWM_FREQ 350

    #endif

    unsigned short GetTimerReloadValue(unsigned short uFreq){

      unsigned int uiReload;

      if (uFreq>550) uFreq=550;

      if (uFreq<50) uFreq=50;

      uiReload=0xFFFF*50/uFreq;

      return (unsigned short)uiReload;

    }


    void init(void) {

      unsigned short Reload;

    Reload=GetTimerReloadValue(MOTOR_PWM_FREQ);

    :

    :

    timer_init(TIMER1, 1); //   
    timer_init(TIMER2, 1); //   
    timer_init(TIMER4, 1); //   
    timer_init(TIMER8, 1); //

    timer_init(TIMER5, 21); // PWM OUT 1-3   
    timer_pause(TIMER5);
    timer_set_count(TIMER5,0);
    timer_set_reload(TIMER5,Reload);
    timer_resume(TIMER5);   
    timer_init(TIMER3, 21); // PWM Out 4   
    timer_pause(TIMER3);
    timer_set_count(TIMER3,0);
    timer_set_reload(TIMER3,Reload);
    timer_resume(TIMER3);
        //setupUSB();
        /* include the board-specific init macro */   
    BOARD_INIT;
    }
    In APM_RC.cpp:
    void APM_RC_Class::OutputCh(unsigned char ch, uint16_t pwm){
    //  pwm=map(pwm, 1000, 2000, 32000, 64000); 
    pwm=map(pwm, 1000, 2000, 3273, 6546); // with prescale=21, Freq= 50 Hz 
    analogWrite(analogOutPin[ch], pwm);
    }

    best regards

    Thomas

    wirish.c

    APM_RC.cpp

    • @Thomas thank you very much for your code . This new frequency is used by all the pwm output or only from some channel ? Is possible to select different channel with different frequency .

      For example . ESC output at 550 Hz and standard servo at 50 or 200 hz.

      Best

      Roberto

  • the 3 sensors have an analog output and are connected to the ADS7844 AD Converter.

    So there is only the ADS7844 sampling rate to set (Datasheet)

    • Hi Thomas,

      in VRIMU i use same sensor of oilpan in one revision in other i use the same gyro of Mikrkoopter adxrs610 , the board is more expensive you have limit to 300 °/s as scale but you have more risolution.
      Good for Video application.

      In my test i'm going until 200 khz update to ADC without any problem if i going up 250 the adc converter stop to work.

      Some idea how to upgrade i2c and spi lib to DMA approach. Other questions , but the revision of code  for jeti that you send to me work fine on your jeti box ?

      Best

      Roberto

  • i just rised the speed of the main loop to 250 hz.

    it is windy and i had to move the stick up to the physical end to fight against the wind.

    the copter come down two times belly up and the esc's didn't stop with beeping until i pulled the power plug.

    overloaded?

    i use standard esc's sold from the diydrones store.

     

    a few turnigy plush are in my box ... looks like i have to test them.

    robert

    • The problem with my turnigy Basic 25 A: With 550 Hz Motor PWM (not main loop) they were beeping most of the time.

      With 400 Hz they work, but while increasing the throttle, they stopped to work.

      I think the problem is the very small gap between the pulses while hard gas,

      so then ESC goes out of sync and stops to work.

      With 350 Hz PWM the ESC worked good from minimum to full throttle.

      (The Plush should work with 400 Hz)

    • Hi Robert but are you using Multipilot32 ? What firmware ? on MP32 i'm going until 800 hz of main loop.

      Best

      Roberto

  • I did a little reseach. It seems that the ARR Register (Autoreload) shold be set to a value around 2500 for 400 Hz (found this in the AutoQuad code from Bill Nesbit).

    The ARR can be set with the 'timer_set_reload' Function in the 'timers.c'.

    This function is called only from one position: 'setOverflow' in HardwareTimer.cpp.

    And setOverflow is called in the Servo::attach() with the parameter SERVO_OVF

    SERVO_OVF is a result of:

    #define CYC_20MSEC     (20000 * CYCLES_PER_MICROSECOND)

    #define SERVO_PRE ((uint16)((CYC_20MSEC >> 16) + 1))

    #define SERVO_OVF ((uint16)((CYC_20MSEC / SERVO_PRE) - 1))

     

    so I should increase the SERVO_OVF value, to get a longer period, right?

     

    • Hi Thomas ,

      yes doing a test ... strange that turnigy don't work at 550 hz ...I try also china supersimple buy from giantcod and it works.

      Inform you about the results ..are  you connected signal and ground ? Some times if you don't connect gnd the esc don't work fine ...

      Best

      Roberto

This reply was deleted.