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 support@ccsinfo.com

Problem with the production of pwm wave

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



Joined: 17 Sep 2017
Posts: 59

View user's profile Send private message

Problem with the production of pwm wave
PostPosted: Thu Nov 23, 2017 3:18 am     Reply with quote

Hi, I wrote the following program to generate a pwm wave
Code:

#include <16f1823.h>
#device *=16
#fuses NOWDT            //NO Watch Dog Timer
#fuses PUT            //Power Up Timer
#fuses NOLVP          //No low voltage programing
#fuses NOCPD          //No EE protection
#fuses NOPROTECT      //Code not protected from reading
#fuses NOWRT          //Program memory not write protected
#fuses NODEBUG        //No Debug mode for ICD
#fuses NOBROWNOUT     //No brownout reset
#USE DELAY (clock=1000000,int)
#include <stdio.h>
#include <string.h>

void main()
{
set_tris_c(0b11101111);
output_low(PIN_C5);
setup_timer_2(T2_DIV_BY_1,20,1);

setup_ccp1(ccp_pwm);
set_pwm1_duty(512);

while(TRUE)
{
}
}

According to the above, the program now needs to generate a wave at 12 khz frequencies،But does not produce.
Of course, the low frequencies are up to 1khz by changing the settings, but no more.
Meanwhile, I want to use the micro-clock internal, whether the setting is correct.
Thank you for saying what the problem is
qwwe



Joined: 17 Sep 2017
Posts: 59

View user's profile Send private message

PostPosted: Thu Nov 23, 2017 3:49 am     Reply with quote

Is this microcontroller digital converter analog
If it has ccs commands to use it
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Nov 23, 2017 4:43 am     Reply with quote

The problem is your duty cycle.

You have a PR2 value of 20.
Duty max (for full on) = (PR2+1)*4 = 84

You are loading 512 for the duty, so the output will be permanently high.

Look at the examples in the data sheet (table 24-5, 6 & 7. Note how the maximum resolution shoots down as the PR2 value goes down.

set_pwm1_duty(42L);

Would be a starting value.
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