Pwm dspic 33 and CANbus comunication

Thread Starter

Manuel_Mac

Joined Dec 14, 2012
5
Hi, I'm trying to drive a motor using a dspic33. I'm using PWM to control the motor and CANbus to communicate with PC (that's a school project, I have to use these things). Both pwm and CAN work fine, but when I try to send the duty cycle value with CAN, pwm doesn't work. I've used debugger and that's what i've found:
- CAN buffer is read by DMA
- Firmware read DMA and set the duty cycle register
- DMA buffer is cleared
- PWM module clear the duty cycle register too

That's the main:
while(1)
{
duty=ecan1msgBuf[1][3];
if(duty!=0)
{
P2DC1=duty*100;
}
}

And here pwm initialization:
P2TCONbits.PTEN=0; //bisable pwm
P2TCONbits.PTOPS=0b0000; //postscaler 1:1
P2TCONbits.PTCKPS=0b00; //prescaler 1:1
P2TCONbits.PTMOD=0b00; //freerunning mode
P2TPER=499; //pwm period value bits
P2FLTACONbits.FAEN1=0;
PWM2CON1bits.PEN1H=0;
PWM2CON1bits.PEN1L=1;
PWM2CON1bits.PMOD1=1;
PWM2CON2bits.IUE=0;
PWM2CON2bits.OSYNC=0;
PWM2CON2bits.UDIS=0;
P2DC1=0;
P2OVDCONbits.POVD1H=0;
P2OVDCONbits.POVD1L=1;
P2TCONbits.PTEN=1;
 

ErnieM

Joined Apr 24, 2011
8,415
By "work fine" I assume you have some way to see that pwm and CAN both are working by themselves?

Make a debug build and drop a breakpoint where the code detects a CAN reception, and track what actually gets received, how it is handled, and where it goes.
 

Thread Starter

Manuel_Mac

Joined Dec 14, 2012
5
Yes, they both workby themself.

The only thing I can see using debugger is that once DMA is cleared, Duty cycle register is cleared too.

I'va also tried to use this firmware:

while(1)
{
P2DC1=500;
}

pwm works until DMA register is cleared, than duty cycle is set to zero and then is set to 500.
 
Top