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.

How to generate 13 pulses of PWM signal from microcontroller?

Status
Not open for further replies.

chirag2239

Member level 3
Joined
Jul 29, 2011
Messages
64
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
2,048
Hello,

I am working on a project and I don't know how to generate only 13 pulses of PWM from Microcontroller at every 1 second?

I am using ATmega16. If you can explain thoroughly, then it would be more better for me. sample program would be the best.

Thanks.
Chirag
 

I haven't used ATmega16 for a long time, but in general you can get an interrupt fired at the falling and rising edge, using the output compare interrupt of an AVR. I think with the overflow interrupt as well.

For the first 26 interrupts (13 pulses), you will toggle the desired pin to produce the pwm. You will then hold the pin to 0 in every interrupt, until 1 second is reached. And then 26 pulses counting is starting again and so on.
 

Hi,

With ATMega16 ... every PWM signal can generate an interrupt.
13 at falling edge and 13 at rising edge. You can decide which one you want.

Per interrupt you can count the pulses and stop the output after 13.

And you can count on while the output is enabled.

***
An example:
You want 13 pulses with a frequency of 1kHz.
* Then start the output,
* count 13 pulses
* disable the output, but let the timer counter/ continue to interrupt
* count 987 pulses to determin the rest of the second
* then restart the loop

You can run all these short functions within the ISR. And have plenty of processing power remaining for the main loop.

Klaus
 

I haven't used ATmega16 for a long time, but in general you can get an interrupt fired at the falling and rising edge, using the output compare interrupt of an AVR. I think with the overflow interrupt as well.

For the first 26 interrupts (13 pulses), you will toggle the desired pin to produce the pwm. You will then hold the pin to 0 in every interrupt, until 1 second is reached. And then 26 pulses counting is starting again and so on.


Sorry my friend,

I appreciate your knowledge but I did not get you. As I am new to programming microcontroller, I did not get this.

Thanks.
Chirag
 

Hi,

he just says the same than me.
The difference is: he toggles the pin with software, while my solution toggles the pin with hardware.

Klaus
 

Ok. But I do not know how to do this. I know how to generate PWM wave on OCR0 pin. What would be the next? It will be continued in generate. But I need only 13 cycles to the Ultrasonic sensor.
SO what I need to do next?
For 40kHz, I need to do prescaling and TCCR0=6C and OCR0 will be 204.
So I will get PWM pulses on OCR0 pin. Now what to do next to have only 13 cycles?
 

Hi,

Next step?

--> first line of my post#3: generate interrupts.
(If you don´t know how, then read the datasheet. It is explained in there. )

then follow the rest of the steps of post#3

Slowly. Step by step. Don´t go the next step whe the one before doesn´t work properly.

Klaus

- - - Updated - - -

Added:

For 40kHz, I need to do prescaling and TCCR0=6C and OCR0 will be 204.
--> It depends on AVR clock frequency. You didn´t say.

Klaus
 
Ok. But I do not know how to do this. I know how to generate PWM wave on OCR0 pin. What would be the next? It will be continued in generate. But I need only 13 cycles to the Ultrasonic sensor.

It was already mentioned that you should use the timer interrupt service to count the amount of interrupts. Reaching 13 events, means 13 pulses on output, isn't it clear ?
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top