Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: sampling rates? on: April 27, 2011, 09:04:56 am
RetroLefty said:
For real high speed event timing it's best to utilize external digital logic chips to build a high speed counter that could be clocked at say 50Mhz and have one photosensor start the counter and the second one stop the counter and then have the Arduino read the count value and reset the external counter for the next timing event. It would take just a couple of chips and a crystal oscillator to create such a critter.

The laser was the easiest way for me to experiment with the pulsein() I was reading about.  I will look at building external logic on breadboard and using my UNO to control/reset the chips as you said.  Endless fun with parts ;-)

Johnwasser said:
The ATmega has built-in counters and timers...  Perhaps use the light sensors to trigger interrupts.  On the first one, reset a timer.  On the second, save the timer value.

This was what I was trying to do in the first place.  But not using interrupts.  In the laser example the actual first attempt had the two sensing diodes 4 INCHES apart and I was only 30 FEET from the laser (backyard) and trying to use millis() to compare the two events .. even with micros() none of the readings I got made any sense .. like I said .. there is some geometry I am forgetting about radians arc seconds etc that I didn't factor in .. but it was just an experiment to compare two sensed beams without actually haveing two transmitters aimed perfectly at two diodes.  I think what I built would have worked for something as slow as a race car passing two transmitters at 400mph and breaking the beams to my breadboard.  The rest was a quest for further understanding.
2  Using Arduino / Programming Questions / Re: sampling rates? on: April 26, 2011, 10:25:46 pm
When I say very fast try 62,830 feet/second  ( when I did the math for what I was trying to do I went DAMN that is faster than I thought ).
Are you sure of your math? 62,830 foot/seconds is equal to 42,838.64 miles per hour! That is faster than Earth escape velocity. What could you possible be trying to measure that moves that fast?

is possible I am wrong ... lets see .. Rotary Laser ... 1000ft range .. 600rpm
circumference = 1000ft X 2 X 3.14 = 3280feet
rotational speed is 600rpm so beam travels 3280feet 600times in a minutes or 3768000feet/min or 62800feet/second or 62.8feet/millisecond or .0628feet/microsecond or .75inches/microsecond

Assuming that 1000feet range and 600rpm (easy enough to measure rotational speed with only one photo diode) it will take the rotating laser 16microseconds to travel 12inches around the circle or 32microseconds to travel 24inches.   However if only the 24inches between photodiodes is known ... could I measure the distance from the center by counting how long it takes for the laser to travel the 24inches?

I am thinking that micros() isn't accurate enough to get an accurate time measurment as it will always be multiple of 4 microseconds.

There might be some geometry I am forgetting about but I think what I was asking about is still valid  How long does it take to do the functions and how long does it take to register the change in state of the digital pin.  How slow does the event need to occur to be to be assured that EVERY event gets measured?

3  Using Arduino / Programming Questions / sampling rates? on: April 26, 2011, 06:23:36 pm
I am trying to learn by reading other posts here and in some cases building stuff to test my working knowledge about what I "think" I learned.  I know I can use a photo transister to measure when a light is on/off or use a magnetic reed switch to test open/closed on any of the digital input pins.  What I am unclear of is how fast the microcontroller can it sense these changes?  For example if I have a magnet on a bike wheel I can "count" how many revolutions with a switch ( I realize this example is slow ), but is there a rate where the "counter" will start missing a closed switch?  If i use a emmitter / receiver pair to measure pulses of light ( like inside a mouse ) is there a rate where the samples will begin to be inaccurate?

And in the opposite direction .. how fast can I measure changes on the digital pins and what is the fastest way to measure the changes on a digital pin.

Where I am going with this is to have TWO photo diodes on two different input pins and compare the times that both diodes sense a beam of light.  I can use pulsein() to sense a pulse on first diode and micros() to timestamp the pulse then pulsein() to sense the pulse on the second diode and micros() to timestamp that one then a little math to get the difference in time between when the pulses come in and then calculate the speed.  I just don't have a feel for how fast execution of functions happens within a program.  For example if something is traveling very fast past two beams of light how long it takes to execute the sensing determines how far apart to put the sensors.  When I say very fast try 62,830 feet/second  ( when I did the math for what I was trying to do I went DAMN that is faster than I thought ).  How far will it travel during the execution time of the program functions so I don't miss the second pulse?

4  Using Arduino / General Electronics / Re: arduino uno power hog? on: April 12, 2011, 09:42:36 pm
Thanks for the quick answers .. unfortunately now raises several new questions:

Crossroads said:
And if you're running delay, you've got the processor running full time too, got the power LED on the whole time, got the at8mu2 running full time, if your unused pins are left floating as inputs you've got potentlal switching losses there (best to set unused pins as inputs with internal pullups enabled).

You'd be way better off running of 3 AAs direct to the 5V header pin, bypassing the regulator.

I am still learning but is there a way to shut down the at8mu2, power LED, and processor for a specified length of time.  I can set the unused pins as you suggest but have not done it in this case as all the examples leave all the unused pins alone in the sketches and didn't know this would be a problem.

Last part of your reply was to apply 3 AAs to the 5V header .. 3X1.5(or as pointed out for rechargables1.25)=4.5V(3.75v) .. I was under the impression that you needed to have a 5v supply to the 328p but after looking it up Vcc can be 1.8-5.5v .. does lower voltages effect the ocillator timers and such or the reliability of the chip to operate?

MarkT said:
A rechargeable 9V battery reduces the cost over alkaline---but they are normally 150mAh or so, whereas AA's are 2000mAh (13 times the life).  And if using rechargeable AA's then use 4, not 3, as they are about 1.25 to 1.3V each rather than 1.5V for alkaline.

Untill you told me I had no idea that there was that much of a difference in mAh between the two types of batteries.  For now I am working on a computer upstairs and the breadboard in the basement and thought being able to run the UNO from a "portable 9V supply" would be a good idea.  I will just rip a PC supply out of a junk PC and use for 5V supply on the workbench (come to think of it I will have 12V and 3.3V also)  Eventually I will have a PC downstairs running Linux with Arduino IDE running on it so will have the USB port downstairs too.

Thanks again guys,
5  Using Arduino / General Electronics / arduino uno power hog? on: April 11, 2011, 10:14:10 pm
I have been playing a little with my new Arduino UNO and built a little "timer" that blinks an LED 3 times after a selectable time delay of from 1minute to 4 hours.  the ONLY hardware I have attached to my UNO is 16pin DIP switch and a single LED/resister.  The switch grounds the "input" pins, program does a little math, delay(SelectedDelay) happens and then blinks the LED on the "output" pin .... Everything works exactly as I expected it to when loaded..

Then I decided to see if I can use a 9v battery to power my UNO and run the timer without being hooked to my USB cable.  It works fine except that it doesn't last very long at all .. if set for 20min delay I get about 3 hours before the green power LED on my UNO goes out.  Is this normal??  Why does the UNO suck the life out of a 9v battery so fast?

6  Using Arduino / Programming Questions / differances between "coding" with arduino ide vs. AVR ide on: April 11, 2011, 09:55:00 pm
I have been tinkering with different sketches included with the Arduino IDE and some on the net.  I came accross some "code" that is "compiled" using the AVR IDE loaded on an ATmega8 through a STK500 developer board.  I have a Arduino UNO board with the ATmega328p and would like to know if I can adapt the code for the 328p or would I have to start over from scratch and build the entire sketch from the ground up as the writer did in AVR IDE back in the beginning of 2008.  I am a little fuzzy with the stuff that happens after you hit the upload button on a sketch.  His code starts with the following lines:
#include <stdint.h>\par
#include <stdlib.h>\par
#include <inttypes.h>\par
#include <avr/eeprom.h>\par
#include <avr/interrupt.h>\par
#include <avr/io.h>\par
#include <avr/pgmspace.h>\par
#include <avr/sleep.h>\par
#include <avr/wdt.h>\par

so does the Arduino IDE add stuff like this to the program before it 'compiles' it into something the chip can execute?

7  Using Arduino / General Electronics / Re: using digital pins and "pull up" and "pull down" resisters on: March 31, 2011, 04:47:44 pm
V->10K resister->pin2 set as input->N/O switch->GND --- resister here is pull up

This is the most common, mostly because the Arduino microcontroller has built-in pullup resistors that can be enabled so you don't even need the external resistor. Make sure "V" in your hookup is 5V and not some arbitrary voltage.

In my origional question I had the 5V and will be using the 5V socket on the UNO as source.  How do you "enable" the built-in pullup resistors inside the 328?  For now I will use the 10K resister but would be nice not to have the extra components.

8  Using Arduino / General Electronics / using digital pins and "pull up" and "pull down" resisters on: March 31, 2011, 09:55:06 am
I am new to my Arduino Uno and am a little fuzzy on the pin voltages and use of "pull up" and "pull down" resisters.  I might be thinking wrong but what I am trying to do is attach a couple of switches to the digital pins and modify the "blink" sketch to check the switches (input) and based on which switches are closed select a value to use in the delay(XXXX) portion of the loop.  It is my understanding that during the delay the Arduino does nothing but is it safe to change the switches under power?  I will be using a DIP switch to select 4 different pins either HIGH or LOW and using the resulting binary combinations to give me 16 selectable values for the delay().  The delay will be from 2 to 32 MINUTES so it will be unlikely to be in middle of switching when board checks the switch settings, but what I am worried about it do I need to remove power/hold reset button when changing the DIP positions?

Am I correct in understanding that the position of the resister determines if pull-down or pull-up and it can be either with the same components.  I don't know how to make image here but if:
 5V->N/O switch->pin2 set as input->10K resister->GND --- resister here is pull down
 5V->10K resister->pin2 set as input->N/O switch->GND --- resister here is pull up
only difference is if check for HIGH or LOW on pin2 correct so far??
and since there is no real difference between a closed DIP switch and a N/O switch with a finger pushing on it continuously or open DIP switch and a N/O switch released, IF is safe to swich under power I can test the sketch with 4 pushbuttons and short delay values first .  Just don't want to hurt the board if not safe to do this under power.

9  Using Arduino / Programming Questions / Re: writing your own functions? on: March 09, 2011, 10:26:29 am
If you really want to learn C/C++, get set up on a Linux box with a full gcc dev system
unfortunately I am on a fixed income and I just had to replace a "kick butt gaming" computer with a "what I could afford" computer when the video card fried on the "kick butt" and took out the MB as well.  I might be able to cobble together another computer from spare parts but that would be months down the road with no guarantees of a Linux box.  Gonna stick with the working machine for a while.
10  Using Arduino / Programming Questions / Re: Beginner programming question on: March 08, 2011, 10:56:16 pm
You can look at the code in "init()" in a source file called "wiring.c" in your distribution

I looked in several of the directories installed when I installed Arduino IDE but didn't find any file called "wiring.c"  Found "wiring.cpp" and "wire.h" which begs me to ask this question:
What are the different file extensions and what do they contain?  I have seen the following online referenced and don't know where they come from or whether I can copy/paste the examples into code of my own:

Clearing this part up will help me a lot.
11  Using Arduino / Programming Questions / Re: writing your own functions? on: March 08, 2011, 10:27:28 pm
Thank you to both Gardner and cr0sh for your VERY instructional replies.  You both caught the ending bracket being missing but that was a simple mistake in my cut/paste from the code I wrote.  I understand what you mean about the readablility aspect of keeping the brackets lined up and I will try to follow this in the future.  So my understanding is that if the variables are defined outside of ALL functions it is global and can be changed by any function.  If it is defined inside a function (even the "main"), calls outside the defining function don't effect that value when the called function is over.  It would seem that very specific variables would usually not be effected but it would allow something like
void function() {
  int x = 0;
  for (int i=0; i < 10; i++) {
    //do something here;
  x += 1;
so the counter variable could be used within the function and you don't need to worry about effecting a simular counter outside the function??

as for the brackets again... they don't seem to actually end up as part of the code just something to make sure the compiler does what you really want it to do and make sure you can read what you are actually doing.

I have checked out several books on C and they seem harder because the books are outdated and the only "editor" that I have is the Arduion IDE and it doesn't force you to put all the #include statements at the beginning and much is done in between the coding "I write" and the "coding sent to the compiler" that I know nothing about.  Even tutorials online are old and refer to WINAVR and AVRDude as separate things to download or something.  But I have only had my Arduino Uno for a week.  I will get it down.

Again thanks for the tutorial, it really helped me understand it.

12  Using Arduino / Programming Questions / writing your own functions? on: March 08, 2011, 04:36:58 pm
In reading through some of the questions and answers Pixelk stated in another thread
it seems more efficient to split my main function ( MenuUpdate ) into many small functions
and since I am new to C the only understanding I have is that a function is "simular" to a subroutine but I would like to know how they differ and HOW to write your own functions.  The only programming I have done prior to getting my Arduino Uno is in BASIC and I had a small collection of subroutines that I could just paste together to "get the job done"

While playing with LEDs I wrote the following code:

if (lastLED == 13)
      lastLED = 10;
  else lastLED = lastLED +1;

but COULD it have been something like:

void whichLED ( ) {
  if (nextLED == 13) {
        nextLED = 10;
       else {
       lastLED = lastLED +1;

And do i need all the { } brackets?
13  Using Arduino / Programming Questions / Beginner programming question on: March 06, 2011, 09:02:44 pm
I have finally gotten my Arduino Uno and after playing with the blink and fade routines a little bit to test if everything is working alright I noticed that there seems to be a bunch of stuff missing in the code.  Only the void setup() and void loop() portions.  Some of the other sketches have some definitions before the setup() or additional functions to be called from the loop() but when I was looking at some other examples in C they usually have stuff like #include <stdint.h> #include <stdlib.h> #include <inttypes.h> or such at the top.  Is the Arduino IDE automatically adding stuff to the "programming" I write and if so what is it adding?  If I have a programfile.c written by someone else (open source so no copywrite issues) do I have to do some editing of the programfile.c to make a programfile.pde usable by Arduino IDE to get it on my atmega MCU?
14  Using Arduino / Microcontrollers / Re: beginner (research stage) questions on: February 28, 2011, 01:07:45 am

<snip> Nothing in this chain of events uses AVR Studio and I'm pretty sure that you can only use 'real' hardware programmers with AVR Studio. Getting Arduino stuff working well in AVR Studio is a pretty complex topic, some may have done it, most have problems with all the gory details. I use only the Arduino IDE platform when doing stuff with Arduino boards and chips.

Ok.. If I understand you right I was confusing the AVR Studio IDE software with Arduino IDE software.  I already downloaded AVR Studio but didn't install from the download .. will get the Arduino IDE instead.
Thanks, Dmac257
15  Using Arduino / Microcontrollers / Re: beginner (research stage) questions on: February 25, 2011, 05:00:54 pm
Lefty said:

Originally one did need to buy or build a hardware programmer to burn bootloaders into blank chips. However there is now a sketch you can load onto a Uno board called ArduinoISP (it's in the example files) that will turn your Uno board into a hardware programmer that when wired correctly to a breadboard mounted blank chip, will burn the bootloader if the 'Arduino as ISP' programmer is selected from the burn bootloader options. This can be tricky getting everything set up correctly, but there is lots of help here from people that have done this.

So basically the Uno Board has a bootloader that allows you to load sketches into the Boards microcontroller, ArduinoISP sketch turnes the Uno into a the programmer and the blank microcontroller is wired up from the protoboard to the Uno Board to allow Studio to program the blank chip including burning the appropriate bootloader on the new chip.

Makes sense .. Glad I asked first !
Pages: [1] 2