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.

problem related to overflow in dspic33EP512MU810

Status
Not open for further replies.

kappa_am

Full Member level 6
Joined
Jul 16, 2012
Messages
331
Helped
19
Reputation
38
Reaction score
19
Trophy points
1,298
Location
Vancouver
Activity points
3,859
Hi all,
Recently, I have been working on inverter controlled by dspic33EP512MU810. I was updating angle of output voltage using following code
Code:
 void Timer1Int() iv IVT_ADDR_T1INTERRUPT {            //Voltage vector rotation
  T1IF_bit = 0;
  if (ROT_DIR==1) FTHETA = (float) FTHETA + (float) DELTHETA;
   else FTHETA = (float) FTHETA - (float) DELTHETA;
  THETA = FTHETA;
  LATD=THETA;}
ROT_DIR is direction of rotation, FTHETA is voltage angle in float format and THETA voltage angle in integer format. 0xFFFF=360 degree. After a wile depending of output votage ferequency, THETA does not get updated first some bits of less significant byte and after some extra time is elapsed whole THETA gets equal to 0xFFFF and does not get any update.

I changed the code to
Code:
 void Timer1Int() iv IVT_ADDR_T1INTERRUPT {            //Voltage vector rotation
  T1IF_bit = 0;
  if (ROT_DIR==1) FTHETA = (float) FTHETA + (float) DELTHETA;
  else FTHETA = (float) FTHETA - (float) DELTHETA;
  if (FTHETA>65535) FTHETA=FTHETA-65535;
   if (FTHETA<0) FTHETA=65535-FTHETA;
  THETA = FTHETA;
  LATD=THETA;}
and it seems it works good. I am wondering what is wrong with first updating method. how overflow affects the procedure and cause the weird behavior?

Thank you for your response
 
Last edited:

Hi,

if (FTHETA<0)
Seems that FTHETA is specified as signed int16 (with a decimal range of -32768 ....+32767)

FTHETA=65535-FTHETA
But here you use it as unsigned int16 (with a decimal range of 0...65535)

Klaus
 

KlausSt, Thank you for your response. Actually, FTHETA is float specified as a float. The second one works perfectly. My question is about the first routine. when I do not include these two lines the results go wrong after a few minutes depending on output voltage frequency. Please see the following pictures. I don't know why this occures!

PORTD shows THETA. As you see after a few second first bit does not get updated, anymore. After several seconds the number of the bits that did not get updated increase, and finally after some minutes none of the bits gets updated.
by adding those two line shown in the second program, the problem is solved. In spite of that, I would like to know why this phenomenon is happening.

Thanks

IMG_20170629_151341535_TOP.jpg
IMG_20170629_151343058.jpg
IMG_20170629_151512030.jpg
IMG_20170629_151624121.jpg
 

1. FTHETA is always incremented - is the value ever unwound or reset elsewhere? If not, after some interval of time (depending on frequency of interrupt and DELTA, it may eventually saturate or overflow.
2. Your decimal constants in the added if() expressions *may* be getting promoted to float for comparison to the float, which may or may not be the actually desired behavior.

I think all this code example really demonstrates is that you need to periodically "unwind" FTHETA in a properly controlled manner. This is relying on C compiler language promotions which may work one way or another depending upon the compiler settings used, etc.

Have the compiler generate intermediate assembly language listing and study what is going on.
 

Dear ftsolutions, thank you for your response.Actually, FTHETA is never reset. my question is that THETA itself overflow every cycle ( output voltage cycle, 5ms). why it does not lead to trap? another question is float is 32-bit variable up to 6.8*10^38, considering DELTETA,.... it should be saturated in longer time. The third question is why this kind of behavior? I mean first control of a few least significant bits are lost then higher bits and at last saturation. why not strightforward to saturation? I am confused!!!
 

Using a float variable for a continuously incremented quantity is a really bad idea. It can possibly run into a float overflow exception, but before this happens, it most like gets stuck at a constant value due to the resolution reduction.

Looks like you never considered the behavior of float data type.

Why not using a reasonable scaled fixed point variable for theta as everyone does? E.g. unsigned scaled to 0..360° respectively signed to -180..+180°.
 

Thank you for your explanation,
unfortunately, although I used scaling method in modulation and some other subroutines, I cannot use that method for Theta determination. Because DELTHETA is a function of some parameters (output frequency and switching frequency). Since output frequency is variable in continus form DELTHETA can take any value and rounding it cause lots of error as time goes by.
 

The considerations don't make sense to me. Reasonably scaled fixed point arithmetic can achieve better accuracy than float.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top