Hi;
I have an Arduino Genuino UNO board. In my project, I need to generate quadrature signals. I am using pins 9,10,11, 12 for this purpose. My requirement is that signal of pin 9 should be in phase difference of 90 degree with pin 11 and signal of pin 10 should be in phase difference of 90 degrees with pin 12. Also pin 9 should have phase difference of 10 degree with 10 and pin 11 should have phase difference of 10 degree with pin 12.
Do you guys have a solution?
Below is the code I have written:
unsigned int InFreq = 0;
unsigned int InShiftFreq = 0;
unsigned int ReFreq = 0;
unsigned int ReShiftFreq =0;
unsigned int FreqtoTest[]={250,125,62,31,15,7,3};
void setup()
{
int j=0;
pinMode( 9 , OUTPUT ); // Arduino Pin 9 = OCR1A
pinMode( 10 , OUTPUT ); // Arduino Pin 10 = OCR1B
pinMode( 11, OUTPUT );
pinMode( 12, OUTPUT );
//TCCR1A = _BV( COM1A0 ) |_BV( COM1B0 ); // Both outputs in toggle mode
//TCCR1B = _BV( WGM13) | _BV( WGM12); // CTC Waveform Generation Mode
//OCR1A = 0; // Let's assume initially it is zero, then it toggles to zero
for (j=0;j<7;j++)
{
porttoggle(FreqtoTest[j]);
}
}
// prescaler of 1 will get us 8MHz - 488Hz
// User a higher prescaler for lower freqncies
//#define PRESCALER 1
//#define PRESCALER_BITS 0x01
//#define CLK 16000000UL // Default clock speed is 16MHz on Arduino Uno
/*int setWaveforms( unsigned long freq , int shift )
{
unsigned long clocks_per_toggle = (CLK / freq) / 2; // /2 becuase it takes 2 toggles to make a full wave
ICR1 = clocks_per_toggle;
unsigned long offset_clocks = (clocks_per_toggle * shift) / 180UL;
OCR1B= offset_clocks;
TCCR1B |= _BV( CS11 );
}*/
int porttoggle(unsigned int TimeDelay)
{
int i=0;
InFreq = TimeDelay;
InShiftFreq = TimeDelay/2;
for(i=0;i<100;i++)
{
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
delay(InShiftFreq);
digitalWrite(11,HIGH);
digitalWrite(12, HIGH);
//delay(InShiftFreq);
//delay(InShiftFreq);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
delay(InShiftFreq);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
delay(InShiftFreq);
//delay(InShiftFreq);
}
}
//cycling through some phase shifts at 50Khz
void loop()
{
porttoggle(10);
// setWaveforms( 100 , 90 );
}

