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.

correcting freq for pwm signal

Status
Not open for further replies.

aliyesami

Full Member level 6
Full Member level 6
Joined
Jan 7, 2010
Messages
369
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
USA
Visit site
Activity points
4,190
I have generated a pwm signal from sample code/video available online and its working fine except its freq is only 76.4 Hz where as the meanwelll LDD driver I want to use requires 100-1Khz signal.
The code iam using is shown below.
I have two questions :
1- how can I increase the freq of this PWM signal to around 100+ Hhz ?
2- the datasheet is giving the formula to calculate the pwm freq but I cant get 76.5 Hz from it so if you can help me analyze why my freq is 76.Hz?

thanks

Code:
DDRB |= (1 << PORTB3);      //PWM pin PINB3
TCCR0A = (1 << COM0A1) | (1 << WGM00) | (1 << WGM01);
TIMSK0 = (1 << TOIE0);
TCCR0B = (1 << CS00) | (1 << CS02);

Main {

ISR(TIMER0_OVF_vect)
{
	OCR0A = 20;
}
.
.
 

actually PWM is used for varying duty cycle of signal. u can change the frequency also by providing different count. Post your full code for
clear understanding.
 

You can get formula for calculating pwm frequency in data sheet for example total time periode= Reg count value* (1/(oscfreq/4) )
and 1/total time periode you will get frequency

fix the frequency you want select your crystal frequency value and from the formula calculate reg count value and put value in appropriate reg


Thanks & Regards
 

its working now .

I had not set the clock/prescaler mode , I set CS30 to 1 and I got the PWM signal.

TCCR3B |= 1<<CS30;
 

I have new issue related to this . my OC3A is working but my OC3B is not with the following settings :
what do I have to do more to enable OC3B ?
Thanks
Code:
//PWM pin PINB6 -OC3A 16BIT TIMER 
 //PWM pin PINB7 -OC3B 16BIT TIMER 
 DDRB |= ((1 << PORTB6) | (1 << PORTB7));              

 // WGMn: FA0:3 FAST PWM:OCRnA mode 15 ; COM3A1: non-inverting fast PWM; WGM31: 
 TCCR3A |= ((1<<WGM31) | (1<< WGM30) | (1<<COM3A1)); 

 TIMSK3 = (1 << TOIE3); 
 sei(); 

 //clock set bit .. prescaler = 8 , giving 305.5 Hz 
 TCCR3B |= ((1<<WGM32) | (1<WGM33) | (1<<CS31)); 

 ISR(TIMER3_OVF_vect) 
 { 
    OCR3A = dutyCycle; 
    OCR3B = dutyCycle; 
 }
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top