const int pulseOutPin = 0b0111;
const int clkOutPin = 0b1001;
int count = 0b0000;
const uint8_t bin[0b00010001] = {0b0001, 0b0000, 0b0001, 0b0000, 0b0001, 0b0000, 0b0001, 0b0000, 0b0001, 0b0000, 0b0001, 0b0000, 0b0000, 0b0000, 0b0000, 0b0000, 0b0000}; // dauer eines Status 4µs
void initialize(long microseconds = 1000000);
ISR(TIMER1_COMPA_vect)
{
PORTD = bin[count] << 0b0111;
count++;
if (count >= 0b00010001)
{
count = 0b0000;
}
}
void setup()
{
noInterrupts();//stop interrupts
TCCR1A = _BV(COM1A0) ; //toggle OC1A on compare match
OCR1A = 7; //top value for counter, 7 = 1MHz
TCCR1B = _BV(WGM12) | _BV(CS10); //CTC mode, prescaler clock/1
TIMSK1 = bit(OCIE1A); //PCINT23; //bit(OCIE1A); //interrupt on Compare A Match
//pinMode (pulseOutPin, OUTPUT);
DDRD = 0b10000000;
//pinMode (clkOutPin, OUTPUT);
DDRB = 0b00000010;
interrupts();//allow interrupts
}
void loop()
{
}
is there a more elegant or faster way to reset a counter to zero?
Ziel ist es eine Periode von <= 3µs zu erreichen. Aktuell sind es 8µs.
have look here:
ISR(TIMER1_COMPA_vect)
{
PORTD = bin[count] << 0b0111;
count++;
if (count >= 0b00010001)
{
count = 0b0000;
}
}
any help or advice is welcome!