How to program a PWMs using mikroC dsPIC

General discussion on mikroProg™ programmer and debugger and mikroProg Suite software as well.
Post Reply
Author
Message
espoir1976
Posts: 58
Joined: 31 May 2012 19:27

How to program a PWMs using mikroC dsPIC

#1 Post by espoir1976 » 31 May 2012 19:39

Hi every body,

i am now in programming dsPIC using dsPIC, and i try to program a PWMs in the aim to control an inverter using dsPIC 33fj128mc706. I use mikroC_dsPIC and i have this simple program :

void main()
{

PWM1_Init(5000, 0, 1, 0); // Init Pwm1 at 5 kHz
PWM2_Init(5000, 0, 2, 0); // Init Pwm2 at 5 kHz
PWM3_Init(5000, 0, 3, 0); // Init Pwm3 at 5 kHz
PWM1_Start();
PWM2_Start();
PWM3_Start();

while(1)
{
PWM1_Set_Duty(128);
PWM2_Set_Duty(128);
PWM3_Set_Duty(128);
Delay_ms(1000);
}

}

But i have some error like

';' expected but )

Thanks a lot for your help

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: How to program a PWMs using mikroC dsPIC

#2 Post by dejan.odabasic » 01 Jun 2012 10:08

Hello,

could you tell me what is the version of your compiler?

Best regards.

espoir1976
Posts: 58
Joined: 31 May 2012 19:27

Re: How to program a PWMs using mikroC dsPIC

#3 Post by espoir1976 » 01 Jun 2012 16:12

dejan.odabasic wrote:Hello,

could you tell me what is the version of your compiler?

Best regards.
Thank you for reply,

i use MikroC : mikroc.dspic.v4.0.0.0 version

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: How to program a PWMs using mikroC dsPIC

#4 Post by dejan.odabasic » 04 Jun 2012 10:29

Hello,

I suggest you to download and install the latest version (MikroC PRO for dsPIC 5.6)
http://www.mikroe.com/eng/products/view ... for-dspic/

Our PRO line of compilers came out about four years ago.
I could help you with some examples, but I'm using latest version compiler, and many of the old libraries and their functions are drastically changed.

Please try to rewrite your example using new compiler and let me know if you had any success.

Best regards.

espoir1976
Posts: 58
Joined: 31 May 2012 19:27

Re: How to program a PWMs using mikroC dsPIC

#5 Post by espoir1976 » 05 Jun 2012 04:27

dejan.odabasic wrote:Hello,

I suggest you to download and install the latest version (MikroC PRO for dsPIC 5.6)
http://www.mikroe.com/eng/products/view ... for-dspic/

Our PRO line of compilers came out about four years ago.
I could help you with some examples, but I'm using latest version compiler, and many of the old libraries and their functions are drastically changed.

Please try to rewrite your example using new compiler and let me know if you had any success.

Best regards.
Thank you for reply and for the link.

I have goot now a last version of MikroC, and i have written the following project:

unsigned int current_duty, adcRes;
unsigned int pwm_period1;

void main() {

PORTB = 0x0000; // set pin as output
TRISB.F0 = 1; // set pin as input - needed for ADC to work (for ADC1BUF0)
ADC1_Init();

current_duty = 25; // initial value for current_duty


pwm_period1 = PWM_Init(5000, 1, 1, 0);

PWM_Start(1); // Star PWM module 1

while (1) { // endless loop

adcRes = ADC1_Get_Sample(1); // read the new value of ADC

PWM_Set_Duty(adcRes, 1); // set newly acquired duty ratio by the value which is given by ADC
Delay_ms(20);
}
}


I want to know if this project works well.

Best reagrds

espoir1976
Posts: 58
Joined: 31 May 2012 19:27

Re: How to program a PWMs using mikroC dsPIC

#6 Post by espoir1976 » 13 Jun 2012 22:50

Hi every body,

i have succefuly configure ADC and PWM using a last version of MikroC PRO. Now, my question is about how to configure a 3 PWM (with phase shift). Note that my frequency is 60 Hz.

Thank you

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: How to program a PWMs using mikroC dsPIC

#7 Post by dejan.odabasic » 14 Jun 2012 15:28

Hello,

unfortunately phase shifting features are not supported by our library at this moment.
I will pass your interest, related to the phase shift, to our software development team.

Best regards.

espoir1976
Posts: 58
Joined: 31 May 2012 19:27

Re: How to program a PWMs using mikroC dsPIC

#8 Post by espoir1976 » 15 Jun 2012 13:12

dejan.odabasic wrote:Hello,

unfortunately phase shifting features are not supported by our library at this moment.
I will pass your interest, related to the phase shift, to our software development team.

Best regards.
Thank you for your response and your interest for my research works. I await your developments with impatience.

Best regards

Post Reply

Return to “mikroProg™ programmer and debugger”