Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Current Protection issue in BLDC motor

Status
Not open for further replies.
Hello Easyrider,KluasST,C_mintra, all others,

Please find the attached code for review.

Code:
/***********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws. 
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIESREGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT.  ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability 
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the 
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2011, 2017 Renesas Electronics Corporation. All rights reserved.
***********************************************************************************************************************/

/***********************************************************************************************************************
* File Name    : r_main.c
* Version      : CodeGenerator for RL78/G14 V2.05.00.03 [05 May 2017]
* Device(s)    : R5F104BA
* Tool-Chain   : CA78K0R
* Description  : This file implements main function.
* Creation Date: 04/09/2017
***********************************************************************************************************************/

/***********************************************************************************************************************
Pragma directive
***********************************************************************************************************************/
/* Start user code for pragma. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */

/***********************************************************************************************************************
Includes
***********************************************************************************************************************/
#include "r_cg_macrodriver.h"
#include "r_cg_cgc.h"
#include "r_cg_port.h"
#include "r_cg_adc.h"
#include "r_cg_timer.h"
/* Start user code for include. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
#include "r_cg_userdefine.h"

/***********************************************************************************************************************
Global variables and functions
***********************************************************************************************************************/
/* Start user code for global. Do not edit comment generated here */
//changable
/*#define B1  TRDGRB1
#define B2  TRDGRC1
#define B3  TRDGRD1*/
//#define DMx 4000



#define U1 P1.5
#define U2 P1.6
#define U3 P1.4
#define prd 4000
boolean pA,pB,pC,set,state,dir,stop,load,cc,bb,aa,volt,set1,ft,chak;
unsigned char amit_pos,reduce;
unsigned int ducycle,i,j,count,amit_adc,count1,current,voltage,todecide,abc,vcnt,ccnt,deccnt,dirc;
extern void dutychange(unsigned char,unsigned int);


void dclock(unsigned char *seq)
{
 switch(*seq)
 {
  case 5:
  U1=1;U2=0;U3=0;
  dutychange(2,ducycle);
  break;
  case 1:
  U1=1;U2=0;U3=0;
  dutychange(3,ducycle);
  break;
  case 3:
  U1=0;U2=1;U3=0;
  dutychange(3,ducycle);
  break;
  case 2:
  U1=0;U2=1;U3=0;
  dutychange(1,ducycle);
  break;
  case 6:
  U1=0;U2=0;U3=1;
  dutychange(1,ducycle);
  break;
  case 4:
  U1=0;U2=0;U3=1;
  dutychange(2,ducycle);
  break;
 }
}

void danticlock(unsigned char *seq)
{
 switch(*seq)
 {
  case 3: //0x02,0x04,0x06,0x01,0x03,0x05,
  U1=1;U2=0;U3=0;
  dutychange(2,ducycle);
  break;
  case 2:
  U1=1;U2=0;U3=0;
  dutychange(3,ducycle);
  break;
  case 6:
  U1=0;U2=1;U3=0;
  dutychange(3,ducycle);
  break;
  case 4:
  U1=0;U2=1;U3=0;
  dutychange(1,ducycle);
  break;
  case 5:
  U1=0;U2=0;U3=1;
  dutychange(1,ducycle);
  break;
  case 1:
  U1=0;U2=0;U3=1;
  dutychange(2,ducycle);
  break;
 }
}





void run()
{
          ADS=3;
	 for(i=0;i<=100;i++);
	   amit_adc = (ADCR >> 6);
	   
      //softstart
	   todecide=amit_adc*4;
	  if(todecide>=(prd-20)){todecide=prd-20;}  
	  
	  abc++;
	  if(abc>=50)
	  {
	   abc=0;
	   {
		  if(todecide>=ducycle){ducycle=ducycle+5;}
		  if(todecide<ducycle){ducycle=ducycle-5;}
	   }
          } 
  
  if((chak==0)&&(ft==0))
    {
    amit_pos=P6;
	   
		    if((amit_pos==7)||(amit_pos==0))
		     {
		      amit_pos=1;
		       
		     }	     
	    }
    if(state==0)danticlock(&amit_pos);
    else dclock(&amit_pos);
    }
  


void Dev_Init()
{
 ducycle=todecide=0;
 R_TMR_RD1_Start();
 R_ADC_Start();
}
/* End user code. Do not edit comment generated here */
void R_MAIN_UserInit(void);

/***********************************************************************************************************************
* Function Name: main
* Description  : This function implements main function.
* Arguments    : None
* Return Value : None
***********************************************************************************************************************/
void main(void)
{

  	R_MAIN_UserInit();
    /* Start user code. Do not edit comment generated here */
    U1=0;U2=0;U3=0;
    for(i=0;i<=60000;i++);
    for(i=0;i<=60000;i++);
    for(i=0;i<=60000;i++);
    for(i=0;i<=60000;i++);
    for(i=0;i<=60000;i++);
    for(i=0;i<=60000;i++);
    for(i=0;i<=2500;i++)
    {
     for(j=0;j<=6000;j++);
    }  //////////////
    
    while (1U)
    {
      run();
     
    }
    /* End user code. Do not edit comment generated here */
}

/***********************************************************************************************************************
* Function Name: R_MAIN_UserInit
* Description  : This function adds user code before implementing main function.
* Arguments    : None
* Return Value : None
***********************************************************************************************************************/
void R_MAIN_UserInit(void)
{
    /* Start user code. Do not edit comment generated here */
    EI();
    Dev_Init();
    if(P3.1==1)state=0;
    else state=1;
    /* End user code. Do not edit comment generated here */
}

/* Start user code for adding. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */


If any doubt or difficulty, please ask me. I am using Renesas Controller.
 

Hi,

dutychange(2,ducycle);

This function is used change the duty cycle.The number 2 defines which bottom mosfet to trigger and ducycle assigns duty cycle.

Awaiting for your reply.
 

Anything wrong with the code?

- - - Updated - - -

The issue is still pending. Everytime motor needs initial start up by hand then motor is properly working. I am also getting good torque. But the issue is in first start.

Awaiting for your reply.

All guys please reply me.
 

I see you start ducycle with zero; where it is getting incremented?

Your program is not having much comments; it is very unreadable.
 

I will post properly commented code tomorrow. Meanwhile please go through the code . Whatever you are not getting I will try to explain in the deep.
 

What are all the for loops doing in the main subroutine? just generating a delay?

In the R_main_User_Init you make a call to EI(); what it is doing?
 
Last edited:

Hello C_mintra,

thanks for the doubts.

All for loops are generating delay. This delay is just for protection. Some Power supplies probably won't give 12V directly when power ON. They are like 2V.....3V......7V......10V....12V after power ON. That is why delay is added.

EI(); is the enable interrupt function. For Renesas Controllers, we have to use this function.
 

There is some problem with the softstart part; please take a look.

Which compiler you are using? Is the compiler giving any error?

some variables that are never used but defined; they may be removed. Some variables are not passed on properly. They need to be made global. Are all the header files needed? I shall take another look later.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top