|
|
View previous topic :: View next topic |
Author |
Message |
af19
Joined: 21 Aug 2014 Posts: 15
|
[SOLVED]Motor pwm pair 3 not working |
Posted: Sun Feb 01, 2015 8:28 am |
|
|
I'm working with dspic33fj16mc102
I want to use motor pwm unit to make 3 phase pwm.
here is my code.
Code: |
#include <33FJ16MC102.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#device ICSP=1
#use delay(crystal=8MHz)
#DEFINE PHASE_SHIFT_120 0X5555
#DEFINE PHASE_SHIFT_240 0XAAAA
int SineTable[256]={0, 5, 10, 15, 20, 24, 29, 34, 39, 44, 48, 53, 58, 62, 67, 72, 76, 81, 85, 89, 94, 98, 102, 106, 111, 115, 119, 122, 126, 130, 134, 137, 141, 144, 147, 151, 154, 157, 160, 163, 165, 168, 171, 173, 176, 178, 180, 182, 184, 186, 187, 189, 190, 192, 193, 194, 195, 196, 197, 198, 198, 198, 199, 199, 199, 199, 199, 198, 198, 198, 197, 196, 195, 194, 193, 192, 190, 189, 187, 186, 184, 182, 180, 178, 176, 173, 171, 168, 165, 163, 160, 157, 154, 151, 147, 144, 141, 137, 134, 130, 126, 122, 119, 115, 111, 106, 102, 98, 94, 89, 85, 81, 76, 72, 67, 62, 58, 53, 48, 44, 39, 34, 29, 24, 20, 15, 10, 5, 0, -5, -10, -15, -20, -24, -29, -34, -39, -44, -48, -53, -58, -62, -67, -72, -76, -81, -85, -89, -94, -98, -102, -106, -111, -115, -119, -122, -126, -130, -134, -137, -141, -144, -147, -151, -154, -157, -160, -163, -165, -168, -171, -173, -176, -178, -180, -182, -184, -186, -187, -189, -190, -192, -193, -194, -195, -196, -197, -198, -198, -198, -199, -199, -199, -199, -199, -198, -198, -198, -197, -196, -195, -194, -193, -192, -190, -189, -187, -186, -184, -182, -180, -178, -176, -173, -171, -168, -165, -163, -160, -157, -154, -151, -147, -144, -141, -137, -134, -130, -126, -122, -119, -115, -111, -106, -102, -98, -94, -89, -85, -81, -76, -72, -67, -62, -58, -53, -48, -44, -39, -34, -29, -24, -20, -15, -10, -5};
int16 i = 0;
int16 Phase1,Phase2,Phase3,Temp1,Temp2,Temp3;
#INT_PWM1
void pwm1_isr(void)
{
if (i>=0XFFFF)
i=0;
i += 328;
}
void main()
{
setup_motor_pwm(1,MPWM_FREE_RUN,1,1,199);
set_motor_unit(1,1,MPWM_ENABLE,4,4);
set_motor_unit(1,2,MPWM_ENABLE,4,4);
set_motor_unit(1,3,MPWM_ENABLE,4,4);
OUTPUT_HIGH(PIN_A0);
enable_interrupts(INT_PWM1);
enable_interrupts(INTR_GLOBAL);
while(TRUE)
{
Temp1 = i;
Temp2 = i + PHASE_SHIFT_120;
Temp3 = i + PHASE_SHIFT_240;
Phase1 = (Temp1)>>8;
Phase2 = (Temp2)>>8;
Phase3 = (Temp3)>>8;
set_motor_pwm_duty(1,1,SineTable[Phase1]+199);
set_motor_pwm_duty(1,2,SineTable[Phase2]+199);
set_motor_pwm_duty(1,3,SineTable[Phase3]+199);
//TODO: User Code
}
}
|
my problem is that the third pwm pair is not working.
PWM1H3 (PIN RB10) is always 0 V and PWM1L3 (PIN RB11) is always 2.5 V
I cant change this pins state either. I tried OUTPUT_HIGH() and OUTPUT_LOW() to change this pins state but they didnt work. i think something is preventing these pins to work.
other PWM Pins such as PWM1L1,PWM1H1,PWM1L2 and PWM1H2 work properly and i can get PWM from these pins.
I dont know what is the problem. i changed my microcontroller too, but the problem exist.
Any suggestion?
PCB Design
Last edited by af19 on Tue Feb 03, 2015 2:20 pm; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Sun Feb 01, 2015 8:36 am |
|
|
While I don't use that PIC....
..what other peripherals can those pins control? The 'default' might be another peripheral , so PWM won't work...
The fact that output_high() doesn't work..hmm..are those pins used for an ICD or Debug module ??
I'd go back to the '1 HZ LED' program... to test and get those 2 pins running right....
I know 1 step forward, 2 back...BUT.. heck, that's PIC101 !
Jay |
|
|
af19
Joined: 21 Aug 2014 Posts: 15
|
|
Posted: Sun Feb 01, 2015 8:57 am |
|
|
Quote: | The fact that output_high() doesn't work..hmm..
are those pins used for an ICD or Debug module ??
|
Thank you for your Reply.
I tested led 1HZ LED Program too, but it didnt work.
These PINS are not debug PINS, debug pins are B0 and B1.
Here is the microcontroller picture.
do you have any suggestion? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Sun Feb 01, 2015 9:10 am |
|
|
Not getting the 1Hz LED program to work ..arrgh....
It should work for any and all I/O pins.
You've got to sort that out before you proceed....
hmm. if this PIC has 'configurable' I/O pins, that could be the issue. Do you need 'pin_select' at all ?
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Sun Feb 01, 2015 9:11 am |
|
|
I'd suggest adding:
MPWM_FAULT_NO_CHANGE
The motor PWM wakes with _both_ fault inputs triggered. You either need to clear them or they will override the output. Not sure what the default override is, but this may be what you are seeing.
As a comment, the maths in your interrupt doesn't work. an int16, can never be >0xFFFF. It'll appear to work, since the 16bit addition will wrap, but the actual test is not doing anything useful. |
|
|
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
|
af19
Joined: 21 Aug 2014 Posts: 15
|
|
Posted: Sun Feb 01, 2015 9:48 am |
|
|
Thanks for the reply.
Quote: | hmm. if this PIC has 'configurable' I/O pins, that could be the issue. Do you need 'pin_select' at all ? |
I didn't use 'pin_select' for other pins, but i will give this a shot.
What should i write for PWM1H3 and PWM1L3 after the #pin_select?
i checked the datasheet. it seems 'OUTPUT COMPARE Fault A' is on pin B11 too.
What should i write for PWM1H3 and PWM1L3 after the #pin_select?
Quote: | I'd suggest adding:
MPWM_FAULT_NO_CHANGE
The motor PWM wakes with _both_ fault inputs triggered. You either need to clear them or they will override the output. Not sure what the default override is, but this may be what you are seeing.
As a comment, the maths in your interrupt doesn't work. an int16, can never be >0xFFFF. It'll appear to work, since the 16bit addition will wrap, but the actual test is not doing anything useful. |
I will add MPWM_FAULT_NO_CHANGE and i will tell the result. I dont have the programmer right now, I will tell you tomorrow.
Quote: | dspic33fj16mc102 ... well what is your compiler version? |
My compiler version is 5.015, 5967. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Sun Feb 01, 2015 11:22 am |
|
|
The motor PWM, is not one of the relocatable peripherals (I checked that). |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Feb 01, 2015 1:00 pm |
|
|
Quote: |
I tested led 1HZ LED Program too, but it didnt work.
PCB Design
.
.
.
|
Where are the caps on your crystal circuit ? I don't see them, unless
they are on another layer of your board.
Look at this dsPIC33 schematic. It has two 22pf caps on the crystal:
http://www.microchip.com/forums/download.axd?file=0;730810
Put those in, and it will probably start working. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Sun Feb 01, 2015 1:16 pm |
|
|
Good catch PCM P !
I looked at the layout and saw another 'tweak' if the board needs to be changed for the caps.
If C4 is turned 90*, then the -ve can tie into the gnd bus on the bottom. Move the xtal closer to the PIC, then add the 2 22puff caps from the xtal to gnd. If the cap pins are .2 apart then the +ve to C4 can be rerouted through the gap instead of trough pins 8 and 9 of the PIC to pin 13.
Another 'tweak' could be to remap D2 as the 'power LED'. It's result in fewer traces, a bit 'straighter', reducing the chance of 'flash overs'.
Having FOUR traces between PIC pins 1 and 28 kinda scares an old guy like me as well.....
heck, as long as it works though !!
Jay |
|
|
af19
Joined: 21 Aug 2014 Posts: 15
|
|
Posted: Sun Feb 01, 2015 1:17 pm |
|
|
Thanks for the Reply.
Quote: | The motor PWM, is not one of the relocatable peripherals (I checked that). Smile |
Quote: | Where are the caps on your crystal circuit ? I don't see them, unless
they are on another layer of your board. |
I've not putted these caps.
I will give it a try.
Do you think this is the reason of the problem? |
|
|
af19
Joined: 21 Aug 2014 Posts: 15
|
|
Posted: Sun Feb 01, 2015 1:23 pm |
|
|
Quote: | the board needs to be changed for the caps. |
Quote: | Where are the caps on your crystal circuit ? I don't see them, unless
they are on another layer of your board. |
I'm going to test on the breadboard first.
Am I going to need these caps on bread board too? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Sun Feb 01, 2015 3:18 pm |
|
|
just to confirm..
yes, you do need the caps ! If you look in the datasheet section about 'oscillator configurations'.. whenever you use a discrete crystal you MUST have 2 small caps as well. The value of the caps depends on the crystal but generally speaking 22pfd will work.
If you had it 'working' without them, it's due to the 'stray' capacitance of the PCB, wiring,humidity, etc. and , well, you just got lucky it worked.
Jay |
|
|
af19
Joined: 21 Aug 2014 Posts: 15
|
|
Posted: Mon Feb 02, 2015 2:00 am |
|
|
Thanks for the reply.
Quote: | just to confirm..
yes, you do need the caps ! If you look in the datasheet section about 'oscillator configurations'.. whenever you use a discrete crystal you MUST have 2 small caps as well. The value of the caps depends on the crystal but generally speaking 22pfd will work. |
Quote: | Notice caps on crystal on breadboard: |
I changed my micro controller and it is not programmed. but there is still a 2.5 v voltage on PIN B11, output of the micro controller should be 3.3 V and 2.5 v is Vcap voltage. I think there is a problem with my PCB.
I picked up the Micro controller from the board and PIN B11 is 0 V.
I dont know what is the problem. |
|
|
|
|
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
|