Does any one have any idea why the following code outputs a jittery signal? Attached is the Scope image.
Thanks!!
int pinOne = 9;
int pinTwo = 10;
#define fastWrite(_pin_, _state_) ( _pin_ < 8 ? (_state_ ? PORTD |= 1 << _pin_ : PORTD &= ~(1 << _pin_ )) : (_state_ ? PORTB |= 1 << (_pin_ -8) : PORTB &= ~(1 << (_pin_ -8) )))
// the macro sets or clears the appropriate bit in port D if the pin is less than 8 or port B if between 8 and 13
void setup() {
pinMode(pinOne, OUTPUT); // set outPin pin as output
pinMode(pinTwo, OUTPUT);
}
void loop()
{
fastWrite(pinOne, HIGH); // set Pin high
//delayMicroseconds(20); // waits "on" microseconds
fastWrite(pinTwo, HIGH);
delayMicroseconds(20);
fastWrite(pinOne, LOW); // set pin low
//delayMicroseconds(20); //wait "off" microseconds
fastWrite(pinTwo, LOW);
delayMicroseconds(20);
}
If you mean like the below, I still see the jittery signals. Do did i not implement it correctly?
int pinOne = 9;
int pinTwo = 10;
#define fastWrite(_pin_, _state_) ( _pin_ < 8 ? (_state_ ? PORTD |= 1 << _pin_ : PORTD &= ~(1 << _pin_ )) : (_state_ ? PORTB |= 1 << (_pin_ -8) : PORTB &= ~(1 << (_pin_ -8) )))
// the macro sets or clears the appropriate bit in port D if the pin is less than 8 or port B if between 8 and 13
void setup() {
pinMode(pinOne, OUTPUT); // set outPin pin as output
pinMode(pinTwo, OUTPUT);
}
void loop(){
while (1)
{
fastWrite(pinOne, HIGH); // set Pin high
//delayMicroseconds(20); // waits "on" microseconds
fastWrite(pinTwo, HIGH);
delayMicroseconds(20);
fastWrite(pinOne, LOW); // set pin low
//delayMicroseconds(20); //wait "off" microseconds
fastWrite(pinTwo, LOW);
delayMicroseconds(20);
}
}