PWM & ADC in 12F1501 need help

Thread Starter

oookey

Joined May 24, 2010
70
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?
 

Attachments

JohnInTX

Joined Jun 26, 2012
3,813
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:
Rich (BB code):
// INTERNAL FREQ. 16MHz
// PIC 12F1501

unsigned short dutyVal, ADC_VAL1, ADC_VAL2;
void InitMain() {
  TRISA= 0B000011; //SET RA0 & RA1 INPUT.
  CM1CON0 = 0;
  CM1CON1 = 0; //OFF COMPARATORS
}
main(void) {
  InitMain();
  PWM1_Init(500000); // PWM FREQ 500KHz
  PWM1_Start();
  dutyVal = 153;
  PWM1_Start();
  while(1){
    ADC_VAL1=ADC_Read(0);
    ADC_VAL1 /= 4;
    if ((unsigned short)ADC_VAL1>127)
    {
      dutyVal = 0;
      PWM1_Set_Duty(dutyVal);}
      ADC_VAL2=ADC_Read(1);
      ADC_VAL2 /= 4;
      if((unsigned short)ADC_VAL2>127)
      {
       dutyVal = 0;
       PWM1_Set_Duty(dutyVal); 
       }
       else
       {
        PWM1_Set_Duty(dutyVal); // SET DUTY CYCLE
        }
    }//while
}
Have fun!
 
Last edited:

Thread Starter

oookey

Joined May 24, 2010
70
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.
 

Thread Starter

oookey

Joined May 24, 2010
70
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.
 

Attachments

JohnInTX

Joined Jun 26, 2012
3,813
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.
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:

Thread Starter

oookey

Joined May 24, 2010
70
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.:)
 

JohnInTX

Joined Jun 26, 2012
3,813
I use the PIC16f1503 with the PicKit 2 and the device file 1.62.14 referenced here:https://www.microchip.com/forums/m731464-print.aspx
If you already have 1.62.14 then ignore. Still don't see the PIC16F1501 supported.
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?
 
Last edited:
Top