Well, we do not know what's the code in mE's library. I believe it set's the OSC so you don't have to. But I am not sure.
PWM1_init initializez the first module. I don't know how many modules does your pic have. You should check the datasheet for that.
PWM program from mikroC PRO for PIC Help
-
- Posts: 16
- Joined: 26 Dec 2010 16:47
Re: PWM program from mikroC PRO for PIC Help
Maybe could be a bad PIC configuration settings?
-
- Posts: 2
- Joined: 25 Dec 2011 09:50
Re: PWM program from mikroC PRO for PIC Help
did the program work in proteus? i have also checked some simple examples in proteus but they aren't working too....
Re: PWM program from mikroC PRO for PIC Help
Hey;
Why does'nt this program work ?
Why nobody answer us ?
Why does'nt this program work ?
Why nobody answer us ?
Re: PWM program from mikroC PRO for PIC Help
Hi
I am using PIC18F67K40. In this, I am implementing PMW. But it is not working. Can you suggest me what is the issue?
I am using PIC18F67K40. In this, I am implementing PMW. But it is not working. Can you suggest me what is the issue?
- stefan.filipovic
- mikroElektronika team
- Posts: 1135
- Joined: 18 Dec 2018 10:30
Re: PWM program from mikroC PRO for PIC Help
Hi,
Please find the simple example for PWM with PIC18F67K40 in the attachment.
Kind regards,
Please find the simple example for PWM with PIC18F67K40 in the attachment.
Kind regards,
- Attachments
-
- PWM.ZIP
- (87.99 KiB) Downloaded 144 times
Stefan Filipović
Re: PWM program from mikroC PRO for PIC Help
Thanks for your reply.
Already I got the functionality of PWM. But I want to decrease PWM frequency. The least possible frequency is 489Hz. If I give less than this frequency, it is giving an error. Can I decrease that frequency? If it is possible, then how to decrease? Please suggest to me.
Already I got the functionality of PWM. But I want to decrease PWM frequency. The least possible frequency is 489Hz. If I give less than this frequency, it is giving an error. Can I decrease that frequency? If it is possible, then how to decrease? Please suggest to me.
- stefan.filipovic
- mikroElektronika team
- Posts: 1135
- Joined: 18 Dec 2018 10:30
Re: PWM program from mikroC PRO for PIC Help
Hi,
The PWM frequency is derived from the system clock frequency, so I guess you are using 64 MHz Fosc, with this Fosc you can't get PWM frequency lower than 489Hz. Decreasing the Fosc frequency you will be able to decrease the PWM frequency.
Kind regards,
The PWM frequency is derived from the system clock frequency, so I guess you are using 64 MHz Fosc, with this Fosc you can't get PWM frequency lower than 489Hz. Decreasing the Fosc frequency you will be able to decrease the PWM frequency.
Kind regards,
Stefan Filipović
Re: PWM program from mikroC PRO for PIC Help
Hello,
I am using PIC18F67K40 MCU, I need to generate the PWM signal but my problem is I new to PPS config settings so I found one example code and generate the pwm signal but every 2 sec it will generate the PWM signal its width is changing very lately so please help me to get the perfect pwm signal as our requirement.
Code:
unsigned int duty1 = 0;
void InitMain() {
OSCCON1 = 0X60; //HFINTOSC & 1:1 Divider
OSCCON3 = 0x00; // inorder to decrease the clock rate i used OSCCON2
OSCTUNE = 0x00; //mAximum Frequency
OSCFRQ = 0X08; //64 Mhz
TRISC.B4 = 0; // designate PORTC pins as output
PORTC.B4 = 0; // set PORTC to 0
Unlock_IOLOCK();
PPS_Mapping_NoLock(_RC4, _OUTPUT, _CCP1);
Lock_IOLOCK();
PWM1_Remappable_Init(5000); // Initialize PWM1 module at 5KHz
}
void main() {
InitMain();
PWM1_Remappable_Start(); // start PWM1
while(1){
for(duty1 = 0; duty1 < 90; duty1++){
PWM1_Remappable_Set_Duty(duty1);
Delay_us(1);
}
for(duty1 = 60; duty1 > 0; duty1--){
PWM1_Remappable_Set_Duty(duty1);
Delay_us(1);
}
}
}
please guide me, thanks in advance,
best regards
mmm
I am using PIC18F67K40 MCU, I need to generate the PWM signal but my problem is I new to PPS config settings so I found one example code and generate the pwm signal but every 2 sec it will generate the PWM signal its width is changing very lately so please help me to get the perfect pwm signal as our requirement.
Code:
unsigned int duty1 = 0;
void InitMain() {
OSCCON1 = 0X60; //HFINTOSC & 1:1 Divider
OSCCON3 = 0x00; // inorder to decrease the clock rate i used OSCCON2
OSCTUNE = 0x00; //mAximum Frequency
OSCFRQ = 0X08; //64 Mhz
TRISC.B4 = 0; // designate PORTC pins as output
PORTC.B4 = 0; // set PORTC to 0
Unlock_IOLOCK();
PPS_Mapping_NoLock(_RC4, _OUTPUT, _CCP1);
Lock_IOLOCK();
PWM1_Remappable_Init(5000); // Initialize PWM1 module at 5KHz
}
void main() {
InitMain();
PWM1_Remappable_Start(); // start PWM1
while(1){
for(duty1 = 0; duty1 < 90; duty1++){
PWM1_Remappable_Set_Duty(duty1);
Delay_us(1);
}
for(duty1 = 60; duty1 > 0; duty1--){
PWM1_Remappable_Set_Duty(duty1);
Delay_us(1);
}
}
}
please guide me, thanks in advance,
best regards
mmm