Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Timer2 Interrups REFUSE to work! :( on: September 18, 2012, 10:01:23 pm
I also didn't see anything referring to #include <interrupts.h> (I didn't need to in my case) nor interrupts() or sei()
2  Using Arduino / Programming Questions / Re: Timer2 Interrups REFUSE to work! :( on: September 18, 2012, 09:52:57 pm
Consider this code which "checks" the value of foo, a global variable that gets updated via ISR
Code:
unsigned int foo = 0;
ISR(blahblah)
{
//update foo here
}

void loop ()
{
 while (foo == 0); /wait for foo to get updated
//do stuff after foo gets updated
}

Your while loop would never exit, because the compiler will read from the register(memory bank) which previously held "latest" value of foo instead of force reading the actual value from RAM.

Check out Nicks awesome page about interrupts: http://www.gammon.com.au/forum/?id=11488

Is there any way you can add in some debugging functions to send some output to the serial port, etc? I think that will be the easiest way to debug whats going on instead of just eye-balling the code and making changes
3  Using Arduino / Programming Questions / Re: Timer2 Interrups REFUSE to work! :( on: September 18, 2012, 08:59:43 pm
I don't see any variables being declared as volatile. If an interrupt service routine is going to update variables they should be marked as volatile.

Specifically:
seconds -- TIMER2_OVF_vect
minutes -- TIMER2_OVF_vect
hours -- TIMER2_OVF_vect
show_the_time -- INT0_vect
4  Using Arduino / Project Guidance / Re: Electronic Door Lock keypad with Arduino on: September 18, 2012, 08:52:32 pm
If there is an H-bridge, the outputs will be connected to the black and red wires that go to the motor/actuator.

I can't tell from the pictures taken what drives the actuator.
5  Using Arduino / Project Guidance / Re: What plug do I use to connect 3 pin plug to arduino board? on: September 18, 2012, 08:39:57 pm
About the sensor:
What 3 pin plug on what sensor? Analog or digital?
6  Using Arduino / Networking, Protocols, and Devices / Re: HELP HELP HELP ETHERCAT on: September 13, 2012, 05:06:53 pm
EtherCAT slave implementation guide: http://www.ethercat.org/pdf/english/ETG2200_V2i0i0_SlaveImplementationGuide.pdf

Source: http://www.ethercat.org/en/publications.html#info
I would suggest becoming a member of the EtherCAT Technologies Group for more resources.
7  Using Arduino / Networking, Protocols, and Devices / Re: Ethernet Sniffer on: September 13, 2012, 05:01:39 pm
You will need to see if the ethernet interface chip supports promiscuous mode or something similar (that's what it's called on computers).

As far as libraries that are already developed, your top two choices will be WIZnets W5100 or Microchips ENC28J60
8  Using Arduino / Installation & Troubleshooting / Re: Arduino UNO, all of a sudden can't upload programs on: September 13, 2012, 04:55:52 pm
Check the "Devices and Printers" icon in the control panel. You should have it listed there and it's properties will tell you the COM port its on as well as let you switch it.

If not, check the Device Manager under "Ports (COM AND LPT)" Make sure it isn't disabled and doesn't have any error codes.
9  Using Arduino / Programming Questions / Re: Bitshit question. on: September 13, 2012, 04:35:39 pm
Quote
if that Supported_PID20 has 00010000000000000000000000000000 in it and unsigned long

That is a VERY large number, much larger than can fit into a unsigned long. Is that decimal or binary representation?

10  Using Arduino / Project Guidance / Re: gracefully shutdown a windows computer with arduino on: September 12, 2012, 08:25:18 pm
Windows XP provides an interface for a uninterpretable power supply shut down via a com port.

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/pwrmn_ups_configure_ups.mspx?mfr=true

You could configure windows to look on the arduino com port, and emulate the APC smart protocol

http://www.networkupstools.org/ups-protocols/apcsmart.html
11  Using Arduino / Project Guidance / Re: Driver Mosfet on: September 10, 2012, 10:54:48 pm
From a low cost standpoint, I would probably go with a logic-level N channel mosfet. This would allow me to switch the load between ground or open circuit (which would actually have a flyback diode of course). http://electronics-diy.com/electronic_schematic.php?id=1020



You could also switch the power supply to the circuit, commonly done using a P channel mosfet (but possible with an N channel). http://www.irf.com/product-info/hexfet/ips.html

If you have problems getting logic-level mosfets, then the mosfet driver is the way to go, such as the one you have mentioned. There are other needs that require mosfet drivers as well.
12  Using Arduino / Project Guidance / Re: how to generate less than microsecond delay? on: September 10, 2012, 10:42:25 pm
Check the microcontroller data sheet. For the Arduino Uno with the ATmega328, www.atmel.com/Images/doc8161.pdf#page=429 the PDF says the NOP instructions takes 1 clock cycle.

For a 16 MHz clock, 1 NOP takes 1/16MHz to complete, https://www.google.com/search?q=(1%2F(16*10^6))+seconds+to+nanoseconds
13  Using Arduino / Project Guidance / Re: Maze solver "stop" method? on: September 07, 2012, 05:33:18 pm
Don't forget to handle the case where millis() rolls back over to 0 just like an odometer in a car. That is sure to throw you for a loop down the road

smiley-wink
14  Using Arduino / Project Guidance / Re: Maximizing ADC abilities on: September 07, 2012, 02:36:56 am
I have to say, that is an excellent idea.

So the ADC would loop over a single buffer and the read function would be a few samples behind. So the only requirement there would be that the read function be just a bit faster than my ADC routine (unless this was a finite event)

Actually this method works to my advantage because the wireless module I plan on using (NRF24L01 aka mirf) has a max packet size of 32 bytes. I'll just blast off 32 samples at a time (given 8 bit samples)
15  Using Arduino / Project Guidance / Maximizing ADC abilities on: September 07, 2012, 01:59:52 am
I've been thinking about a larger project but what is currently slowing me down is the ADC implementation.  I'll be looking to digitize human voice, walkie-talkie style (high frequencies aren't of interest).

Using the Ardunio Uno, with the ATMega328, the ADC is rated 15 kSaps at maximum resolution -> www.atmel.com/Images/doc8161.pdf#page=250
Using the analogRead function built into Arduino has some redundancies I would need to bypass (setting up ADMUX, using 10 bits when I only want 8 right now, blocking call) (see arduino-1.0.1\hardware\arduino\cores\arduinowiring_analog.c)
So I propose an interrupt based method using ISR(ADC_vect) to fill up two finite buffers, then the interrupt triggers another conversion.  Should one buffer be full, the ADC reading will be placed in the other buffer.
This double buffering method would allow a chunk of readings to be transmitted while simultaneously acquiring. The transmitting of chunks would actually be in a timer ISR such that the only code in the loop() would be for updating LCD screen, user input/ouput etc.

Any comments on the double buffering method? Here is what I've come up with so far using 10 bit ADC results, a single buffer length of 500 and transfers over serial port for debug.

Code:
#include <avr/interrupt.h>

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif


#define ADClength 500
 unsigned int ADCreadings[ADClength]; //my implementation of a buffer
 unsigned int ADCpos = 0; //current write position of the buffer
 
void setup() {
  Serial.begin(115200);
  sbi(ADCSRA, ADIE);  // Enable ADC Interrupt
 
  sbi(ADCSRA, ADPS2); //Set the ADC prescaler to
  sbi(ADCSRA, ADPS1); //  110 which is
  cbi(ADCSRA, ADPS0); //   divide by 64
 
 
  sbi(ADCSRA, ADEN); //Enable ADC conversions
  ADMUX = (DEFAULT << 6) | (0 & 0x07); //taken from Arduino_wirings.c sets up AVCC reference and pin 0
  sbi(ADCSRA, ADSC); //Start a ADC conversion to get the whole thing started
}
 
 void loop(){

    if (ADCpos >= ADClength) { //Is the buffer at max capacity?
      for (int i = 0; i < ADClength; i++) {//if yes, then print over serial port all values
       Serial.println(ADCreadings[i]);
      }
      ADCpos = 0; //reset the position
      sbi(ADCSRA, ADSC);//restart ADC conversions
    }
 }
 
 ISR(ADC_vect)
{
  byte high, low;
  low = ADCL; //Must read ADCL before
  high = ADCH; //  ADCH
      if (ADCpos < ADClength) {//Do we have room in the buffer?
ADCreadings[ADCpos++] = (high << 8) | low; //Yes, add in the 10 bit sample.
        sbi(ADCSRA, ADSC); //start another conversion
      }
}
Pages: [1]