|
|
View previous topic :: View next topic |
Author |
Message |
iruraz
Joined: 28 Jul 2009 Posts: 10
|
120 KHz Carrier Signal |
Posted: Thu Feb 18, 2010 5:10 am |
|
|
Hi Everyone,
I try to obtain 120 KHz carrier signal with using pwm module of pic 16f877 . PWM uses timer2 and maximum frequency value is 250 Hz because pr2 maximum value is 255 and postscale maximum value is 16. And the formula is :
Tpwm=Tcommand*(pr2 + 1)*(tmr2 division ratio)
And here is the code below. How can i obtain 120KHz signal with pwm.
regards
Code: |
#include <16f877.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay (clock=4000000)
#use fast_io(c)
void main ( )
{
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_1(T1_DISABLED);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
set_tris_c(0x00);
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_16,255,16);
set_pwm1_duty(30);
while(1);
}
|
|
|
|
monsters_inc
Joined: 18 Jan 2010 Posts: 14
|
|
Posted: Thu Feb 18, 2010 5:53 am |
|
|
Hi. With oscillator of 4MHz you can't obtain exact 120Khz. You can obtain 125Khz. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
|
Ttelmah Guest
|
|
Posted: Thu Feb 18, 2010 8:14 am |
|
|
I have a strange suspicion, he may be after 120Hz (not 120kHz...). 244Hz, is the _minimum_ frequency from the PWM (all dividers at maximum), with a 4MHz crystal, which is what he shows.
A search here will find some answers.
Generally the 'point' of the PWM, is to allow frequencies _above_ those that can be handled by other solutions, to be generated without too much processor overhead. A 120Hz PWM, can be generated by using a normal timer interrupt instead.
The 'answer' depends massively on what is really required. Number of resolution steps, what else the processor needs to do at the same time, etc. etc..
Best Wishes |
|
|
|
|
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
|