Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help with 16f877A PWM

Status
Not open for further replies.

zero2004

Member level 1
Joined
Dec 12, 2009
Messages
33
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,505
Hi every one

I try to work with PWM in my pic, i wrote my first attempt program in mikroc but it doesnt work, the program is

unsigned short i;
void main() {
PORTC = 0xff;
Pwm1_Init(5000);
Pwm1_Start();
Pwm1_set_Duty(123);
}

can you tell me the wrong in this program

thanks for your helping
 

Hi zero2004,

Try: TRISC=0; before pwm initialisation.
 

Hi zero2004,

Give more details: uC used, Compiler, circuit, clock used...
 

Hi

16f877A, MikroC compiler, 8MHz Clock
 

hi

just check the fuse setting of the controller
it's done by edit project in project window
i think i myself repeated the same thing many times here
then compile it.
also add the following
unsigned short i;
void main() {
PORTC = 0x00;
Pwm1_Init(5000);
Pwm1_Start();
Pwm1_set_Duty(123);

while(1){;}// added

}

it will work
 

hi

just check the fuse setting of the controller
it's done by edit project in project window
i think i myself repeated the same thing many times here
then compile it.
also add the following
unsigned short i;
void main() {
PORTC = 0x00;
Pwm1_Init(5000);
Pwm1_Start();
Pwm1_set_Duty(123);

while(1){;}// added

}

it will work

Hey dude , I'm facing the same problem that you had faced , but I don't understand what is the fuse setting of the controler ?? Plz help thanks
 

The flash bits refers to the bits you are setting or clearing after you have created a new project in MikroC.They are also found bits of the configuration register of the controller which you are using
Regards,
Jerin.
 

thnks dude ,,I have another problem with mikroc in configuration
for example ANSEL =0; is an error and C1ON_bit =0; is also an error ,, it says undeclared identifier
 

Are these the variables you used or defined names for some port pins by "#define"?
Regards,
Jerin.
 

Hi ahmed,
It shows error because the register ANSEL and bit C1ON do not exist in the target microcontroller. If you are using 16F877A, check the datasheet and there you can see that there is no ANSEL register but ADCON1 register for analog pin selection. There is no C1ON bit, instead write 7 to CMCON, like:
Code:
CMCON=7;//turn comparator off
ADCON1=7;//turn ADC off

Hope this helps.
Tahmid.
 
Last edited:
Thank you tahmid ,, I found that i don't know alot of things , you guys helped me
 

Then one question please. Where did you use these "ANSEL" & "C1ON" stuff while coding?
Regards,
Jerin.
 

while programming pic16f877 , these are writtem in the help of mikroC , at the PWM example .
 

Hi Ahmed,
In the mikroC examples, the codes are written using PIC16F887 in which the registers are different from 16F877.

Hope this helps.
Tahmid.
 

I think the register ANSEL & C1CON are used only for certain PICs & for all other variants of PIC we use ADCON & CMCON registers.
Regards,
Jerin. ;-)
 

Yes jerin,
The newer variants of PIC family like 16F887, 16F690, 16F1937, etc use the registers ANSEL and C1CON rather than ADCON and CMCON used in previous PIC microcontrollers. The use of ANSEL however, I would say, has made analogue channel selection much easier than the previous ADCON1 method.

Hope this helps.
Tahmid.
 

dear tahmid .
So could you tell me plz how to use the ADCON1 method ? I realy don't understand that table in the datasheet.
Thanks in advance
 

The ADCON0 register controls the operation of the A/D module. The ADCON1 register configures the functions of the port pins. The port pins can be configured as analog inputs or as digital I/O. For this purpose of making the PORTA pins analog or digital we are using ADCON1 register.The lower 4 bits of the register ADCON1(PCFG3,PCFG2,PCFG1,PCFG0) determines which pin of the PORT to be selected as analog & which are to be digital. Default case is that all the pins of PORTA are analog.So if we have to use any other peripherals than ADC on PORTA then it is required to configure the pins which are required for us to DIGITAL other wise no output will be obtained.
The MSB bits are for alignment of the ADC 10 bit value to be aligned to left or to the right.
In ADCON0 (CHS2,CHS1,CHS0),these bits are used in order to select the analog channel we needed/required for our application or code.The last 2 bits are there to start the ADC(ADON) & to check whether the ADC conversion is over or not(GO/DONE).
Still you have doubts post it here......... :)
Regards,
Jerin.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top