Thanks to "stimmer" I got the right frequency of 1HZ or Period of 1sec, luckily. My next step is to use the "Serial Monitor" to change the frequency.
When I use the following approach. And put something in the command line it starts to blink but it is not the exact frequency. Afterwards, when I put another amount in the command line, the frequency does not change.
What do you suggest to read from the Serial monitor to change the frequency?
Thank you.
volatile boolean l;
void TC0_Handler()
{
long dummy=REG_TC0_SR0; // vital - reading this clears some flag
// otherwise you get infinite interrupts
l= !l;
}
void setup(){
Serial.begin(9600);
pinMode(13,OUTPUT);
pinMode(2,OUTPUT); // port B pin 25
analogWrite(2,255); // sets up some other registers I haven't worked out yet
REG_PIOB_PDR = 1<<25; // disable PIO, enable peripheral
REG_PIOB_ABSR= 1<<25; // select peripheral B
REG_TC0_CMR0=0b00000000000010011100010000000000; // set channel mode register (see datasheet)
REG_TC0_CCR0=0b101; // start counter
REG_TC0_IER0=0b00010000; // enable interrupt on counter=rc
REG_TC0_IDR0=0b11101111; // disable other interrupts
NVIC_EnableIRQ(TC0_IRQn); // enable TC0 interrupts
}
void loop(){
digitalWrite(13,l);
if (Serial.available() > 0) {
int x = Serial.read();
REG_TC0_RC0 = x*pow(10,6); // counter period ---- POW (base, exponent) .5 ==> almost 1sec 10^8 = 0x5F5E100
}
}