Serial Monitor sucks!

I use Arduino Due and got help from you guys to make the frequency of 1HZ.
But when I use the Serial Monitor to change the frequency, something goes wrong.

I dunno even what exactly it takes and put into the register namely “REG_TC0_RC0”.

Can anyone help me with this please? Any ideas?


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(){
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=0b0000000000001001110001000… // 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(){


// send data only when you receive data:
while (Serial.available() > 0){

int x;

REG_TC0_RC0 = x*pow(10,6); // counter period ---- POW (base, exponent) 


Any ideas?

Post a complete program ? Get rid of the multiple blank lines ? Format the code to make it readable ? Don't use the pow() function when it is not necessary ? Print the value of x on the Serial monitor ?

I dunno even what exactly it takes and put into the register namely "REG_TC0_RC0".

Why not do a Serial.println( x ) to see what your getting. It's possible your send in a char and not an actual int.

REG_TC0_RC0 Is a string of characters, so your arduino code will need capture the individual characters sent by the serial monitor and reform them back into a string if you actually want REG_TC0_RC0 as the final product.

I guess that in order to compile this code I would need IDE version 1.5.2, but what about that dotdotdot symbol (ellipsis)?

REG_TC0_CMR0=0b0000000000001001110001000… // set channel mode register (see datasheet)

So, before we proceed, it would be good to know which program the serial monitor is talking to. It would be even better not to blame the serial monitor when there are plenty of alternative explanations for the malfunctions.

From your code I get that REG_TC0_SR0 is an unsigned long, presumably setting an interval for a timer (its definition, if it exists somewhere, is specific for the Due). And you certainly know that 10^6 is 1,000,000 so you don’t need to recalculate it each time you read a char, and you don’t need the pow function. The formula thus becomes:

REG_TC0_SR0 = x * 1000000UL;

Now the only thing you have to consider is that x ranges from 0 to 255. If you send the character ‘1’ it will translate into 49. If you send a space, x becomes 32. If you send a carriage return, x becomes 13. The ASCII table says the rest. If you wish to set x to 1 by sending the character ‘1’ you’ll have to subtract 48, but also make sure (insert an if to make sure) that you don’t send negative numbers.

I'm guessing serial isn't working the way you expect: