caramoan tour package

caramoan tour package

Author Topic: need help sa pagdebug ng dspic30f4011  (Read 293 times)

Offline studyante

  • Size AA Battery
  • ****
  • Posts: 105
  • Pogi/Ganda Points: 0
need help sa pagdebug ng dspic30f4011
« on: March 07, 2011, 05:22:12 PM »
gamit ko po ay mikroc for dspic. kapag nagiinitialize ako ng pwmmc module ng mikroc tapos naginitialize din ako ng timer pagkatapos either yung pwm or yung timer ang hindi gagana. di ko madebug kung bakit ganun ang nangyayari

Philippine Electronics Forum

need help sa pagdebug ng dspic30f4011
« on: March 07, 2011, 05:22:12 PM »

Offline motion55

  • Technical People
  • Diesel Generator
  • *****
  • Posts: 1878
  • Pogi/Ganda Points: 243
  • Gender: Male
  • Been at this longer than you've been alive.
Re: need help sa pagdebug ng dspic30f4011
« Reply #1 on: March 08, 2011, 06:06:48 AM »
Looks like may conflict sa dalawang modules. Sorry but I am not familiar with the mikroc compiler and so I can't help.

Have you tried using Microchip's C30 compiler? I am using that compiler on a dsPIC33 project and I don't have problem with it.
"Set your mind free!"

Philippine Electronics Forum

Re: need help sa pagdebug ng dspic30f4011
« Reply #1 on: March 08, 2011, 06:06:48 AM »

Offline studyante

  • Size AA Battery
  • ****
  • Posts: 105
  • Pogi/Ganda Points: 0
Re: need help sa pagdebug ng dspic30f4011
« Reply #2 on: March 08, 2011, 07:41:27 AM »
sir i tried using mplab c30 tapos nung sinimulate ko using mplab sim yung port na nagchachange every timer interrupt ay hindi fixed yung period..kapag magkasabay po sila ng pwm module ganun po nangyayari pero kapag naka-off naman yung pwm module ay maayos naman yung period nung timer ko..di ko po alam gagawin..

Philippine Electronics Forum

Re: need help sa pagdebug ng dspic30f4011
« Reply #2 on: March 08, 2011, 07:41:27 AM »

Offline studyante

  • Size AA Battery
  • ****
  • Posts: 105
  • Pogi/Ganda Points: 0
Re: need help sa pagdebug ng dspic30f4011
« Reply #3 on: March 08, 2011, 10:54:44 AM »
eto po yung code ko para sa paginitialize ng timer at pwmmc

Code: [Select]
#include <p30f4011.h>
_FOSC(CSW_FSCM_OFF & XT);
_FWDT( WDT_OFF );
_FBORPOR( PBOR_OFF & BORV_45 & MCLR_EN );
_FGS( CODE_PROT_OFF );

#define Fosc 8000000
#define Fcy Fosc/4
#define Fpwm 640
#define Deadtime 2

//pwmmc variables
int index1 = 0, index2 = 11, index3 = 21;
static float sine_table[32] = { 1.00,0.80,0.62,0.44,0.30,0.16,0.08,0.02,
                                0.00,0.02,0.08,0.16,0.30,0.44,0.62,0.80,
                                1.00,1.20,1.38,1.56,1.70,1.84,1.92,1.98,
                                2.00,1.98,1.92,1.84,1.70,1.56,1.38,1.20 };


void __attribute__((__interrupt__)) _PWMInterrupt( void ){
//increment indeces
    index1++;
    index2++;
    index3++;
    //reset indeces
    if(index1 == 32)   index1 = 0;
    if(index2 == 32)   index2 = 0;
    if(index3 == 32)   index3 = 0;
    //update PWM duty cycles
PDC1 = (sine_table[index1]*PTPER);
PDC2 = (sine_table[index2]*PTPER);
PDC3 = (sine_table[index3]*PTPER);
IFS2bits.PWMIF = 0;
}

void pwmmc_init(void){
TRISE = 0x0100; // PWM pins as outputs, and FLTA as input
PTPER = (Fcy/Fpwm - 1) >> 1; // Compute Period for desired frequency
OVDCON = 0x0000; // Disable all PWM outputs.
DTCON1 = Deadtime; // ~2 us of dead time @ 20 MIPS and 1:1 Prescaler
PWMCON1 = 0x0077; // Enable PWM output pins and enable complementary mode
PDC1 = (sine_table[index1]*PTPER);
PDC2 = (sine_table[index2]*PTPER);
PDC3 = (sine_table[index3]*PTPER);
IFS2bits.PWMIF = 0; // Clear PWM Interrupt flag
IEC2bits.PWMIE = 1; // Enable PWM Interrupts
OVDCON = 0x3F00; // PWM outputs are controller by PWM module
PTCONbits.PTMOD = 2; // Center aligned PWM operation
PTCONbits.PTEN = 1; // Start PWM
}

void __attribute__((__interrupt__)) _T1Interrupt( void ){
LATBbits.LATB3 = ~LATBbits.LATB3;
  IFS0bits.T1IF = 0; // Clear timer 1 interrupt flag
}

void timer1_init(void){
TMR1 = 0; // Reset timer counter
T1CONbits.TON = 0; // Turn off timer 1
T1CONbits.TSIDL = 0; // Continue operation during sleep
T1CONbits.TGATE = 0; // Gated timer accumulation disabled
T1CONbits.TCS = 0; // use Tcy as source clock
T1CONbits.TCKPS = 0;
PR1 = 500;
        IFS0bits.T1IF = 0; // Clear timer 1 interrupt flag
IEC0bits.T1IE = 1; // Enable timer 1 interrupts
T1CONbits.TON = 1; // Turn on timer 1
}

int main(void){
        pwmmc_init();
ADPCFG = 0xFFFF;
TRISBbits.TRISB3 = 0;
LATBbits.LATB3 = 0;
timer1_init();
while(1);
return 0;
}





Philippine Electronics Forum

Re: need help sa pagdebug ng dspic30f4011
« Reply #3 on: March 08, 2011, 10:54:44 AM »

Offline studyante

  • Size AA Battery
  • ****
  • Posts: 105
  • Pogi/Ganda Points: 0
Re: need help sa pagdebug ng dspic30f4011
« Reply #4 on: March 09, 2011, 12:57:44 AM »
gusto ko po sana ng 50khz na timer na may kasabay na 6.4kHz na MCPWM kaso hindi po sila nagsasabay. either wala sila pareho or may isa lang na gumagana kapag initialize ko na yung dalawang module.. di ko parin siya mapagana hanggang ngayon.

Philippine Electronics Forum

Re: need help sa pagdebug ng dspic30f4011
« Reply #4 on: March 09, 2011, 12:57:44 AM »

Offline motion55

  • Technical People
  • Diesel Generator
  • *****
  • Posts: 1878
  • Pogi/Ganda Points: 243
  • Gender: Male
  • Been at this longer than you've been alive.
Re: need help sa pagdebug ng dspic30f4011
« Reply #5 on: March 09, 2011, 05:34:45 AM »
Sorry been very busy for the past few days. Walang time to look at your code to find the exact cause but I find a few possible problems.

Your sine table is a table of float numbers. The PIC does not have a math coprocessor. To calculate "PDC1 = (sine_table[index1]*PTPER);" will take a lot of CPU cycles. That is not good to do within an interrupt service routine. What it has is a hardware multiplier. It is best to use a table of 16-bit integers for the sine table. Better yet, since the value of PTPER is fixed, all calculations can be done during compile time and not during runtime to save on CPU cycles. Bale kung pre calculated siya, simply get the values from the sine table and copy to PDC1, PDC2 and PDC3.



"Set your mind free!"

Offline studyante

  • Size AA Battery
  • ****
  • Posts: 105
  • Pogi/Ganda Points: 0
Re: need help sa pagdebug ng dspic30f4011
« Reply #6 on: March 09, 2011, 07:47:48 AM »
Sorry been very busy for the past few days. Walang time to look at your code to find the exact cause but I find a few possible problems.

Your sine table is a table of float numbers. The PIC does not have a math coprocessor. To calculate "PDC1 = (sine_table[index1]*PTPER);" will take a lot of CPU cycles. That is not good to do within an interrupt service routine. What it has is a hardware multiplier. It is best to use a table of 16-bit integers for the sine table. Better yet, since the value of PTPER is fixed, all calculations can be done during compile time and not during runtime to save on CPU cycles. Bale kung pre calculated siya, simply get the values from the sine table and copy to PDC1, PDC2 and PDC3.





Thanks sir..pasensya na po sa abala..ittry ko po na fixed na yung table wrt sa PTPER...may isa pa po akong problema...tnry ko magpablink ng LED on all ports..nakaset naman yung ADPCFG na register as digital tapos yung RB1 port ko ay laging high lang tapos yung RB2 at RB5 ko walang inooutput..sira na po kaya yung ports ko? hindi ko po alam kung paano siya nasira..lagi naman po akong maingat sa pagset ng ADPCFG..yung 3 ports lang po yung hindi nagbblink..

Philippine Electronics Forum

Re: need help sa pagdebug ng dspic30f4011
« Reply #6 on: March 09, 2011, 07:47:48 AM »

 

Privacy Policy

Contact Us: elabph@yahoo.com