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.

PWM with ATmega16 in Codevision

Status
Not open for further replies.

Wafeeq

Member level 3
Joined
Jul 26, 2010
Messages
61
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Pakistan
Activity points
1,728
Hi All

i am working on Atmega16L. i want to run a machine whose speed varies with the frequency of PWM Signal. i am working on Codevison. please help me how to set the frequency of the pwn signal.. i have generated 800HZ with following code with 8MHz. i dont know how t change the frequency now. i want to change frequecy form 1Hz to 2KHz...

TCCR1A=0xA0;
TCCR1B=0x11;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x27;
ICR1L=0x10;
OCR1A=0;
//OCR1AL=0x00;
OCR1B=0;
//OCR1BL=0x00;

OCR1A=2500;// 50 % Duty cycle
OCR1B=2500;// 50 % Duty cycle
 

Hi All

i am working on Atmega16L. i want to run a machine whose speed varies with the frequency of PWM Signal. i am working on Codevison. please help me how to set the frequency of the pwn signal.. i have generated 800HZ with following code with 8MHz. i dont know how t change the frequency now. i want to change frequecy form 1Hz to 2KHz...

TCCR1A=0xA0;
TCCR1B=0x11;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x27;
ICR1L=0x10;
OCR1A=0;
//OCR1AL=0x00;
OCR1B=0;
//OCR1BL=0x00;

OCR1A=2500;// 50 % Duty cycle
OCR1B=2500;// 50 % Duty cycle

To change the frequency you have to change TCCR1 Registers

To change the pulse width you need to modify the OCR1 Registers

OCR1A and OCR1B are 8 bit registers. You can't load value more than 255.

By the way how did you calculated OCR1 for the value 2500??
 

i dont know how to calculate this value. i got this value by hit and trial method. i saw on CRO its width is 50% at 2500 ant 100% at 5000;
Please tell me how to calculate this value? how to set the registers?

the main problem i am facing is how to calculate for the frequency? i am using both OCR1A and OCR1B. if i change the value of TCNT. it change the frequecny but for both outputs. i want to change the frequency separately for both outputs.
 

OCR1A and OCR1B are 8 bit registers. You can't load value more than 255.

OCR1A and OCR1B are 16bit registers of the 16bit clock timer 1, actually each one of them is two 8 bit registers (OCR1AH-OCR1AL) and (OCR1BH-OCR1BL) but they can be used as 16bit register because codevision has already defined
sfrw OCR1B=0x28; // 16 bit access
and
sfrw OCR1A=0x2a; // 16 bit access

i dont know how to calculate this value. i got this value by hit and trial method. i saw on CRO its width is 50% at 2500 ant 100% at 5000;
Please tell me how to calculate this value? how to set the registers?

the main problem i am facing is how to calculate for the frequency? i am using both OCR1A and OCR1B. if i change the value of TCNT. it change the frequecny but for both outputs. i want to change the frequency separately for both outputs.

You can't change the frequency individually, if you use one timer then you can only get one frequency.
The two compare registers can be loaded with two different values to give two different duty ratios but with the same frequency.
Depending on the PWM mode, if you use top=ICR1 ( instead of a fixed top 0xff/0h1ff/0h3ff ) then you can also change the PWM from the value of ICR1

The frequency and duty ratio depend on the mode and values used

In fast PWM top=ICR1, the output PWM frequency=timer clock/(ICR1+1) and the duty=OCR1A(B)/ICR1
In fast PWM top=0h00ff, the output PWM frequency=timer clock/256 and the duty=OCR1A(B)/256
In fast PWM top=0h01ff, the output PWM frequency=timer clock/512 and the duty=OCR1A(B)/512
In fast PWM top=0h03ff, the output PWM frequency=timer clock/1024 and the duty=OCR1A(B)/1024

In phase correct or phase & freq correct top=ICR1, the output PWM frequency=timer clock/(ICR1*2) and the duty=OCR1A(B)/ICR1
In phase correct or phase & freq correct top=0h00ff, the output PWM frequency=timer clock/(255*2) and the duty=OCR1A(B)/256
In phase correct or phase & freq correct top=0h01ff, the output PWM frequency=timer clock/(511*2) and the duty=OCR1A(B)/512
In phase correct or phase & freq correct top=0h03ff, the output PWM frequency=timer clock/(1023*2) and the duty=OCR1A(B)/1024

Alex
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top