Hi everyone,
My name is Aneel Devaraju. I am working on a Senior Design project at University of North Texas, USA.
This project is where I and another person build an inductive charger which gives maximum results, while using minimum power.
We are using the Arduino UNO, Rev 3 MCU for this project.
We initial found a code where we can changed the UNO frequency output from 40kHz to any frequency higher then 40. The original code is in the website below:
http://www.fiz-ix.com/2012/01/how-to-configure-arduino-timer-2-registers-to-drive-an-ultrasonic-transducer-with-a-square-wave/
(This is listed to source the person of the original code; my partner and I DO NOT want ourselves to get in trouble)
Our code below is a modified version of the code to suit our pruposes:
// constants won't change. Used here to
// set pin numbers:
const int ledPin = 13
; // the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
long previousstate = 0;
long interval =400;
void startTransducer()
{
TCCR2A = _BV(COM2A0) | _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(WGM22) | _BV(CS20);
OCR2A = B10010000; // 400, so timer2 counts from 0 to 400 (400 cycles at 16 MHz)
}
void setup()
{
pinMode(ledPin, OUTPUT);
startTransducer();
}
void loop()
{
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentstate = OCR2A;
if(currentstate=110) {
//previousstate=currentstate;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}}
We started the long interval with 99, then went to, 100, then 110 (these values are the number of cycles)
For a 40kHz frequency, we know that it requires 200 cycles to produce that frequency. So what I did was that in order to produce an 80kHz frequency, I calculated that 400 cycles would be needed. However, I have learned that 400 cycles would give us 1/2 of 40kHz.
I tested the above code, and somehow it gives an output of 90kHz, instead of 80kHz. (I tested the code with 99,100,110 cycles , and still we result an output of 90 kHz, instead)
Please review the above code and let me know as soon as possible with what is wrong in the syntax of the code. Thanks.
BR,
Aneel Devaraju