swallow_159
New Member
hi all
how can write C code for make this waveform?
I need help
how can write C code for make this waveform?

I need help
We agree on the basics.Just creating loop delays between on/off points is an extremely crude way of doing it, but it works. Properly it should be done with an interrupt and a timer. I have no experience with AVR's, but I'm sure there is plenty of sample code for timers out there, and I'm sure AVR FREAKS can help.
while I agree with you on the basics, when one first makes it work I think they should start in an organized way that can eventually lead to something fast and elegant. But this may be small enough that a complete re-write isnt a big deal.First make it work
Then make it fast
Then make it elegant
This would be the best way to start. It will help you with flow.One statement at a time where each statement is one of the following:
OUT = 0 ;
while(t < next_edge) ; // do nothing
OUT = 1 ;
unless you know something we don't and have a magic Ace up your sleeve.
ok but becoze they r very fast pulse with high frequency I think maby when AVR want exert the prgram line the 4 u sec pastJust creating loop delays between on/off points is an extremely crude way of doing it, but it works. Properly it should be done with an interrupt and a timer. I have no experience with AVR's, but I'm sure there is plenty of sample code for timers out there, and I'm sure AVR FREAKS can help.
ok becoze of fast pulse I think use PWM mode of micro is it true?This would be the best way to start. It will help you with flow.
You learn flow and you'll write good code.
#include <util/delay.h> /* for _delay_ms() */
PORTD |= (1<<PD5); // output 1 on the pin 5 of PORTD
_delay_ms(980); //wait for 980 mS.
PORTD &= ~(1<<PD5); // output 1 on the pin 5 of PORTD
_delay_ms(980); //wait for 980 mS.
I'm not sure but I'm pretty sure you'd needHello,
you can use the _delay_ms() function like that :
and put that in for loop or while loops any how you want to build your wave form. don't forget to set the port's DDR as output!Code:#include <util/delay.h> /* for _delay_ms() */ PORTD |= (1<<PD5); // output 1 on the pin 5 of PORTD _delay_ms(980); //wait for 980 mS. PORTD &= ~(1<<PD5); // output 1 on the pin 5 of PORTD _delay_ms(980); //wait for 980 mS.
#include <avr/io.h>
I hope yourTo be honest my normal approach to software is "make it perfect first time and make all code easily and efficiently reusable for the future", but as I said I've never used a microcontroller. Also my language of choice is java, which is much better for reusability than c.