Cannot generate PWM with PIC16F1704

mikroC, mikroBasic and mikroPascal PRO for Microchip’s 8-bit PIC MCUs.
Post Reply
Author
Message
Stefan3v
Posts: 5
Joined: 24 Sep 2012 10:27
Location: Romania
Contact:

Cannot generate PWM with PIC16F1704

#1 Post by Stefan3v » 12 Mar 2020 09:56

Someone can help me with an example?
I try this code, worked in PROTEUS, but don't work on MCU.

Code: Select all

void wdt_reset() {
   asm CLRWDT;
}

void main() {
  OSCCON = 0b01011010;                // OSC internal @1MHz
  
  ANSELA = 0b00000101;                // Configure AN pins as digital - RA0=1 is ADC0 and RA2=1 is DAC1 for another use
  ANSELC = 0;                                // Configure AN pins as digital
  C1ON_bit = 0;                              // Disable comparators
  C2ON_bit = 0;
  OPA1EN_bit = 0;                           // Disable OpAmp
  OPA2EN_bit = 0;

  TRISA = 0b00000101;                // RA0=1 pins is input for ADC0 and RA2=1 is output (set 1) for DAC1 - ignore this
  TRISC = 0b00000000;                // All pins is output
  LATC = 0x01;                             // All RC pins sets to low - LED1 to RC0
  
  Unlock_IOLOCK();
  PPS_Mapping_NoLock(_RC3, _OUTPUT, _CCP2);
  PPS_Mapping_NoLock(_RC5, _OUTPUT, _CCP1);
  Lock_IOLOCK();
  
  PWM1_Remappable_Init(1000);      // Set current freq for PWM1 - library BUGGGG
  PWM2_Remappable_Init(2000);      // Set current freq for PWM1
  PWM1_Remappable_Start();       // Start PWM1 - vezi la RunPrg_LED() - library BUGGGG
  PWM2_Remappable_Start();       // Start PWM1 - vezi la RunPrg_LED()
  PWM1_Remappable_Set_Duty(128); //!!!!!
  PWM2_Remappable_Set_Duty(128); //!!!!! - library BUGGGG
  //FVRCON.FVREN = 0; // disable Internal Voltage reference
  
  while(1){
    wdt_reset();                 //
  }

}
CONFIG1 : $8007 : 0x0EDC
CONFIG2 : $8008 : 0x1603

Many thanks!

Stefan3v
Posts: 5
Joined: 24 Sep 2012 10:27
Location: Romania
Contact:

Re: Cannot generate PWM with PIC16F1704

#2 Post by Stefan3v » 20 Mar 2020 15:21

I solved with MPLABX and XC8.

Please close this topic!

Post Reply

Return to “PIC PRO Compilers”