So I have been struggling to make this chip output a 2.5 khz signal.
I think I have managed to output this, but now I need to oscillate up and down +/- 500 Hz.
So I will need the square signal to go from 2000 to 3000 kHz.
This is the code I have done to output the signal.
Mod edit: added code tags
I have used a 64 prescaler, with a 50.05 value of comparison, this after trying several combinations I think this works the best. I need to keep the 50 % duty cycle I am on right now.
Do you have any ideas, suggestions ??
Thanks in advance for your time.
----------------------------------------------------------------------------------------------------------------
EDIT
I was able to output a constant 2.5 kHz, yes. But now my issue is to make it oscillate the 500 Hz. I tried to do that by changing the comparison value from 63.05 to 41.5 which are the values of 2.0 and 3.0 kHz respectively. But it doesn't do that, the duty cycle changes and my actual range of values are from 1.2 to 9 kHz.
What options do I have ?
I think I have managed to output this, but now I need to oscillate up and down +/- 500 Hz.
So I will need the square signal to go from 2000 to 3000 kHz.
This is the code I have done to output the signal.
C:
void setup()
{
DDRB |= bit (PB0); // Set pin PB0 as output
// stop Timer 0
TCCR0A = 0;
TCCR0B = 0;
TCNT0 = 0;
// set up Timer 0
TCCR0A |= bit (COM0A0); // Toggle OC0A/OC0B on Compare Match
//TCCR0B |= bit (CS01); //With this setting prescaler to 8
//TCCR0B |= bit (CS00);// | bit (CS01); // Prescaler of 1024
TCCR0B |= bit (CS00) | bit (CS01); // Prescaler of 64
TCCR0A |= bit (WGM01); // Start Timer 0 in CTC mode
OCR0A = 50.05; // CTC Compare value (count up to 128)
}
void loop()
{
}
I have used a 64 prescaler, with a 50.05 value of comparison, this after trying several combinations I think this works the best. I need to keep the 50 % duty cycle I am on right now.
Do you have any ideas, suggestions ??
Thanks in advance for your time.
----------------------------------------------------------------------------------------------------------------
EDIT
I was able to output a constant 2.5 kHz, yes. But now my issue is to make it oscillate the 500 Hz. I tried to do that by changing the comparison value from 63.05 to 41.5 which are the values of 2.0 and 3.0 kHz respectively. But it doesn't do that, the duty cycle changes and my actual range of values are from 1.2 to 9 kHz.
What options do I have ?
Last edited by a moderator: