PWM & ADC in 12F1501 need help

Discussion in 'Embedded Systems and Microcontrollers' started by oookey, Feb 12, 2014.

  1. oookey

    Thread Starter Member

    May 24, 2010
    62
    0
    Hi all,

    I’m using two ADC signals input to limit the PWM value, in the 12F1501.
    ADC signal1 inputs to RA0, ADC signal2 inputs to RA1, PWM output from RA2.

    I got stuck with this error message after compiled: “Not enough parameters 12F1501-PWM.c” pointing to this command: “PWM_Init1(500000);”

    Please any advice?
     
  2. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    According to the manual the name should be PWM1_Init(500000L); PWM1_Start(); etc
    The formal parameter list for PWM1_Init(long freq) shouldn't say 'const'. That implies a runtime constant and this wants a compile time literal. If you are using MikroC's built in libraries, you shouldn't have to prototype the functions at all.
    Be sure you have specified the oscillator frequency of the PIC.
    Other than that, it looks OK.

    EDITs: To clarify, MikroC User's Manual uses 'constant' in two contexts:
    1) As a literal i.e. a hard-coded value specified in the source i.e. x=10; No space is allocated for the value 10. 10 is variously referred to as a constant or literal by MikroC. It probably should only be referred to as literal but that's the way it is.
    2) As a storage class where 'const' is a value or pointer to a value that IS allocated space BUT does not change during the running of the program. (The compiler will flag an error if you try). i.e. const char howdy[]="Hello"; allocates 6 bytes of storage and initializes them to 'Hello\0'; You can't change the characters.
    In the case of PWM1_Init(), it wants a literal as in #1. It uses the literal value to compute PWM settings only.

    Fixed those things and it compiles with no errors:
    Code ( (Unknown Language)):
    1. // INTERNAL FREQ. 16MHz
    2. // PIC 12F1501
    3.  
    4. unsigned short dutyVal, ADC_VAL1, ADC_VAL2;
    5. void InitMain() {
    6.   TRISA= 0B000011; //SET RA0 & RA1 INPUT.
    7.   CM1CON0 = 0;
    8.   CM1CON1 = 0; //OFF COMPARATORS
    9. }
    10. main(void) {
    11.   InitMain();
    12.   PWM1_Init(500000); // PWM FREQ 500KHz
    13.   PWM1_Start();
    14.   dutyVal = 153;
    15.   PWM1_Start();
    16.   while(1){
    17.     ADC_VAL1=ADC_Read(0);
    18.     ADC_VAL1 /= 4;
    19.     if ((unsigned short)ADC_VAL1>127)
    20.     {
    21.       dutyVal = 0;
    22.       PWM1_Set_Duty(dutyVal);}
    23.       ADC_VAL2=ADC_Read(1);
    24.       ADC_VAL2 /= 4;
    25.       if((unsigned short)ADC_VAL2>127)
    26.       {
    27.        dutyVal = 0;
    28.        PWM1_Set_Duty(dutyVal);
    29.        }
    30.        else
    31.        {
    32.         PWM1_Set_Duty(dutyVal); // SET DUTY CYCLE
    33.         }
    34.     }//while
    35. }
    Have fun!
     
    Last edited: Feb 12, 2014
  3. oookey

    Thread Starter Member

    May 24, 2010
    62
    0
    Thanks JohnInTX :)

    The compile failed again with the edited, but after I updated the MikroC software, it just beautifully does it. :D

    Later i'll program into the chip, hopefully no issue arise.
     
  4. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    I used MikroC Pro Ver 6.00. Interesting about the version incompatibility.

    Good luck!
     
  5. oookey

    Thread Starter Member

    May 24, 2010
    62
    0
    Hi all,

    Is the pickit2 not supporting 12F1501? :(
    1st it shown "No Device Found", i pressed the "READ" button again, then shown "Unsupport Part..."

    Please any suggestion? Thanks.
     
  6. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    I don't think PICkit2 supports the 12F1501. MPLABX says no and the Development Tool Selector
    lists only PICKit3, ICD3, RealICE as programmers/debuggers and PM3 as a programmer..

    Sorry,
    Time for an upgrade?

    BTW: For debugging w/PICkit consider using a header if you debug under MPLABX. I think MikroC's IDE requires their own ICD.
     
    Last edited: Feb 13, 2014
    oookey likes this.
  7. oookey

    Thread Starter Member

    May 24, 2010
    62
    0
    Well, my pickit2 still in good shape & I read about some negative comments on the pickit3, so I’m not eager to get one, until retire of the pickit2.:)
     
  8. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
    SgtWookie and JohnInTX like this.
  9. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    I don't see it either - in the PK2 Programmer application Ver 2.61.00 Device File 1.62.14 OS Firmware Version 2.32.00. Pulling up PK2 in the Microchip Store, they tell you to buy a PK3. Who knew?
     
  10. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
    I don't even see ANY documents or software available under Pickit 2 page, do you??? http://www.microchip.com/Developmenttools/ProductDetails.aspx?PartNO=DV164121

    EDIT: OK I think we are saying the same thing, they have completely pulled the plug on the PICKit 2.
     
    Last edited: Feb 13, 2014
  11. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
Loading...