Show Posts
Pages: 1 [2] 3 4 ... 14
16  Forum 2005-2010 (read only) / Bugs & Suggestions / Large installation on Mac OS X on: March 21, 2007, 05:33:36 pm
The arduino-0007 installer for mac os x has unstripped avr development tools and duplicates of many of the tools in tools/avr/avr/bin. That could be slimmed down by about a factor of four by stripping and eliminating duplicates.
17  Forum 2005-2010 (read only) / Syntax & Programs / Re: string to int (pwm) on: April 11, 2007, 12:44:09 pm
You can use the standard C library function atoi(). It takes a string in decimal and returns an integer. I just checked and it only adds about 120 bytes to the sketch.
18  Forum 2005-2010 (read only) / Syntax & Programs / Re: Softwareserial on: April 13, 2007, 05:10:53 pm
SoftwareSerial has some timing issues. It doesn't push the tx pin high when started, that can ruin the first character, but you can work around that by setting it high when you set the pinmode for it.

Worse, the rather expensive math operation to compute the bit delay gets shuffled into an unfortunate code path and makes the start bit be about 1.5 bit times long ensuring that your bits are sampled on the edges instead of the centers

Still, I wouldn't expect you to get nothing from that. I'd expect you to get a few percent of your characters garbled, or all of them, depending on the timing of your receiver's uart.

(Patches are in the works for 0008 software serial to stabilize it.)

SoftwareSerial::begin() just stores your bit rate in an instance variable. It seems unlikely that could cause a problem directly unless you have run out of SRAM. If you don't do a ::begin() you will get a divide by zero error in print. I don't know what that does.
19  Forum 2005-2010 (read only) / Syntax & Programs / Re: measure time <1ms on: June 10, 2007, 02:33:48 pm
All of the outputs on the Arduino are PWM, that is just the way it works. You would only use the ones driven by the counter you mess with, and you could probably choose a mode where they would work, just not in "phase correct pwm" which  is the mode that causes downward counting.

Writing to a register, like TCCR1A is just like assigning a variable.
20  Forum 2005-2010 (read only) / Syntax & Programs / Re: measure time <1ms on: June 09, 2007, 06:46:50 pm
It is the delay(900) at the bottom. This waits for a counter that is incremented by TCNT0 rolling over so your code is always called not too long after the rollover.

About TCNT1, 16 bits is better, but... The way it is configured in the arduino I think it counts from 0 up to a limit based on your PWM output and then back down to 0. That would be difficult or impossible to interpret. You could change the counter mode, but you would lose the analog output.
21  Forum 2005-2010 (read only) / Syntax & Programs / Re: measure time <1ms on: June 05, 2007, 07:04:29 pm
The TCNT0 register from timer0 isn't really a part of the Arduino environment, it is the underlying hardware.

I wouldn't try to correlate TCNT0 rollovers and millis().  Millis is derived from the rollover count, but sometimes it jumps 1 and sometimes millis() jumps 2 because the timer doesn't rollover on a millisecond interval, plus doing long integer arithmetic really eats up the clock cycles and bytes so I avoid it unless I really need it.

If your time interval is less than 1024 microseconds, and I suspect if you move the gates close enough you can be certain of that, then you have either zero or one rollover in any measurement and when you subtract the times you know. If you got a negative time interval add 1024 microseconds. Be careful about when you convert from unsigned to signed.

The atmega8 and atmega168 manuals are from Atmel.  http:// http://www.atmel.com/dyn/products/devices.asp?family_id=607 will get you into the neighborhood.
22  Forum 2005-2010 (read only) / Syntax & Programs / Re: measure time <1ms on: June 04, 2007, 02:17:47 pm
You can use the pulseIn() function if you can arrange for your signal to arrive as a pulse. If this isn't possible because it involves two pins or someother reason then you must look outside the normal API.

If you look at the hardware level this becomes possible. Timer0 is an 8 bit counter that increments every 4 microseconds with a 16MHz Arduino in the standard configuration. You can read its value with TCNT0. You'll have to watch for when it rolls over and do the right thing.

You can read about the timers in the Atmel chip manual for your processor.
23  Forum 2005-2010 (read only) / Syntax & Programs / Re: timer interupts on: June 18, 2007, 10:25:37 pm
Be aware, the overflow interrupts do not fire if you are resetting the timers with a compare match. There is a different interrupt vector for that. I don't think that is your problem, but you will probably bump into it.

Some functions use cli() and sei(), but they should only disable interrupts for short times.

The timer0 overflow interrupt is used inside the Arduino libraries to implement the millisecond timing functions. I wonder if that one is taking precedence over yours?

For timer1, although there are two different output compare registers, you won't get to make two different frequencies because only one will get to clear the timer. That one will set the frequency and the other will only be able to control duty cycle.

If any of your frequencies are multiples of each other you could make your fastest one be on timer2 and use the timer2 compare match interrupt to count and toggle the slower one.
24  Forum 2005-2010 (read only) / Syntax & Programs / Re: question about libraries on: June 16, 2007, 06:58:35 pm
It should just happen. The way you typed it in the forum, you have spaces inside the angle brackets. It should not have spaces. You want it to be like this...
Code:
#include <avr/io.h>
25  Forum 2005-2010 (read only) / Syntax & Programs / Re: Activating Pull-Up Resistor for Analog Ins on: June 15, 2007, 05:02:49 pm
I haven't tried, but with arduino-0008 the analog ins also show up as digital14 through digital19. You should be able to do something like a digitalWrite(14,HIGH) to turn them on.
26  Forum 2005-2010 (read only) / Syntax & Programs / Re: read specific bits of a byte? on: June 05, 2007, 07:18:36 pm
tempalte has got a lot of the right parts, just not all together.

The packed bitfield structure is correct. That will let you access the 8 bits of the byte individually. But if you want to assign a byte into it, then you either need to put it inside a union or do some typecasting.

For whatever reason, it is not the habit of Arduino programmers or the avr-gcc people to use bit structures. They tend to shift and mask. At a first glance, the object code is about the same so it is a matter of preference.  (Personally, I like bit structs for fixed structures, but I don't code that way here.)
27  Forum 2005-2010 (read only) / Syntax & Programs / Re: Way to wrap long string? on: May 29, 2007, 01:09:17 pm
You can do this...
Code:
const char longstring[] = "aaa"
    "bbb"
   "ccc";
but you might make sure to learn about <avr/pgmspace.h> and PROGMEM because otherwise your strings all get copied into SRAM and you don't have much of that.
28  Forum 2005-2010 (read only) / Syntax & Programs / Re: millis() for three years on: May 27, 2007, 02:53:33 pm
You should do your timer reprogramming inside your setup() function. This runs after the init in the libraries.

Your code will not effect the timing unless you disable interrupts for more than about... 1000-2000 microseconds.

I'm told the radio folks that really care about crystal stability make "crystal ovens", little insulated covers for the crystal with a temperature sensor and a resistor inside. Then they pick a temperature above any likely ambient temperature for the device and keep the crystal at that temperature by turning the resistor on and off. That should get you are very stable time source, though you'd have to calibrate it by measuring it over a long time period.
29  Forum 2005-2010 (read only) / Syntax & Programs / Re: millis() for three years on: May 27, 2007, 12:26:58 pm
Oh right, I forgot about the phase correct aspect. It might not overflow, and you would certainly have to turn on the interrupt enable bit.

I subtract 1000000 because there will be a few left over each time each time, it will go from 999424 to 1000448 and I don't want to lose that 448. About every other time the while loop while run twice and eat up the accumulated remainders.
30  Forum 2005-2010 (read only) / Syntax & Programs / Re: millis() for three years on: May 25, 2007, 12:06:24 pm
Currently millis() overflows much sooner than you might expect because it is calculated from a timer that ticks every 1024 microseconds.

You could take the overflow interrupt on timer2 which runs at the same rate as the millis() timer and define a 'seconds' counter. That might look something like this...
Code:
volatile unsigned long seconds = 0;

SIGNAL(SIG_OVERFLOW2)
{
  static long microseconds = 0;
  
  microseconds += 1024;
  if ( microseconds > 1000000L) {
    seconds++;
    microseconds -= 1000000L;
  }
}

unsigned long secondsSinceBoot()
{
  unsigned long t;
  uint8_t oldSREG = SREG;

  cli();    // disable interrupts
  t = seconds;
  SREG = oldSREG; // restore interrupts
  return t;
}

Then every 1024 microseconds that SIGNAL function will run and accumulate another 1024 microseconds. When there are more than a million accumulated it increments the second and uses up that million. Then you can check "seconds" to see how long it has been since boot. It isn't quite that easy, because the interrupt could fire in the middle of your code reading "seconds", so I added the function "secondsSinceBoot" to safely get you a copy of "seconds" by briefly disabling interrupts. (they won't be lost, just delayed).

You could stick a call to your function in after seconds gets incremented, but be aware you are running at interrupt level and some things don't work... like delay() will freeze and if you take more than about 900 microseconds you will lose a clock tick and not keep correct time. Probably better to poll seconds from your main loop.

(Crappy code notes: The above code doesn't pay any attention to F_CPU or check that timer2 hasn't been changed from its default function. If you diddle with those sorts of things then you'll know what to do.)
Pages: 1 [2] 3 4 ... 14