My understanding is, you want a blocksignal with a period of about 200 ms and a duty cycle of 50%?
You can program a timer which generates an interrupt each 100ms. In the interrupt handler you can then toggle the output pin.
This code makes a 15kHz blockwave with 50% dutycycle. Credits to ard_newbie who posted it as an answer to my question couple of months ago.
Change the prescaler, RA and RC register to get the needed values
/**************************************************************************************/
/* PWM pulses on TIOA0 (arduino pin 2) Frequency = 15 KHz, Duty cycle = 50% */
/* Interruptions on TIOA0 rising and falling edges */
/**************************************************************************************/
void setup() {
/************* Timer Counter 0 Channel 0 to generate PWM pulses thru TIOA0 ************/
PMC->PMC_PCER0 |= PMC_PCER0_PID27; // TC0 power ON - Timer Counter 0 channel 0 IS TC0
PIOB->PIO_PDR |= PIO_PDR_P25; // PB25 is no more driven by the GPIO
PIOB->PIO_ABSR |= PIO_PB25B_TIOA0;
TC0->TC_CHANNEL[0].TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1 // MCK/2, clk on rising edge
| TC_CMR_WAVE // Waveform mode
| TC_CMR_WAVSEL_UP_RC // UP mode with automatic trigger on RC Compare
| TC_CMR_ACPA_CLEAR // Clear TIOA0 on RA compare match
| TC_CMR_ACPC_SET; // Set TIOA0 on RC compare match
TC0->TC_CHANNEL[0].TC_RC = 2800; //<********************* Frequency = (Mck/2)/TC_RC Hz = 15 KHz
TC0->TC_CHANNEL[0].TC_RA = 1400; //<******************** Duty cycle = (TC_RA/TC_RC) * 100 % = 80 %
TC0->TC_CHANNEL[0].TC_IER = TC_IER_CPCS // Interrupt on RC compare match
| TC_IER_CPAS; // Interrupt on RA compare match
NVIC_EnableIRQ(TC0_IRQn); // Interrupt enable
TC0->TC_CHANNEL[0].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN; // Software trigger TC0 counter and enable
}
void TC0_Handler()
{
uint32_t status;
status = TC0->TC_CHANNEL[0].TC_SR; // Read and clear TC0 status register
if(status & TC_SR_CPAS) {
// Toggle pin 1
}
else // if(status & TC_SR_CPCS)
{
// Toggle pin 2
}
}
void loop() {
}