12F683 - PWM

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
Bonca
Posts: 319
Joined: 18 Mar 2009 07:55

12F683 - PWM

#1 Post by Bonca » 06 Sep 2009 09:33

Hi,
I try to use the PWM module of 12F683, but can't get signal on the CCP output. It is simulated by Proteus without success. There is no error message aftre build. I have tried the basic blinking LED application and it worked fine. I would like to ask you to find the problem in my code:

Code: Select all

/*******************************************************************************
  CONFIG = 0x0FF4
  Project > Edit project:
                        Oscillator: Internal RC No Clock
                        WDT: Off
                        PUT: Off
                        MCLRE: Enabled
                        CP: Off
                        Data EE RP: Off
                        BOD: BOD enabled, SBOREN disabled
			Internal External SOM: Enabled
			Monitor clock fail safe: Enabled
*******************************************************************************/

void main() {
     OSCCON = 0b01000111;  // internal oscillator at 1MHz
     ADCON0 = 0;           // ADC disabled
     CMCON0 = 7;           // comparator disabled
     ANSEL =  0;           // pins are digital
     TRISIO = 0b00001000;  // pins are output, GP3 always input
     GPIO = 0;
     PWM1_Init(1000);
     PWM1_Start;
     PWM1_Set_duty(127);

   while(1){}
}
Thank you in advance:
Bonca

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#2 Post by p.erasmus » 06 Sep 2009 13:45

Yes Proteus is the altimate !!
just wodering why Microchip and mE has put so much effort in developing a simulator ,while every body thinks Proteus is the answer
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

MAN
Posts: 437
Joined: 11 Jan 2006 18:32
Location: Brasil

Re: 12F683 - PWM

#3 Post by MAN » 06 Sep 2009 14:40

Hi;
Bonca wrote:Hi,
It is simulated by Proteus without success.

Code: Select all

/*******************************************************************************
  CONFIG = 0x0FF4
  Project > Edit project:
                        Oscillator: Internal RC No Clock
                        WDT: Off
                        PUT: Off
                        MCLRE: Enabled
                        CP: Off
                        Data EE RP: Off
                        BOD: BOD enabled, SBOREN disabled
			Internal External SOM: Enabled
			Monitor clock fail safe: Enabled
*******************************************************************************/

void main() {
     OSCCON = 0b01000111;  // internal oscillator at 1MHz
     ADCON0 = 0;           // ADC disabled
     CMCON0 = 7;           // comparator disabled
     CCP1CON = 0x0F;   //+++++++++++++++++++++++
     ANSEL =  0;           // pins are digital
     TRISIO = 0b00001000;  // pins are output, GP3 always input
     GPIO = 0;
     PWM1_Init(1000);
     PWM1_Start;
     PWM1_Set_duty(127);

   while(1){}
}
Thank you in advance:
Bonca
I think that you need to configure in the CCP1CON the PWM mode for active-hi or low depending like you want.
Working with you, for you!
MAN

Acetronics
Posts: 715
Joined: 27 Dec 2006 14:33
Location: Le Tréport , FRANCE

#4 Post by Acetronics » 06 Sep 2009 17:17

Hi, Bonca

PWM1_Start(); could make it work MUCH better ...

IF you forget the () ... no asm produced ... no warning nor !!!

Alain

Acetronics
Posts: 715
Joined: 27 Dec 2006 14:33
Location: Le Tréport , FRANCE

#5 Post by Acetronics » 06 Sep 2009 17:22

Addendum

The CCP1CON register defaults to Positive PWM ...

set it to 0b00001110 will invert pwm ratio ...

Alain

Bonca
Posts: 319
Joined: 18 Mar 2009 07:55

#6 Post by Bonca » 06 Sep 2009 18:20

Many thanks for your answers!
First, I have really forgot to use brackets (). Since I have fixed, same result: no warning after build and no PWM signal on the CCP output. Could this be comming from Proteus?

Bonca

Acetronics
Posts: 715
Joined: 27 Dec 2006 14:33
Location: Le Tréport , FRANCE

#7 Post by Acetronics » 06 Sep 2009 20:38

Hi

Probably Proteus ... :roll:

worked fine aboard my Easypic 5 :lol:

Alain

MAN
Posts: 437
Joined: 11 Jan 2006 18:32
Location: Brasil

#8 Post by MAN » 06 Sep 2009 23:19

hi;
Acetronics wrote:Hi

Probably Proteus ... :roll:

worked fine aboard my Easypic 5 :lol:

Alain
the CCP1CON is set by default to mode active-hi by routine PWMStart, it's not default of register, the register starts with zero at POR.
I have custom to set these registers and TRIS manualy in my programs. Now if we missing to put the brackets in the call routine and compiler don't write
asm code, do not issue error or warning maybe it seem a compiler mistake and not proteus. Proteus simulate this segment of code and other larger than
this very well. I still never see the Proteus missing some code that realy was writing correct. Acetronics, very good catch with regard the brackets maybe
it be one issue to ME's corrects for new releases.
Working with you, for you!
MAN

User avatar
mileta.miletic
mikroElektronika team
Posts: 493
Joined: 05 Jun 2009 14:46
Location: Belgrade, Serbia
Contact:

#9 Post by mileta.miletic » 10 Sep 2009 14:28

Hi,

PWM1_Start; without the () is just a pointer. This is legal in C.
Regards,
Mileta

Mince-n-Tatties
Posts: 2780
Joined: 25 Dec 2008 15:22
Location: Scotland

#10 Post by Mince-n-Tatties » 10 Sep 2009 17:12

its is known that versions of proteus have issue with PWM simulation, especially if the software is not properly registered with the manufacturer.

if you are a registered (or demo) user of proteus and you feel that your software code is correct, then simply contact Labcentre for help. They are very helpful.

there is no ultimate software simulator for anything that i have every come across, this includes proteus! simulators by their very nature will always be lacking some level of hardware simulation and lagging new hardware capabilites.

Acetronics
Posts: 715
Joined: 27 Dec 2006 14:33
Location: Le Tréport , FRANCE

#11 Post by Acetronics » 11 Sep 2009 08:26

mileta.miletic wrote:Hi,

PWM1_Start; without the () is just a pointer. This is legal in C.
Hi, Mileta

[Humour ON ]

It's not a pointer ... it's a MISTAKE , moreover without any pointer :wink:

[Humour OFF ]

Alain

Bonca
Posts: 319
Joined: 18 Mar 2009 07:55

#12 Post by Bonca » 13 Sep 2009 12:14

Hi,
I have solved my problem. Basically I wanted to generate PWM signal based on AD value.

Code: Select all

/*******************************************************************************
  Fan PWM control
  12F683
  CONFIG = 0x0FD4
  Project > Edit project:
                        Oscillator: Internal RC No Clock
                        WDT: Off
                        PUT: Off
                        MCLRE: Disabled
                        CP: Off
                        Data EE RP: Off
                        BOD: BOD enabled, SBOREN disabled
                        Internal External SOM: Enabled
                        Monitor clock fail safe: Enabled
*******************************************************************************/

void main() {
     OSCCON = 0b01000111;        // pdf 22.
     ADCON0 = 0b10001111;        // pdf 67.
     CMCON0 = 7;                 // pdf 58.
     ANSEL =  0b00001000;        // pdf 35.
     TRISIO = 0b00011000;        // pdf 33.
     GPIO = 0;
     PWM1_Init(200);
     PWM1_Start();

     while(1){
          PWM1_Set_Duty(ADC_Read(3)>>2);
          delay_ms(200);
     }    // while
}    // main
Thank you for your help!

Bonca[/img]

chamrog
Posts: 28
Joined: 18 Jul 2011 19:18

Re: 12F683 - PWM (Message resurrection)

#13 Post by chamrog » 22 Aug 2011 18:49

Greetings,
sorry to resurrect this old thread, but i tried out the stuff with my 12f683, and i noticed something odd, i dont know if where the problem it located, i can simulate the circuit with no problems in "Pic simulator ide", but its only working partially on a bread board, and when connecting my oscilloscope i can that i get 5 volts of ripple on the adc input, zooming in it looks like a square wave. I did change the clock to 32khz, this causes the output frequency on the PWM to to be around 170 hz which is fine for what i need. But i dont understand why have all the ripple on the input.

can someone tell me what silly mistake im making :)

-lk

Post Reply

Return to “mikroC PRO for PIC General”