Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

120 KHz Carrier Signal using pwm module of pic 16f877

Status
Not open for further replies.

iruraz

Member level 2
Joined
May 4, 2009
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
andromeda
Activity points
1,602
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. By the way i work with ccs-c

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);

}
 

120 KHz Carrier Signal - help needed

Hi,
With PIC16F877, the maximum frequency possible with CCP module is 20kHz. For frequencies greater than that you need to use PIC18/24/dsPIC etc.

Hope this helps.
Tahmid.
 

Re: 120 KHz Carrier Signal - help needed

done exactly with a 12MHz clock.
you should adjust the clock as we dont get exactly 120khz

Code:
' Timer0 Registers: 
' Prescaler=1:1; TMR0 Preset=231; Freq=120 000,00Hz; Period=8 333 ns
OPTION_REG.T0CS = 0 ' bit 5 TMR0 Clock Source Select bit:0=Internal Clock (CLKO) / 1=Transition on T0CKI pin
OPTION_REG.T0SE = 0 ' bit 4 TMR0 Source Edge Select bit: 0=low/high / 1=high/low
OPTION_REG.PSA  = 1 ' bit 3 Prescaler Assignment bit: 0=Prescaler is assigned to the Timer0
OPTION_REG.PS2  = 0 ' bits 2-0  PS2:PS0: Prescaler Rate Select bits
OPTION_REG.PS1  = 0 
OPTION_REG.PS0  = 0 
TMR0 = 231            ' preset for timer register

this program should help you a lot:
**broken link removed**
warning: there seems to be a bug there you should set the date of your computer to 2009. dont want to start for me if it is 2010 ...

Added after 3 hours 6 minutes:

and these are the settings with timer 2 :

Code:
' Timer2 Registers:
' Prescaler=1:1; TMR2 PostScaler=1:1; PR2=25 - Freq = 120 000,00Hz - Period = 8 333 ns
'T2CON |       = 0 ' bits 6-3 Post scaler 1:1 thru 1:16
'T2CON.TOUTPS3 = 0 
'T2CON.TOUTPS2 = 0 
'T2CON.TOUTPS1 = 0 
'T2CON.TOUTPS0 = 0 
'T2CON.TMR2ON  = 1 ' Timer2 on bit: 1=Timer2 is on;
'T2CON.T2CKPS1 = 0 ' bits 1-0  Prescaler Rate Select bits
'T2CON.T2CKPS0 = 0 
T2CON = %00000100
PR2 = 25            ' PR2 (Timer2 Match value)
 

120 KHz Carrier Signal - help needed

the program is effectively stuck to work only if the date of the computer is 2009 ...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top