MPLAB X, PWM, Compile error

Discussion in 'Embedded Systems and Microcontrollers' started by Ctenom, Jul 29, 2011.

  1. Ctenom

    Thread Starter Member

    Nov 1, 2010
    59
    1
    Hi i have spent the last few hour's trying to get PWM to work on my pic18f16k22. Im using the C18 compiler in MPLABX V6.1 The probolem im having is it compiles with this error


    Error - could not find definition of symbol 'SetDCPWM1' in file './build/default/production/_ext/916313547/PWM.o'.
    Errors : 1

    The PWM.h file definatly contains the definition and is included in my config.
    Code ( (Unknown Language)):
    1. void SetDCPWM1 ( unsigned int duty_cycle);
    I started off wrighting my own code then found several examples on the web and thay all compile with this error

    My last code looks like this using some code from a C18 cheat sheet by AtomSoftTech.

    Code ( (Unknown Language)):
    1. #include <p18Cxxx.h>
    2. #include <pwm.h>
    3. #include <delays.h>
    4.  
    5. #pragma config FOSC = INTIO67               // Oscillator Selection
    6. #pragma config WDTEN = OFF                  // Watchdog Timer
    7. #pragma config MCLRE = INTMCLR              // MCLR Pin Enable bit
    8. #pragma config DEBUG = ON                  // Background Debug
    9.  
    10.  
    11.  
    12. #define PWM_Tris TRISCbits.TRISC2 //Define a nice name for the PWM TRIS bit.
    13. char direction; //direction holder for out loop
    14. void main (void)
    15. {
    16. char DutyCyc = 0x66; //Start Duty Cycle
    17.  
    18. OSCCON = 0x72; //8MHz clock
    19.  
    20. while(!OSCCONbits.IOFS); //Wait for OSC to become stable
    21.  
    22. PWM_Tris = 0; //Set the pin a OUTPUT
    23.  
    24. SetOutputPWM1 (SINGLE_OUT, PWM_MODE_1); //Set as single output pwm and mode 1 (P1A,P1B,P1C,P1D active-high)
    25.  
    26. OpenPWM1(DutyCyc); //Set the duty cycle and start the PWM module
    27.  
    28. while(1){
    29.  
    30. if(DutyCyc == 0x12) //Check if we reached our minimum. If so set direction (up)
    31.  
    32. direction = 1;
    33.  
    34. if(DutyCyc == 0x66) //Check if we reached our maximum. If so clear direction (down)
    35.  
    36. direction = 0;
    37.  
    38. SetDCPWM1(DutyCyc); //Set the new duty cycle
    39.  
    40. if(direction == 1) //based on direction if 1 (up) add 2 each time to the duty cycle
    41.  
    42. DutyCyc+=2;
    43.  
    44. else // if 0 (down) minus 2 each time to the duty cycle
    45.  
    46. DutyCyc-=2;
    47.  
    48. Delay10KTCYx(3); //small delay (15mS)
    49. }
    50. }
    Thank you for taking time to read my post.
     
  2. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,907
    2,165
  3. Ctenom

    Thread Starter Member

    Nov 1, 2010
    59
    1
    I installed the new version after completely deleting the old one.
    And got a slightly different error but still the same problem.

    Error - could not find definition of symbol 'SetDCPWM1' in file './build/default/production/PWM.o'.
    Errors : 1


    And i was expecting that to work as well:(
    Thank you for your reply
     
  4. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,907
    2,165
    For some of the chips the routines may have been renamed or renumbered. Check the

    "PIC18F Peripheral Library Help Document" in the C18 doc folder.
     
  5. Ctenom

    Thread Starter Member

    Nov 1, 2010
    59
    1
    Just tried updating my C18 from 3.39 to 3.40 still no joy.
     
  6. Ctenom

    Thread Starter Member

    Nov 1, 2010
    59
    1
    Thanks for your help, i belive it might just be teething problems with MPLABX as i have tried just about everything now. I finally got it working using HI-TECH C heres my test code (makes a pretty fading led).



    Code ( (Unknown Language)):
    1. #include <htc.h>
    2.  
    3.  
    4. __CONFIG (1,FOSC_INTIO67);
    5. __CONFIG (2,WDTEN_OFF);
    6. __CONFIG (3,MCLRE_INTMCLR);
    7. __CONFIG (4,STVREN_OFF & DEBUG_ON & LVP_OFF);
    8.  
    9.  
    10.  
    11.  
    12.   void main()
    13.         {
    14.         unsigned char   dc ;
    15.  
    16.         TRISC = 0 ;                    
    17.         PORTC = 0 ;                    
    18.        
    19.         PR2 = 0b01111100 ;
    20.         T2CON = 0b00000101 ;
    21.         CCP1CON = 0b00001100 ;
    22.         CCP2CON = 0b00111100 ;
    23.  
    24.         for(;;)                        
    25.                 {
    26.                
    27.                 for(dc = 5 ; dc < 128 ; dc++)
    28.                         {
    29.                         CCPR1L = dc ;
    30.                         CCPR2L = 128 - dc ;
    31.                         _delay(6000);
    32.                         }
    33.                 for(dc = 127 ; dc > 5 ; dc--)
    34.                         {
    35.                         CCPR1L = dc ;
    36.                         CCPR2L = 128 - dc ;
    37.                         _delay(4000);
    38.                         }
    39.                 }
    40.         }
    Now the proper coding can begin.
     
  7. stahta01

    Member

    Jun 9, 2011
    133
    21
    That code is the function prototype and is the declaration NOT the definition of the function. If this was normal C (instead of embedded C) I would say you are missing a Library that needs linked into the project.
    Since it is a embedded C, could be a missing(or wrong) Compiler or Linker Options; but, I would guess that a object file needs linked that provides the function.


    Quote from http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=188
    Tim S.
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Ctenom: When you were using the C18 did you set the project library include search path? I don't use MPLABX (I use the non-X) but that path and a few others needs to be set for every new project. MPLAB will show the correct path by default, but you still have to select it and OK it.

    Tim: What would be the difference between embedded and this "normal" C? My PIC C compilers are pretty much ANSI standard, with some minor defined exceptions.
     
  9. stahta01

    Member

    Jun 9, 2011
    133
    21
    I have learned that embedded C have a lot of non standard extensions and sometimes you need to link to an system object file instead of with a system library file. Note: Borland also had this linking with system object file; so, it is not just a embedded C issue.

    Note: My main experience in the embedded world is the Dynamic C [like] Compiler from Rabbit (now owned by Digi). And old experience (20+ years ago) with OS9 from Microware. And, PIC Assembly/C as a Student Assistant Teacher. Note: Rabbit Dynamic C IS NOT a ANSI C Language; but getting closer every release cycle.
    Edit: The Microware C Compiler required linking to system object files to get a good build like the Borland C Compiler did.

    Tim S.
     
    Last edited: Aug 4, 2011
Loading...