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

Compilation problem with 30F5015

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



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

Compilation problem with 30F5015
PostPosted: Mon Nov 17, 2014 5:22 am     Reply with quote

Greetings! I`m using MPLab v8.91, CCS v 5.025 and dsPIC30F5015. I`m trying to use the pwm channels. Here is my code:
Code:

#include <30F5015.h>
#FUSES HS2_PLL16,NOWDT,NOPUT
#device ADC=10
#use delay(clock=80M)

#INT_PWM1
void SetPvm()
{
}

void main()
{
   delay_ms(100);
   setup_motor_pwm(1,MPWM_FREE_RUN|MPWM_UP_DOWN_WITH_INTS,1,1,2500);
   setup_motor_pwm(2,MPWM_FREE_RUN|MPWM_UP_DOWN_WITH_INTS,1,1,2500);
   setup_motor_pwm(3,MPWM_FREE_RUN|MPWM_UP_DOWN_WITH_INTS,1,1,2500);
   setup_motor_pwm(4,MPWM_FREE_RUN|MPWM_UP_DOWN_WITH_INTS,1,1,2500);
   set_motor_unit(1,1,MPWM_ENABLE_H|MPWM_INDEPENDENT|MPWM_FAULTA_LI_HI|MPWM_FAULTB_LI_HI,50,50);
   set_motor_unit(1,2,MPWM_ENABLE_L|MPWM_INDEPENDENT|MPWM_FAULTA_LI_HI|MPWM_FAULTB_LI_HI,50,50);
   set_motor_unit(1,3,MPWM_ENABLE_H|MPWM_INDEPENDENT|MPWM_FAULTA_LI_HI|MPWM_FAULTB_LI_HI,50,50);
   set_motor_unit(1,4,MPWM_ENABLE_L|MPWM_INDEPENDENT|MPWM_FAULTA_LI_HI|MPWM_FAULTB_LI_HI,50,50);
   set_motor_pwm_duty(1,1,3875);
   set_motor_pwm_duty(1,2,3875);
   set_motor_pwm_duty(1,3,3875);
   set_motor_pwm_duty(1,4,3875);
   ENABLE_INTERRUPTS(INTR_GLOBAL);
   enable_interrupts(INT_PWM1);
   while(1)
   {   
   }
}



The problem is these isn`t only one half-channel active. For example in this situation the both low and high pins of channel 3 are active! Channels 1 and 2 are OK. On simulation everything is fine, but when load it to the controller. It seems the MPWM_ENABLE command are inverted. Can you tell me how can I fix this or I have to start loading the registers manually?
It seems to me the values for mode change are not correct!
Thanks!
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Nov 17, 2014 6:28 am     Reply with quote

don't use that PIC but...

Providing the PIC really runs the '1Hz LED' test program, I'd dump the listing and confirm/deny that the correct bits are being set/cleared by the compiled code.

Perhaps the compiler or PIC defaults another peripheral to those pins?

Also just setup one PWM channel at a time,confirm it works, then add another and repeat the process.

hth
jay
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Mon Nov 17, 2014 7:33 am     Reply with quote

The oscillator is OK and the controller is working fine. I`ve tried to setup the channel 1 by 1, but everytime when I reach 3 the problems starts!
Any ideas?!

On simulation everything is fine, but on the pcb ... I`ve compared the registers and there are significant differences!
How can I reach the code of this functions - setup_motor_pwm(), set_motor_unit(), set_motor_pwm_duty(). I want to make changes to this code if it`s possible!
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Sat Dec 06, 2014 1:29 am     Reply with quote

Greetings! I have a problem! As you can see I`m using MPWM_UP_DOWN_WITH_INTS mode. This means the pwm module triggers the interrupt twice - on the raising edge and on the falling edge. I need a way to determine in with state the interrupt is trigger. How can I achieve this?
For my app I need to change the active halves of the pwm outputs and it has to be done in the falling part of the pulse.
It`s very important.
Thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Sat Dec 06, 2014 2:29 am     Reply with quote

Don't use UP_DOWN_WITH_INTS.....

You are making things harder for yourself. This is the 'double update' mode (section 15.1.4 in the data sheet), which interrupts on each half cycle.

Switch to MPWM_UP_DOWN

This still generates an interrupt, but just one per cycle, instead of two. Arrange the polarity of your signals, so that this is the point where you want to update.
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Sat Dec 06, 2014 5:35 am     Reply with quote

No! This doesn`t work for me. I need 2 interrupts because I need to change the value twice per period - in the first half and in the second!
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Sat Dec 06, 2014 8:42 am     Reply with quote

If you want to know what half cycle you are in, then read the PTDIR bit. That's what it's for.
Code:

#BIT PTDIR=getenv("BIT:PTDIR")

   if (PTDIR) //here in the down count

   else //here in the up count
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Thu Dec 11, 2014 6:01 am     Reply with quote

There is something wrong! The bit (PTDIR) never goes high. On simulation everything is OK, but when I load the program into the controller and run the debugger ... The PTMR register is counting always upwards and its value stays above 30000. On simulation PTMR value is low(counting from 0) when it`s counting upward. When it`s counting downwards the value is 36000.
With the debugger this is not so! Is it possible the debugger to return false register values?
Help, please!
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Thu Dec 11, 2014 7:06 am     Reply with quote

What debugger?.
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Thu Dec 11, 2014 10:15 am     Reply with quote

Assuming something like the PicKit, a look at the limitations finds that there may be problems above 15MIPS with register watches.
Try running at a low clock rate, and see if the bit then handles properly.
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