chinuhark
Member level 5
I have succesfully done PWM and ADC in the past 2 days and now wanted to do PWM interrupts. I have also successfully done external interrupts using INT0. I wrote the following code for PWM duty cycle control and doing A to D conversions within the PWM1 interrupt (this is just to test PWM interrupt).
I keep getting the following error while building :
PWM Interrupt.c: In function 'main':
PWM Interrupt.c:65:12: error: expected identifier or '(' before '.' token
PWM Interrupt.c:66:10: error: expected identifier or '(' before '.' token
PWM Interrupt.c:67:9: error: expected identifier or '(' before '.' token
PWM Interrupt.c:68:9: error: expected identifier or '(' before '.' token
make[2]: *** [build/default/production/PWM Interrupt.o] Error 255
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
nbproject/Makefile-default.mk:94: recipe for target 'build/default/production/PWM Interrupt.o' failed
make[2]: Leaving directory 'C:/Users/Chinu/MPLABXProjects/PWM Interrupt.X'
nbproject/Makefile-default.mk:78: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/Chinu/MPLABXProjects/PWM Interrupt.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
BUILD FAILED (exit value 2, total time: 625ms)
The code is given below:
What could be the issue?
I keep getting the following error while building :
PWM Interrupt.c: In function 'main':
PWM Interrupt.c:65:12: error: expected identifier or '(' before '.' token
PWM Interrupt.c:66:10: error: expected identifier or '(' before '.' token
PWM Interrupt.c:67:9: error: expected identifier or '(' before '.' token
PWM Interrupt.c:68:9: error: expected identifier or '(' before '.' token
make[2]: *** [build/default/production/PWM Interrupt.o] Error 255
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
nbproject/Makefile-default.mk:94: recipe for target 'build/default/production/PWM Interrupt.o' failed
make[2]: Leaving directory 'C:/Users/Chinu/MPLABXProjects/PWM Interrupt.X'
nbproject/Makefile-default.mk:78: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/Chinu/MPLABXProjects/PWM Interrupt.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
BUILD FAILED (exit value 2, total time: 625ms)
The code is given below:
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 #include <xc.h> #include"PWM Interrupt Config.h" #include<libpic30.h> #include<hspwm.h> volatile float ADCValue; void initAdc1(void); int main() { // Configure PLL prescaler, PLL postscaler, PLL divisor PLLFBD=54; // M=56 CLKDIVbits.PLLPOST=0; // N2=2 CLKDIVbits.PLLPRE=0; // N1=2 // Initiate Clock Switch to Primary Oscillator with PLL (NOSC=0b011) __builtin_write_OSCCONH(0x03); __builtin_write_OSCCONL(OSCCON | 0x01); // Wait for Clock switch to occur while (OSCCONbits.COSC!= 0b011); // Wait for PLL to lock while (OSCCONbits.LOCK!= 1); INTCON2bits.GIE = 1; initAdc1(); /*PWM CONFIGURATION*/ /* Set PWM Periods on PHASEx Registers */ PHASE1 = 5000; //For PWM Freq 14kHz @ 140MHz Fosc PHASE2 = 5000; PHASE3 = 5000; /* Set Duty Cycles */ PDC1 = 0; PDC2 = 300; PDC3 = 200; /* Set Dead Time Values */ /* DTRx Registers are ignored in this mode */ DTR1 = DTR2 = DTR3 = 0; ALTDTR1 = ALTDTR2 = ALTDTR3 = 100; //For 720ns dead time at 140MHz Fosc /* Set PWM Mode to Complementary */ IOCON1 = IOCON2 = IOCON3 = 0xC000; /* Set Independent Time Bases, Center-Aligned mode and Independent Duty Cycles */ PWMCON1 = 0x0604; PWMCON2 = PWMCON3 = 0x0204; /* Configure Faults */ FCLCON1 = FCLCON2 = FCLCON3 = 0x0003; /* 1:1 Prescaler */ PTCON2 = 0x0000; /*Interrupts Config*/ TRIG1 = 0; TRGCON1 = 0; TRGCON1BITS.TRGSTRT = 4; This and the next 3 lines are highlighted by the error message IPC23BITS.PWM1IP = 4; IFS5BITS.PWM1IF = 0; IEC5BITS.PWM1IE = 1; /* Enable PWM Module */ PTCON = 0x8000; while(1) { } } void __attribute__((__interrupt__,no_auto_psv)) _PWMInterrupt() { //ISR Code here AD1CON1bits.SAMP = 1;// Start sampling __delay_us(10);// Wait for sampling time (10 us) AD1CON1bits.SAMP = 0;// Start the conversion while (!AD1CON1bits.DONE);// Wait for the conversion to complete ADCValue = ADC1BUF0;// Read the ADC conversion result} ADCValue = (ADCValue/1023)*5000; PDC1 = ADCValue; IFS5bits.PWM1IF = 0; //Clear Flag for next interrupt } void initAdc1(void) {/* Set port configuration */ ANSELA = 0x0000; ANSELBbits.ANSB2 = 1;// Ensure AN4/RB4 is analog /* Initialize and enable ADC module */ AD1CON1 = 0x0000; AD1CON2 = 0x0000; AD1CON3 = 0x000F; AD1CON4 = 0x0000; AD1CHS0 = 0x0004; AD1CHS123 = 0x0000; AD1CSSH = 0x0000; AD1CSSL = 0x0000; AD1CON1bits.ADON = 1; __delay_us(20); }
What could be the issue?
Last edited by a moderator: