swallow_159
New Member
hi all
how can write C code for make this waveform?
**broken link removed**
I need help
how can write C code for make this waveform?
**broken link removed**
I need help
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
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.
First make it work
Then make it fast
Then make it elegant
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.
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.
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.
Hello,
you can use the _delay_ms() function like that :
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.
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!
#include <avr/io.h>
To 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.