View previous topic :: View next topic |
Author |
Message |
qwwe
Joined: 17 Sep 2017 Posts: 59
|
Problem with the production of pwm wave |
Posted: Thu Nov 23, 2017 3:18 am |
|
|
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
|
|
Posted: Thu Nov 23, 2017 3:49 am |
|
|
Is this microcontroller digital converter analog
If it has ccs commands to use it |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Thu Nov 23, 2017 4:43 am |
|
|
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. |
|
|
|