CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC16F1846 PWM GENERATION WITH SETUP_PWM1

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
halilemirhankara



Joined: 13 Dec 2024
Posts: 2

View user's profile Send private message

PIC16F1846 PWM GENERATION WITH SETUP_PWM1
PostPosted: Fri Dec 13, 2024 2:17 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 14, 2024 6:48 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 14, 2024 7:47 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 14, 2024 8:13 am     Reply with quote

depending on what the bridge driver is driving, you may be able to speed up the PWM ??
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group