Show Posts
Pages: 1 2 3 [4] 5 6 ... 110
46  Using Arduino / Microcontrollers / Re: Attiny85 Tiny Core - Override Timer1 Overflow Interrupt ISR with another one? on: March 11, 2014, 06:53:43 pm
With my variant of the core here:
https://github.com/TCWORLD/ATTinyCore
There is a second core called "tinyNoMillis" which solves this problem by having a version of the core which removes all of the millis() related timer code.


Alternatively for any core, if you add this to your sketch:
Code:
int main (void) {
  sei();
  setup();
  for (;;) {
    loop();
  }
  return 0;
}
This will remove all of the millis() stuff, though it will also stop the analogRead(), analogWrite() and tone() functions working.

You can get the analogRead() functionality working again by doing the following:
Code:
#if F_CPU == 16000000
  // 16 MHz / 128 = 125 KHz
  #define ADC_ARDUINO_PRESCALER   B111
#elif F_CPU == 12000000
  // 12 MHz / 64 ~= 125 KHz
  #define ADC_ARDUINO_PRESCALER   B110
#elif F_CPU == 8000000
  // 8 MHz / 64 = 125 KHz
  #define ADC_ARDUINO_PRESCALER   B110
#elif F_CPU == 1000000
  // 1 MHz / 8 = 125 KHz
  #define ADC_ARDUINO_PRESCALER   B011
#elif F_CPU == 128000
  // 128 kHz / 2 = 64 KHz -> This is the closest you can get, the prescaler is 2
  #define ADC_ARDUINO_PRESCALER   B000
#else
  #error Add an entry for the selected processor speed.
#endif
int main (void) {
  sei();
  // This code will only run once, after each powerup or reset of board
  // set a2d prescale factor
  ADCSRA = (ADCSRA & ~((1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0))) | (ADC_ARDUINO_PRESCALER << ADPS0) | (1<<ADEN);
  // enable a2d conversions
  ADCSRA |= _BV(ADEN);
  setup();
  for (;;) {
    loop();
  }
  return 0;
}
47  Using Arduino / Programming Questions / Re: Converting and Integer Array into One Single Number!!? on: March 11, 2014, 06:43:26 pm
it would be:
Code:
pow(10, exponent);

You also have to get your array indices correct - num[1] is not the first element in an array.

But doing it that way would be far less efficient than the method PaulS is suggesting as that way you only do one multiply by 10 each loop rather than an increasing number of times each loop as the pow() function would do. Using an int as a for loop index when it only goes up to five is also very inefficient.

Code:
unsigned long number=num[0];
for (byte i=1;i<6;i++)
{
    number = number*10+num[i];
}
Note that it has to be an unsigned long as you want 6 base10 digits.
48  Using Arduino / Programming Questions / Re: double gets automatically rounded, not enough precision... on: March 11, 2014, 06:41:58 pm
I'd like to also add that unless you have a due, there is also no difference between float and double, both have the same precision.
49  Using Arduino / Microcontrollers / Re: Attiny 861 timer problem on: March 11, 2014, 05:59:18 pm
This is your problem (just noticed it):
Code:
TIMSK = _BV(OCIE1A);

For the 861, TIMSK is a shared register for both timer 0 and timer 1. You should be doing this:
Code:
TIMSK |= _BV(OCIE1A);

Otherwise you disable the millis interrupt.
50  Using Arduino / Microcontrollers / Re: Attiny 861 timer problem on: March 11, 2014, 05:57:25 pm
They are all variants of each other and of the Arduino core which is a modified version of wiring.

I don't know why I didn't add an 8MHz variant of the 861, I will update the core to add one soon.
(Could you post the entry you added to the boards.txt file so I can add it to the core smiley )

The core should be using Timer0 for the millis() function as per the pins_arduino.h file.
Code:
#define TIMER_TO_USE_FOR_MILLIS                   0
51  Using Arduino / Microcontrollers / Re: Attiny 861 timer problem on: March 11, 2014, 05:05:54 pm
given that the Attiny861 isn't supported by the standard Arduino core, you will have to be more specific as to which core you are using.
52  Using Arduino / Programming Questions / Re: classes in ANSI C? on: March 11, 2014, 05:00:51 pm
The Eclipse AVR plugin uses the very same avr-gcc toolchain that Arduino uses (maybe a different version, but the same tool). Just use C++, it will compile.
53  Using Arduino / Programming Questions / Re: sprintf() causes Arduino to reset on: March 11, 2014, 04:58:41 pm
It likely means that it found a null somewhere nearby in memory your string didn't own, but that was good enough that you saw no ill effects.

For future reference, all strings should have a null termination at the end - that is the only thing that makes a string distinguishable from an array.
54  Using Arduino / Microcontrollers / Re: Measuring VCC with an Attiny 85 on: March 11, 2014, 03:39:24 pm
It was just for timer modules, never mind.

"Note that the 16-bit Timer (Timer1) has only one temporary register that is
shared between all it’s 16-bit register pairs" [http://www.atmel.com/Images/doc1493.pdf]

But also, if the interrupt that occurs happens to access the same registers, then you need to ensure atomic operation on the reads.
55  Using Arduino / Microcontrollers / Re: Measuring VCC with an Attiny 85 on: March 11, 2014, 02:30:11 pm
As far as I recall, all the 16bit registers share the same 8bit temp register, in which case if you access another 16bit register in an interrupt you are screwed. I could be wrong about that, maybe it was just for the timer modules, if so, ignore the interrupt thing.
56  Using Arduino / Microcontrollers / Re: Measuring VCC with an Attiny 85 on: March 10, 2014, 06:23:58 pm
no, you don't need the sei() instruction, that is the whole purpose of backing up the SREG (the register which the cli() and sei() instructions act upon).

Imagine interrupts were disabled before calling that function, it will come in, disable them again, and at the end if you call sei() it will enable the interrupts - but they shouldn't be because they were disabled before the function.
By restoring the SREG to what it was before the cli() instruction, you ensure that the state of the interrupt bit is the same as when the function was called.

The 'ADC' register is 16bit and is known to the compiler to be such and the way in which it should be accessed is known to the compiler. It will actually execute two consecutive 'lds' or 'in' instructions, placing the result of each into two consecutive working registers (equivalent to performing the bit shift (<<smiley-cool ). Essentially it converts it into the same ADCL then ADCH read instructions be ensures that they are never rearranged.
If you read the datasheet you will see that it is actually in certain circumstances legal to read just the ADCH register and not the ADCL one - for example if you want an 8bit conversion result, rather than doing what everyone seems to do which is:
analogRead()/4 ;
or
analogRead()>>2;
What you can instead do is set the ADLAR bit in the ADCSRB register before performing the conversion, and then you can read just the ADCH register and you have direct access to an 8bit conversion result.
57  Using Arduino / Microcontrollers / Re: ATtiny85 I really, really, really want to disable reset fuse. on: March 10, 2014, 06:21:21 pm
It is possible to use the reset pin as an analog input without setting the rstdsbl fuse. As long as you never let the voltage get below the reset threshold voltage. The easiest way to have a 10k pullup resistor to VCC and a 47k resistor between the reset pin and your analog signal source. You can even use this method for a pushbutton, though you have to use the ADC to read the state of the button.
58  Using Arduino / Microcontrollers / Re: ATtiny85 I really, really, really want to disable reset fuse. on: March 10, 2014, 04:31:52 am
Won't work. You cant use the SPI interface to change the fuses without the reset pin. The easiest thing to use is this:
http://www.rickety.us/2010/03/arduino-avr-high-voltage-serial-programmer/

There is an alternative and that is to use a bootloader to program the chip, that way you don't have to re-enable the reset pin each time, it simply takes two pins to play the role of a software RX and TX. I have modified Optiboot to work on an Attiny85 amongst others:
https://github.com/TCWORLD/ATTinyCore
One thing to be aware of though is that you must tune the internal oscillator before the bootloader will work. One of the versions of the bootloader (compiled with attiny85_tuned.bat), which is used by default has a built in tuning code that allows the oscillator to be tuned the first time that the bootloader is loaded and will remember the configuration for later. See here for a description of how: https://github.com/TCWORLD/ATTinyCore/blob/master/tiny/bootloaders/optiboot/Readme%20for%20Tuned%20optiboot.txt

Its not a fool proof method as variations in voltage and temperature can change the oscillator frequency and so the Serial port baud rate goes out of spec. In this case it is possible to still use it if you can find out what the new baud rate is.
59  Using Arduino / Microcontrollers / Re: Measuring VCC with an Attiny 85 on: March 10, 2014, 04:20:34 am
http://www.atmel.com/Images/doc8006.pdf
Read Page 106.

Notice how in the C code examples, they never directly use the ***H and ***L registers.

There is also another problem which the current analogRead() code fails to consider which is interrupts. If an interrupt occurs after you have read ADCL but before you have read ADCH, then you can loose the conversion result. The same is true for using the ADC register name:
Code:
uint16_t read;
uint8_t oldSREG = SREG;
cli();
read = ADC;
SREG = oldSREG;
60  Using Arduino / Microcontrollers / Re: Arduino Tiny on: March 09, 2014, 04:55:40 pm
The empty bootloader can be simply a blank hex file - it is there purely to get the Arduino IDE to set the fuses. I think the current ones are just a 'Blink' sketch.
Pages: 1 2 3 [4] 5 6 ... 110