![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
Compilation problem with 30F5015 |
Posted: Mon Nov 17, 2014 5:22 am |
|
|
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! |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9176 Location: Greensville,Ontario
|
|
Posted: Mon Nov 17, 2014 6:28 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Mon Nov 17, 2014 7:33 am |
|
|
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! |
|
![](templates/subSilver/images/spacer.gif) |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Sat Dec 06, 2014 1:29 am |
|
|
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! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19375
|
|
Posted: Sat Dec 06, 2014 2:29 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Sat Dec 06, 2014 5:35 am |
|
|
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! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19375
|
|
Posted: Sat Dec 06, 2014 8:42 am |
|
|
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
|
|
|
![](templates/subSilver/images/spacer.gif) |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Thu Dec 11, 2014 6:01 am |
|
|
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! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19375
|
|
Posted: Thu Dec 11, 2014 7:06 am |
|
|
What debugger?. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19375
|
|
Posted: Thu Dec 11, 2014 10:15 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|