Show Posts
Pages: 1 2 3 [4] 5 6 ... 115
46  Using Arduino / Microcontrollers / Re: Interval time between 2 consecutive commands. on: June 12, 2014, 03:48:20 am
if (millis()<1000){
counter +=1;
That will keep counting as fast as possible while millis() is less than 1000, i.e. during the first 1000milliseconds of running. Once millis() is larger than that, it will never increment counter again.
In one second of operation, there could be tens of thousands of increments depending on how many instructions it takes to get through the loop() and check millis(). [EDIT: 97610 on my Arduino Mega]
47  Using Arduino / General Electronics / Re: How to distinguish between ‘reset’ and ‘real power loss’ ? on: June 12, 2014, 03:37:31 am
No, it's a hardware feature of the chip.
Partly, but it is also thanks to some of the abstraction from avr-libc.

This is accessing a register without that:
byte value;
asm volatile ("in %0, 0x34 \n\t" :"=r" (value) );
print("MCUSR = ");
or possibly:
volatile byte* ptr;
ptr = (volatile byte*)0x54; //note adding 0x20 as this treats them as mapped into SRAM.
byte value = *ptr;
print("MCUSR = ");
vs. this with the abstraction:
byte value = MCUSR;
print("MCUSR = ");
48  Using Arduino / General Electronics / Re: How to distinguish between ‘reset’ and ‘real power loss’ ? on: June 11, 2014, 05:07:48 pm
This would be a more sensible (and functional) code:
void setup() {

  Serial.print("MCUSR: ");
  if (MCUSR & _BV(EXTRF)){
      // Reset button or otherwise some software reset
      Serial.println("Reset button was pressed.");
  if (MCUSR & (_BV(BORF) | _BV(PORF))){
       // Brownout or Power On
       Serial.println("Power loss occured!");
  if (MCUSR & _BV(WDRF)){
       //Watchdog Reset
       Serial.println("Watchdog Reset");
  // Clear all MCUSR registers immediately for 'next use'
  MCUSR = 0;

The case statement you had would either work if ONLY and external reset occurred, or if ALL 3 of brownout, power on and reset occurred.
The above code filters the events and detects correctly if either an external reset occurred, or if ANY of brownout or power on occurred. Plus if you press the reset button before it gets to the point of clearing MCUSR, it will allow you to see that too.

Granted you still have the problem of optiboot. Almost worth building a standalone ATMega circuit and using ISP to program it (no bootloader). The bootloader would delay the execution of the reset check code anyway.
49  Using Arduino / General Electronics / Re: New Grad working in Industry, want to use MCU's to collect and send 24v DC on: June 11, 2014, 04:59:48 pm
The simple voltage divider circuit could handle that (peak current ~4 A, typical ~1-2)

You serious??? 2+A through a simple voltage divider? From 24V down to 5V, that would be 38W wasted giving an efficiency of 20%.
50  Using Arduino / Microcontrollers / Re: ATTiny87 core? on: June 11, 2014, 12:17:12 pm
You could go for the ATTiny167, which is supported. It is basically the same as the 87, but with more flash.

The only thing that doesn't support the 167 directly is avrdude, though if you add the lines from the attached file into your avrdude.conf file, it will work fine.
51  International / Generale / Re: Aggiungere una MCU compatibile all'IDE on: June 09, 2014, 06:20:07 pm
Please try the patched version:
52  Using Arduino / Programming Questions / Re: TM1638 and the keyboard library, how do I assign keystrokes to a HEX/BIN number? on: June 09, 2014, 04:47:10 am
Hex, Binary, Decimal, Octal. In the end they all compile to the same, there is no difference as far as the processor is concerned.

You will have to be more specific and specify what you want the numbers to look like.
53  Using Arduino / Programming Questions / Re: Cheap and cheerful way to save power? on: June 08, 2014, 03:54:03 am
The best power saving technique, however, is to lower the clock below 16MHz if the design will permit.  In fact, running at 1 MHz is often adequate.
If you are doing something really simple that needs to be ultra low power, you can even run it at 16kHz using the watchdog oscillator and 1/8 prescaler!

As has been said, there is so much other 'stuff' (e.g. usb-serial, power led, regulator, etc.) on an Arduino that there is almost no point sleeping the ATMega chip to save power, it would be like trying to use a pebble to slow a Niagara falls.
For a standalone chip in a carefully designed circuit, the savings are however quite substantial. I've built a dice circuit with a few 1M resistors and an ultra low power op-amp. When running the whole thing draws 1mA (including the LEDS). When the CPU is put into power down mode (to be woken by the op-amp), the whole circuit draws 2uA from a battery - less than the self discharge rate of the coin cell I am using.

The sleep idea can be quite useful for other things than just power saving though. You can use it as part of your program. Imagine that you want to blink an LED, you could toggle the pin and the have a delay(), or you could have a timer running which wakes the CPU at certain intervals and toggles the LED in the interrupt.
54  Using Arduino / Programming Questions / Re: Modify Value within included library on: June 07, 2014, 06:12:32 pm
It is in the header file, which is included, so just use it like any other variable.

As I suspected however, this won't work. In the TLC5940.cpp file you will find this line:
uint8_t tlc_GSData[NUM_TLCS * 24];
That number is expected to be a compile time constant, not a variable. It may work if you replace the line above with a constant number which is the maximum you will ever have and then you should be able to make NUM_TLCS variable.

Why are you trying to change the number?
55  Using Arduino / Programming Questions / Re: Modify Value within included library on: June 07, 2014, 03:15:41 pm
If NUM_TLCS is a #define then it is not possible. These are evaluated to constants at compile time and so cannot be changed during execution.

You could however change the #define to a variable, such as  "byte NUM_TLCS = 0". Then you could simply change this value as any variable. Be careful though, there may be some parts of the library that expect a constant and simply changing the value as a variable would have unexpected consequences.
56  Using Arduino / Microcontrollers / Re: Trouble with using the internal clock on: June 04, 2014, 07:57:42 am
Doesn't matter about the 3.3V, the programmer has no idea, all that is important is the clock frequency and processor. Use the "Arduino pro or mini pro (3.3v,8mhz) with atmega328" entry and you should be fine.
57  Using Arduino / Microcontrollers / Re: Trouble with using the internal clock on: June 04, 2014, 04:27:57 am
Do you have any entries in the boards menu already that mention 8MHz?
58  Using Arduino / Microcontrollers / Re: Looking for arduino boards or its clones on: June 04, 2014, 04:24:05 am
Perhaps you could be *much* more specific.

"A little more powerful" - how powerful?
"a decent amount of memory" - how much memory?
"capable of running an OS" - which os?

What are you trying to do with it?

It seems like you don't want an Arduino at all, but unless you tell use your application it is difficult to know for sure. Perhaps something like the pcDuino3 or Raspberry Pi might be more suitable.
59  Using Arduino / General Electronics / Re: How to fix ringing on a square wave on: May 31, 2014, 08:13:35 am
Assuming it is a digital signal you want, the attached circuit would take your noisy 0Vmin to 1Vmax signal and convert it into a clean 5V logic signal which can be fed directly into a digital input of an Arduino (no need for analogue).

The trigger has threshold voltages of 0.8V and 0.2V for low-high and high-low respectively meaning the input signal can have up to a 1.4Vp-p noise signal and still be correctly converted into digital.

Make sure that if you use it, the op-amp is a rail-to-rail type and is compatible with having 0V on its negative supply terminal. Alternatively an analog comparator could be used instead of the op-amp which is probably a better choice for this sort of circuit - something like an MCP6541.
60  Using Arduino / General Electronics / Re: How to fix ringing on a square wave on: May 30, 2014, 06:44:52 pm
If you are worried about it, add a Schmitt trigger buffer into the circuit. The hysteresis loop of the buffer will ensure that the ringing will be removed (unless it is very large - say >6Vpp depending on the parameters of the buffer).
Pages: 1 2 3 [4] 5 6 ... 115