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.

Need help to genarate a PWM signal with a variable frequency

Status
Not open for further replies.

ADGAN

Full Member level 5
Joined
Oct 9, 2013
Messages
295
Helped
4
Reputation
8
Reaction score
4
Trophy points
18
Activity points
1,837
Hi! I need to generate a PWM signal with 50% duty cycle and a variable frequency using atmega32U4. I'm bit confused on how to achieve this. Is anyone able to direct me in the right direction? Which mode I should use? is there any tutorials that covers this particular scenario?
 

What frequencies to you wish to use?
PWM module doesn't support smooth frequency change. It is not a DDS.
 

This is to control a stepper motor. I haven't decided the frequencies yet.
 

They will be fixed with big step. Read about PWM frequency generation based on timer. As faster timer cycling, than frequency will be greater.
 

What Compiler do you use. I use mikroC Compiler. It has PWM_Init() function which is used like this.

Code:
PWM1_Init(1000); //1 KHz PWM

You can use ADC which gives value from 0 to 1023. You can map this value to required frequency range and when pot value changes just call the PWM_Init() function once by passing the new frequency value.

**broken link removed**
 
Last edited by a moderator:
Hi,

I recommend using CTC mode.
And if you use "toggle" for port function, then you automatically have 50% duty cycle and only one register to change frequency.

Klaus
 

Probably, parameter have to be constant. Anyway, I don't respect mikroc libraries. Don't expect too much from them.
 

Its much easier to generate the stepper waveform in hardware, then use a variable frequency generated in software to drive it.

You need high current hardware drivers anyway, so its no big deal to add an up down counter and decoder to that.
 

What Compiler do you use. I use mikroC Compiler. It has PWM_Init() function which is used like this.

Code:
PWM1_Init(1000); //1 KHz PWM

You can use ADC which gives value from 0 to 1023. You can map this value to required frequency range and when pot value changes just call the PWM_Init() function once by passing the new frequency value.

**broken link removed**

Nah I will not be using MikroC for this project. I'm using avr-gcc compiler and just a text editor to write the code.

- - - Updated - - -

Hi,

I recommend using CTC mode.
And if you use "toggle" for port function, then you automatically have 50% duty cycle and only one register to change frequency.

Klaus

Thanks. I was able to figure this. Is there any tutorials available online on this? I couldn't find any.

- - - Updated - - -

Its much easier to generate the stepper waveform in hardware, then use a variable frequency generated in software to drive it.

You need high current hardware drivers anyway, so its no big deal to add an up down counter and decoder to that.

Yes I'm a using motor driver to drive the stepper motor.
 
Last edited by a moderator:

Hi,

Is there any tutorials available online on this? I couldn't find any.

Yes.
That´s where we all have our informations from: The datasheet. That´s all you need to know.

Read about ctc mode and you will find a formula to calculate the frequency.


Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top