View previous topic :: View next topic |
Author |
Message |
halilemirhankara
Joined: 13 Dec 2024 Posts: 2
|
PIC16F1846 PWM GENERATION WITH SETUP_PWM1 |
Posted: Fri Dec 13, 2024 2:17 am |
|
|
Hi, this is my first position on the CCS forum. I tried to solve this problem on my own but reading datasheets or surfing the net didn't help me.
I am trying to generate PWM 50Hz through the PWM peripheral. However, there is no PWM output from the pins I selected. Below is my full code.
I always check the pins I use for PWM generation with an oscilloscope.
Things I tried:
- Setup timer 2
- Disable ccp, cwg
main.h
Code: | #ifndef MAIN_H
#define MAIN_H
#include <16F18146.h>
#include <stdint.h>
#fuses PUT_1MS, NOBROWNOUT, PROTECT
#use delay(internal=32MHz)
#define pwm_1 PIN_C6
#define pwm_2 PIN_A4
#pin_select PWM1S1P1 = pwm_1
#pin_select PWM1S1P2 = pwm_2
#endif |
main.c
Code: | #include <main.h>
void main() {
setup_pwm1(PWM_ENABLE | PWM_CLK_FOSC | PWM_CLK_DIV_BY_16);
setup_pwm1_slice(0, PWM_PUSH_PULL);
set_pwm1_period(10000);
set_pwm1_duty(0, 5000,0);
PWM1LD = 1;
PWM1EN = 1;
while (TRUE) {
}
}
|
I want to use that setup because I want to generate low frequency PWM with high mcu frequency. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sat Dec 14, 2024 6:48 am |
|
|
I'm curious as to the application for 50Hz PWM.
If say for RC servo control, you may be able to use a slower PIC clock speed, if nothing else is 'time critical'.
Another option may be to just use delay(). While this dedicates the PIC to doing the inline delays. again it may work for you. |
|
|
halilemirhankara
Joined: 13 Dec 2024 Posts: 2
|
|
Posted: Sat Dec 14, 2024 7:47 am |
|
|
It is for a full-bridge driver.
I already got it working with other methods but I am curious about this one because with this method I can use 32 MHz mcu clock and 50 Hz PWM at the same time as I thought.
I also have more coding for this project. I have not added it yet.
And also I am trying to run the code this way because there will be other projects where I will use this method. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sat Dec 14, 2024 8:13 am |
|
|
depending on what the bridge driver is driving, you may be able to speed up the PWM ?? |
|
|
|