Show Posts
Pages: 1 ... 77 78 [79] 80 81 ... 289
1171  Using Arduino / Microcontrollers / Re: How does "reset" work? on: October 27, 2013, 09:03:03 pm
@westfw, great explanation, thanks very much.  I bookmarked it but it deserves better!
1172  Using Arduino / Motors, Mechanics, and Power / Re: Arduino Power on: October 27, 2013, 08:52:23 pm
If there is damage, it may show up as some sort of problem with the pin it was connected to.  Or it may not.  Or something may happen at a later date.  Worst case scenario, the MCU would need to be replaced.  Easy on the Uno, not so easy on the Mega.
1173  Using Arduino / Programming Questions / Re: Trying to make accurate 20 KHz clock, not getting there on: October 27, 2013, 08:31:16 pm
Haha, saw that was on and thought about you!  Good luck, let me know.
1174  Using Arduino / Programming Questions / Re: Trying to make accurate 20 KHz clock, not getting there on: October 27, 2013, 08:17:16 pm
Here's the direct approach.  Seems like we should be able to do it with the library, but not sure what's going on with it.

Code:
//Arduino Uno, Arduino 1.0.5
//Output a given number of PWM cycles when button pressed

const unsigned int BUTTON_PIN = 2;
const unsigned int OUTPUT_PIN = 9;
const unsigned int NCYCLE = 336;              //number of cycles to output

void setup()
{
    pinMode (BUTTON_PIN, INPUT_PULLUP);
    pinMode(OUTPUT_PIN, OUTPUT);
    TCCR1B = _BV(WGM13);        //set mode 8 (phase & freq correct), and stop the timer
    TCCR1A = 0;                 //reset other WGM bits
    ICR1 = 399;                 //counter TOP value
    OCR1A = 199;                //this is the duty cycle, must be between 0 and 399
    TCNT1 = 0;                  //ensure we start at zero
    TIMSK1 = _BV(TOIE1);        //enable overflow interrupt
}

void loop()
{
    if (digitalRead(BUTTON_PIN) == LOW) {
        delay(300);
        TCCR1A = _BV(COM1A1) | _BV(COM1A0);      //inverting mode
        TCCR1B |= _BV(CS10);        //start the timer, prescale 1
    }
}

ISR(TIMER1_OVF_vect)
{
    static unsigned int intCount;

    if (++intCount > NCYCLE) {
        TCCR1B &= ~( _BV(CS12) | _BV(CS11) | _BV(CS10) );     //stop the timer
        TCCR1A &= ~( _BV(COM1A1) | _BV(COM1A0) );    //return the pin to normal mode
        intCount = 0;
        TCNT1 = 0;
    }
}
1175  Using Arduino / Programming Questions / Re: Trying to make accurate 20 KHz clock, not getting there on: October 27, 2013, 08:13:44 pm
You can look at this book!

??
1176  Using Arduino / Programming Questions / Re: Trying to make accurate 20 KHz clock, not getting there on: October 27, 2013, 07:43:51 pm
Yeah I think I can see the burst duration varying too.  Not sure why yet.
1177  Community / Exhibition / Gallery / Re: Vetinari Clock on: October 27, 2013, 07:16:14 pm
Nice project, but shouldn't it move the second hand forwards by the "countOfEvenNumbers + 1" ?
I guess, if it keeps good time, you must be doing that already.

Yes, in fact that is what it does.
1178  Using Arduino / Motors, Mechanics, and Power / Re: Arduino Power on: October 27, 2013, 07:15:38 pm
Wow, thanks for pointing that out, I actually hooked the relay directly to my Arduino, better to take it off now before it permanently damage my Ardunio.  smiley-confuse:~:~

Hope it's not already damaged.
1179  Using Arduino / Programming Questions / Re: Trying to make accurate 20 KHz clock, not getting there on: October 27, 2013, 07:14:53 pm
Trace 2 is the burst?
1180  Using Arduino / Programming Questions / Re: Trying to make accurate 20 KHz clock, not getting there on: October 27, 2013, 05:13:11 pm
Found a button smiley-grin

Code:
//Arduino Uno, Arduino 1.0.5
//Output a given number of PWM cycles when button pressed

#include <Button.h>        //https://github.com/JChristensen/Button
#include <TimerOne.h>      //http://playground.arduino.cc/code/timer1

const unsigned int BUTTON_PIN = 8;
const unsigned int OUTPUT_PIN = 9;
const unsigned int NCYCLE = 336;             //number of cycles to output
const unsigned long PERIOD = 25;             //length of half a cycle in microseconds
const unsigned int DUTY = 512;               //duty cycle as a number between 0 and 1023
const boolean BUTTON_PULLUP = true;
const boolean BUTTON_INVERT = true;
const unsigned long BUTTON_DEBOUNCE = 25;    //ms

Button btnStart(BUTTON_PIN, BUTTON_PULLUP, BUTTON_INVERT, BUTTON_DEBOUNCE);    //Declare the button

void setup()
{
    Timer1.attachInterrupt( timerIsr );
}

void loop()
{
    btnStart.read();       
    if (btnStart.wasPressed()) {
        Timer1.pwm(OUTPUT_PIN, DUTY, PERIOD);
    }
}

void timerIsr()
{
    static unsigned int toggleCount;

    if (++toggleCount > NCYCLE * 2) {
        Timer1.disablePwm(OUTPUT_PIN);
        toggleCount = 0;
    }
}
1181  Using Arduino / Programming Questions / Re: Trying to make accurate 20 KHz clock, not getting there on: October 27, 2013, 04:51:51 pm
Give this a try.  I didn't bother wiring up a button, am just generating the burst every 3 seconds.

Code:
//Arduino Uno, Arduino 1.0.5
//Output a given number of PWM cycles

#include <TimerOne.h>

const int OUTPUT_PIN = 9;
const unsigned long EVERY = 3000;        //start the burst every this many milliseconds
const int NCYCLE = 336;                  //number of cycles to output
const unsigned long PERIOD = 25;         //half a cycle in microseconds
const int DUTY = 512;                    //duty cycle as a number from 0 to 1023

void setup()
{
    Timer1.attachInterrupt( timerIsr ); // attach the service routine here
}

void loop()
{
    unsigned long ms = millis();
    static unsigned long lastStart;
   
    if (ms - lastStart >= EVERY) {
        lastStart += EVERY;
        Timer1.pwm(OUTPUT_PIN, DUTY, PERIOD);
    }
}

void timerIsr()
{
    static unsigned int toggleCount;

    if (++toggleCount > NCYCLE * 2) {
        Timer1.disablePwm(OUTPUT_PIN);
        toggleCount = 0;
    }
}
1182  Using Arduino / Programming Questions / Re: Trying to make accurate 20 KHz clock, not getting there on: October 27, 2013, 03:49:09 pm
Sure, give me a bit to look at the TimerOne library, I haven't used it before.  Let's see if it's easier to work with that or just program down to the bare metal.
1183  Using Arduino / Programming Questions / Re: Trying to make accurate 20 KHz clock, not getting there on: October 27, 2013, 03:30:20 pm
Use the compare match ISR to count the number of times the output pin is toggled, and turn off the timer after the desired number with
Code:
TCCR1B = 0;
1184  Using Arduino / Motors, Mechanics, and Power / Re: Arduino Power on: October 27, 2013, 03:15:01 pm
Well the VR module says 40mA.  I don't see a spec for the relay.  I might go ahead and hook it all up, and put a finger on the Arduino's voltage regulator.  If it gets uncomfortable to leave your finger there, find another AC adapter.

On another note, the relay should almost certainly not be connected directly to the Arduino, but should be driven by a transistor.  See the last page here for the proper way to connect it:
http://pgdev.pighixxx.com/ABC/SET/s1.pdf
1185  Community / Exhibition / Gallery / Re: Vetinari Clock on: October 27, 2013, 12:04:00 pm
Very good, Jack.

Thanks!

Quote
Although, that clock would drive me insane. smiley-wink

Well, that is part of the idea after all! smiley-grin  I've had one running here in my office for a couple months or so (with wires dangling out, connecting it to a breadboard) and I wondered about it at first too, but I got used to the sound pretty quickly.  Think of it as low-frequency white noise smiley-grin
Pages: 1 ... 77 78 [79] 80 81 ... 289