Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ADC sync with PWM failure :(

Status
Not open for further replies.

hotring

Newbie level 2
Joined
Jan 30, 2012
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,313
Hi guys! I am an electronic engineer student and it's the first time I write here!

I am trying to do a project very similar to the app note AN1078 - Sensorless Field Oriented Control of a PMSM Motor.

I'm using a dsPIC30F6015 from Microchip. I'm configuring my ADC in order to trigger with PWM signals and the frequency that my program enter in the ADC interrupt is 4 times lower than the PWM frequency, instead of being with the same frequency.

Anyone knows what's the problem? I've lost a lot of time and I can't get it, but it seems to me that it can be a easy and simple stupid mistake :(
 

The interrupt has a postscaler, the SEVOPS bits in the PWMCON2 control register.
Could this be your problem?
 
The interrupt has a postscaler, the SEVOPS bits in the PWMCON2 control register.
Could this be your problem?

Thanks for your reply ;)

Unfortunately, I have it selected as 0 (0000 = 1:1 Postscale). It's right, isn't it?!

The Adc trigered with the pwm signals should call the ADC interruption in the middle of the period of the pwm signal, right? I can't find information about it...

---------- Post added 31-01-12 at 00:03 ---------- Previous post was 30-01-12 at 23:58 ----------

My PWM init code:

void PWM_init(void) {

// Initialize the PWM Module
PTPER = ((FCY/FPWM) - 1 ) >> 1; // Compute Period for desired frequency
OVDCON = 0x0000; // Disable all PWM outputs
DTCON1 = 0x0000; // Dead Time = 0
DTCON1 = 0.000002 * FCY;
PWMCON1 = 0x00EE; //Enable PWM Pins and enable complementary mode
PWMCON2 = 0x0011;
PDC2 = PTPER; // initial value = 0 Volts
PDC3 = PTPER; // initial value = 0 Volts
PDC4 = PTPER; // initial value = 0 Volts

IFS2bits.PWMIF = 0; // Clear PWM interrupt flag
IEC2bits.PWMIE = 1; // Enable PWM interrupt

OVDCON = 0xFC00; // PWM outputs are controller by PWM module

PTCONbits.PTMOD= 2 ; // Center aligned PWM operation

PTCONbits.PTEN = 1; // Start PWM

}

And my ADC init code:


void ADC_init(void)
{

ADCON1 = 0;
// Signed fractional (DOUT = sddd dddd dd00 0000)
ADCON1bits.FORM = 3;
// Motor Control PWM interval ends sampling and starts conversion
ADCON1bits.SSRC = 3;
// Simultaneous Sample Select bit (only applicable when CHPS = 01 or 1x)
// Samples CH0, CH1, CH2, CH3 simultaneously (when CHPS = 1x)
// Samples CH0 and CH1 simultaneously (when CHPS = 01)
ADCON1bits.SIMSAM = 1;
// Sampling begins immediately after last conversion completes.
// SAMP bit is auto set.
ADCON1bits.ASAM = 1;


ADCON2 = 0;
// Samples CH0, CH1, CH2, CH3 simultaneously (when CHPS = 1x)
ADCON2bits.CHPS = 2;


ADCON3 = 0;
// A/D Conversion Clock Select bits = 8 * Tcy
ADCON3bits.ADCS = 15;


/* ADCHS: ADC Input Channel Select Register */
ADCHS = 0;
// CH0 is AN7 - MUDEI PARA O 10
ADCHSbits.CH0SA = 10;
// CH1 positive input is AN0, CH2 positive input is AN1, CH3 positive input is AN2
ADCHSbits.CH123SA = 0;


/* ADPCFG: ADC Port Configuration Register */
// Set all ports digital
ADPCFG = 0xFFFF;
ADPCFGbits.PCFG0 = 0; // AN0 analog
ADPCFGbits.PCFG1 = 0; // AN1 analog
ADPCFGbits.PCFG2 = 0; // AN2 analog
ADPCFGbits.PCFG10 = 0; // AN7 analog - MUDEI PARA O 10

/* ADCSSL: ADC Input Scan Select Register */
ADCSSL = 0;

// Turn on A/D module
ADCON1bits.ADON = 1;

return;

}
 

You can set when the adc is triggered using the SEVTCMP register.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top