Quantcast
Channel: Forum - Recent Threads
Viewing all articles
Browse latest Browse all 5781

RE: How to configure three-phase PWM output for motor control

$
0
0

Mario,

Currently the SSP Timer Driver does not support OPS mode, so you have to write the code yourself at the register level.

However, still use the Synergy Configuration tool in E2Studio to create a Timer on GPT0.  

You need this as the PWM source to driver the OPS.

Enable the GPT0 interrupt and specify a callback function.  Don't worry about any other settings as you will overwrite these.

Enable the I/O pins for OPS output in the pin config.

In your application, try the code below.

I'll be honest, I don't understand Brush-less DC motor control, so I have no idea if the waveforms being generated are correct.

If you understand this technology then I'm sure you be able to modify the code to achieve what is required.

I hope this helps.

BR, Richard

/* HAL-only entry function */

#include "hal_data.h"

#define PWM_PERIOD_VALUE    0xFFFFL

#define PWN_DUTY_0A         PWM_PERIOD_VALUE / 4

void hal_entry(void)

{

   /* TODO: add your own code here */

   g_timer0.p_api->open( g_timer0.p_ctrl, g_timer0.p_cfg );

   /* Direct register access to some GPT registers is required.

    * A lot of these registers are write protected, so enable access to registers

    */

   R_GPTA0->GTWP = 0x0000A500;

   /*

    * Refer to S7G2 Hardware Users manual for set up flow -

    * 23.3.11.8 GPT_OPS Start Operation Setting Flow

    * Figure 23.85 Example setting for of GPT_OPS start operation

    * for more information

    */

   /* Specify a PWM mode for GPT0 */

   R_GPTA0->GTCR_b.MD = 4; /* Triangle-wave PWM mode 1 (16-bit transfer at trough) (single buffer or double buffer possible) */

   /* Set the Buffer mode for updating Period and Duty registers */

   R_GPTA0->GTBER_b.CCRA = 1;  /* Single buffer operation (GTCCRA ↔ GTCCRC) */

   R_GPTA0->GTBER_b.PR = 0;    /* No buffer operation */

   R_GPTA0->GTIOR = 0;

   R_GPTA0->GTIOR_b.GTIOA = 0x03; /* Set initial output low  - Retain output at cycle end - Toggle output at GTCCRA/GTCCRB compare match */

   /* GPT0 PWM Output enable / disbale */

   R_GPTA0->GTIOR_b.OAE = 1;    /* << If you want to see the GPT0A PWM output, then set this to 1.  Otherwise leave it at 0

   /* Set the PWM Duty and Period of GPT0 PWM */

   R_GPTA0->GTPR = PWM_PERIOD_VALUE;

   R_GPTA0->GTCCRC = PWN_DUTY_0A;

   /* Allow software starting of GPT0 */

   R_GPTA0->GTSSR_b.CSTRT = 1;

   /* Start GPT0 */

   R_GPTA0->GTSTR = 0x00000001;

   /* Set up the OPSCR */

   R_GPT_OPS->OPSCR_b.FB = 1;  /* For demo purposes, input phase from the software settings, not external hardware pins */

   /* Set the phase alignment */

   R_GPT_OPS->OPSCR_b.ALIGN = 1;

   /* Set the phase relationship */

   R_GPT_OPS->OPSCR_b.P = 1;

   R_GPT_OPS->OPSCR_b.N = 1;

   R_GPT_OPS->OPSCR_b.INV = 0;

   /* Enable OPS output */

   R_GPT_OPS->OPSCR_b.EN = 1;

   while(1)

   {

       /* Do nothing */

       /* The values of UF, VF, WF will be modified by the GPT ISR */

   }

}

void cb_timer0(timer_callback_args_t * p_args)

{

   static uint8_t sequence = 0;

   switch( sequence )

   {

       case 0:

       {

           R_GPT_OPS->OPSCR_b.UF = 1;

           R_GPT_OPS->OPSCR_b.VF = 0;

           R_GPT_OPS->OPSCR_b.WF = 1;

           sequence = 1;

           break;

       }

       case 1:

       {

           R_GPT_OPS->OPSCR_b.UF = 1;

           R_GPT_OPS->OPSCR_b.VF = 0;

           R_GPT_OPS->OPSCR_b.WF = 0;

           sequence = 2;

           break;

       }

       case 2:

       {

           R_GPT_OPS->OPSCR_b.UF = 1;

           R_GPT_OPS->OPSCR_b.VF = 1;

           R_GPT_OPS->OPSCR_b.WF = 0;

           sequence = 3;

           break;

       }

       case 3:

       {

           R_GPT_OPS->OPSCR_b.UF = 0;

           R_GPT_OPS->OPSCR_b.VF = 1;

           R_GPT_OPS->OPSCR_b.WF = 0;

           sequence = 4;

           break;

       }

       case 4:

       {

           R_GPT_OPS->OPSCR_b.UF = 0;

           R_GPT_OPS->OPSCR_b.VF = 1;

           R_GPT_OPS->OPSCR_b.WF = 1;

           sequence = 5;

           break;

       }

       case 5:

       {

           R_GPT_OPS->OPSCR_b.UF = 0;

           R_GPT_OPS->OPSCR_b.VF = 0;

           R_GPT_OPS->OPSCR_b.WF = 1;

           sequence = 0;

           break;

       }

       default:

           break;

   }

}

Here is the output I see.

Trace 7 is the GPT0 PWM waveform

Trace 0 - 6 are the OPS U,V,W waveforms


Viewing all articles
Browse latest Browse all 5781

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>