CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

30f2010 dead time problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
torlaktr



Joined: 17 Mar 2016
Posts: 10

View user's profile Send private message

30f2010 dead time problem
PostPosted: Fri Mar 18, 2016 1:42 am     Reply with quote

Hello gentlemen

My problem

It gives error

Expression must evaluate to a constant :: DT too high

Why ?


Code:
#include <30f2010.h>
#device ADC=10
#fuses XT_PLL16
#fuses NOWDT
#fuses NOPROTECT
#fuses NOBROWNOUT
#fuses NOPUT
#fuses NOWRT
#fuses NODEBUG
#fuses PWMPIN
#fuses MCLR
#fuses ICSP1
#use   delay(clock=4000000)

int8 x=0;
int16 dutya = 160;//154

void main(output_drive)
{
setup_motor_pwm(1,MPWM_FREE_RUN  ,1,1,900);
set_motor_unit(1,2,MPWM_ENABLE ,50,50);
set_motor_pwm_duty(1,1,900);
 
basla:

delay_ms(5);

goto basla;
}
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19550

View user's profile Send private message

PostPosted: Fri Mar 18, 2016 3:32 am     Reply with quote

XT_PLL16 and 'clock=4000000', don't really go together. Would imply a crystal at 250KHz.

'main' cannot have a variable received 'by' it. It is always a void function both on it's receipts and returns.

Then a goto loop. Take -50 points. Goto can sometimes be used for very specific programming reasons, but generally a label, and goto, are 'near capital' offences....

Then you have one more closing bracket than opening bracket in the code posted.

The only faults are basic syntax errors:
Code:

#include <30f2010.h>
#device ADC=10
#fuses XT_PLL16
#fuses NOWDT
#fuses NOPROTECT
#fuses NOBROWNOUT
#fuses NOPUT
#fuses NOWRT
#fuses NODEBUG
#fuses PWMPIN
#fuses MCLR
#fuses ICSP1
#use   delay(clock=64MHz) //assuming 4MHz crystal

void main(void)
{
   int8 x=0;
   int16 dutya = 160;//154

   setup_motor_pwm(1,MPWM_FREE_RUN  ,1,1,900);
   set_motor_unit(1,2,MPWM_ENABLE ,50,50);
   set_motor_pwm_duty(1,1,900);
 
   while (TRUE)
      delay_ms(5);
}
torlaktr



Joined: 17 Mar 2016
Posts: 10

View user's profile Send private message

Thank you
PostPosted: Fri Mar 18, 2016 4:40 am     Reply with quote

Dear Ttelmah thank you

But
set_motor_unit(1,2,MPWM_ENABLE ,50,50); very good
Im chance dead time
set_motor_unit(1,2,MPWM_ENABLE ,65,65);

Compiler error : Expression must evaluate to a constant :: DT too high

and then
Im chance dead time
set_motor_unit(1,2,MPWM_ENABLE ,66,66 ); very good

Why not accept 65 ?

and then again Im chance dead time

int8 x = 10;
set_motor_unit(1,2,MPWM_ENABLE ,x,x ); Compiler error : Expression must evaluate to a constant :: DT too high


Why ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 18, 2016 12:16 pm     Reply with quote

The dsPIC30F2010 data sheet says:
Quote:

14.7.1 DEAD-TIME GENERATORS

Each complementary output pair for the PWM module
has a 6-bit down counter that is used to produce the
dead-time insertion. As shown in Figure 14-4, the
dead-time unit has a rising and falling edge detector
connected to the duty cycle comparison output.

14.7.2 DEAD-TIME RANGES

The amount of dead time provided by the dead-time
unit is selected by specifying the input clock prescaler
value and a 6-bit unsigned value.

With 6 bits, you can only get values from 0 to 63. So you could never
get a dead-time of 66 anyway.
Ttelmah



Joined: 11 Mar 2010
Posts: 19550

View user's profile Send private message

PostPosted: Fri Mar 18, 2016 12:54 pm     Reply with quote

Also be aware that the deadtime, is a configuration value, not something that can be changed on the fly.
This is because the PWM has to be stopped before you can update the deadtime. From the data sheet:

"Note: The user should not modify the DTCON1
values while the PWM module is operating
(PTEN = 1). Unexpected results may
occur."
torlaktr



Joined: 17 Mar 2016
Posts: 10

View user's profile Send private message

Thank you
PostPosted: Sat Mar 19, 2016 11:47 am     Reply with quote

I drive h bridge mosfets ...
but I have to replace dead time
How can I do it ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19550

View user's profile Send private message

PostPosted: Sat Mar 19, 2016 3:04 pm     Reply with quote

You set it up once at the start. Since it is a feature of your hardware (how long is needed to ensure that one set of FETs turns off, before trying to turn the others on, it should never have to change.

If you must change it (perhaps two different hardware configurations), then you must stop the PWM (PWM_OFF), and program it to the second value. However as two distinct fixed setup commands.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group