Show Posts
Pages: [1] 2 3 ... 6
1  Using Arduino / Project Guidance / Re: GPS Laptimer on: July 27, 2014, 06:12:44 pm
IR lap timer

GPS lap timer
2  Using Arduino / Programming Questions / [solved] AVR133 long delay using cascaded timers on: July 22, 2014, 03:40:38 pm
I’m trying to create a long delay by cascading timers via the procedure outlined in Atmel Application Note AVR133. I’ve set timer #1 up to toggle the OCR1A (D9) pin and wired that to the T0 pin (D4) which clocks timer #0. Then I put the arduino to sleep and wait for the timer #0 interrupt to wake it. Or at least that’s what I’m trying to do. The values I’m using should toggle the pin 13 LED at a 1 minute frequency. A much longer delay is easily possible, but I can’t get it t work.

Code:
// AVR 133: Atmel Application Note Long Delay Generation
// T = 2/Fs x T1P x OCR1A x (256 - TCNT0)
// T = 2/16000000x256x7500x(256-6)
// T = 60 or 1 minute
//
// connect arduino D9 to D4:
//  T0 = PD4 (Arduino D4 as input)
//  OC1A = PB1 (Arduino D9 as output)
//
#include <avr/sleep.h>
#include <avr/power.h>

void setup() {
  cli();
 
  //set pins
  DDRB |= (1<<PINB1) | (1<<PINB5); //set arduino D9 and D13 as outputs
  PORTB &= ~(1<<PINB1);            //set D9 low
  PORTD &= ~(1<<PIND4);            //set D4 low

  //timer #1 toggles OCR1A on TCNT1=0 in turn toggling T0
  TCCR1A = (1<<COM1A0); //TCCR1A toggle OC1A on compare match
  TCCR1B = 0;
  TCCR1C = 0;
  OCR1A = 7500;       //output compare register on division ratio of 7500
  TIMSK1 = 0;

  //timer #0 fires interrupt when TCNT0=0 waking arduino
  TCCR0A = 0;
  TCCR0B = 0;
  TIMSK0 = (1<<TOIE0);  //enable timer0 interrupt
 
  sei();
}

void loop() {
  //toggle led
  PORTB ^= (1<<PINB5); //toggle led pin

  //reset timers
  TCNT0 = 6;
  TCCR0B = (1<<CS00) | (1<<CS01) | (1<<CS02); //external source (t0) rising edge
  TCNT1 = 0UL;
  TCCR1B = (1<<WGM12) | (1<<CS12); //CTC mode 4 and 256 prescaler

  set_sleep_mode(SLEEP_MODE_IDLE);
 
  sleep_enable();
  power_adc_disable();
  power_spi_disable();
  power_timer2_disable();
  power_twi_disable();
  sleep_mode();
  //go to sleep here, wake on interrupt
  sleep_disable();
  power_all_enable();
 
  //stop timers
  TCCR1B = 0;
  TCCR0B = 0;
}

edit: above code now works.
3  Using Arduino / Programming Questions / Re: How to trigger operation at every hundredth millisecond using ADA Ultimate GPS on: June 12, 2014, 12:50:26 pm
Set your GPS up to send at 10Hz and only one NMEA string, then use code something like this to save after you receive each NMEA sentence.

Code:
void loop() {
  char c;

  //…
  if (Serial.available()) {
    c = Serial.read();

    if (c == '\n') {
      //end of gps string received, save sensor data now…
    }
  }
  //…
}
4  Using Arduino / Programming Questions / Re: how to calculate clock cycle of an instruction on: April 15, 2014, 10:32:21 am
The Lost Art of Cycle Counting
5  Using Arduino / Programming Questions / Re: interrupt starts at different times depending on upload time of program on: April 07, 2014, 10:59:41 am
why is this in there?

Code:
Serial.begin(9600);
6  Using Arduino / Programming Questions / Re: Effect of switch bounce on external interrupt ? on: March 21, 2014, 01:07:15 pm
Normally, the AVR hardware clears the global interrupt flag (in SREG) before entering an interrupt. This means other interrupts are disabled inside the running handler until the handler finishes and exits.

The RETI instruction is the normal function epilogue for an interrupt handler, and thus re-enables interrupts (just like executing an SEI instruction).

For this reason, normally, interrupt handlers can not be nested.

Search ISR(XXX_vect, ISR_NOBLOCK) for a way around this.

or

http://ucexperiment.wordpress.com/2013/05/20/nested-interrupts/

7  Using Arduino / Programming Questions / Re: Need help with "speed optimization" on: March 16, 2014, 09:44:23 pm
#define intHold 7

volatile int c = 0;
volatile int r = 0;

//Increase tooth count by one
void count() {
  c++;
  if(c == 4)
    //digitalWrite(intHold, HIGH);
    PORTD = B10000000;
  else if(c == 6)
    //digitalWrite(intHold, LOW);
    PORTD = B00000000;
  else if(c == 10)
    //digitalWrite(intHold, HIGH);
    PORTD = B10000000;
  else if(c == 12)
    //digitalWrite(intHold, LOW);
    PORTD = B00000000;
}
                                           
//Reset tooth count
void reSet() {
  c = 0;
  r++;
}

void setup() {
  pinMode(intHold, OUTPUT);          //intHold output to TPIC8101 on pin 6
  digitalWrite(intHold, LOW);
  attachInterrupt(0, count, RISING); //24 tooth interrupt on pin 2 calls to function count below
  attachInterrupt(1, reSet, RISING); //1 tooth "reset" interrupt on pin3 calls to function reSet below
  Serial.begin(9600);
  Serial.println("Setup");           //verify setup completed
}

void loop() {                        //Verify resets are working
  if(r > 1) {
    Serial.println("reset");
    r = 0;
  }     
}
8  Using Arduino / Programming Questions / Re: Maths precision for Arduino? on: January 29, 2014, 05:18:43 pm
https://sites.google.com/site/wayneholder/self-driving-rc-car/getting-the-most-from-gps
9  Using Arduino / Programming Questions / Re: $50 bounty: report pitch and roll minus any acceleration effects on: January 28, 2014, 03:56:17 pm
No takers? C'mon guys! Why is this so hardddddd

Two words: kalman filter
10  Using Arduino / Programming Questions / Re: Measuring execution time of functions without Serial.print on: January 24, 2014, 12:43:35 pm
Does this code profiler help?
11  Using Arduino / Programming Questions / Re: Can 'blocked' code miss an interrupt? on: January 15, 2014, 02:26:59 pm
Buttom bounce issue?
12  Using Arduino / Programming Questions / Re: Programatically accessing stack and heap pointers? on: October 29, 2013, 11:57:53 pm
http://playground.arduino.cc/Code/AvailableMemory
13  Using Arduino / Programming Questions / Re: attachInterrupt() calls wrong function upon interrupt on Arduino Mega2650 on: September 23, 2013, 06:59:08 pm
What board are you compiling for? Because when I compile your code I get the following IVT:

Code:
00000000 <__vectors>:
   0: 71 c0        rjmp .+226    ; 0xe4 <__ctors_end>
   2: 00 00        nop
   4: 57 c1        rjmp .+686    ; 0x2b4 <__vector_1>
   6: 00 00        nop
   8: 86 c1        rjmp .+780    ; 0x316 <__vector_2>
   a: 00 00        nop
   c: b5 c1        rjmp .+874    ; 0x378 <__vector_3>
   e: 00 00        nop
  10: e4 c1        rjmp .+968    ; 0x3da <__vector_4>
  12: 00 00        nop
  14: 13 c2        rjmp .+1062    ; 0x43c <__vector_5>
  16: 00 00        nop
  18: 42 c2        rjmp .+1156    ; 0x49e <__vector_6>
  1a: 00 00        nop
  1c: 71 c2        rjmp .+1250    ; 0x500 <__vector_7>
  1e: 00 00        nop
  20: a0 c2        rjmp .+1344    ; 0x562 <__vector_8>
  22: 00 00        nop
  24: 7f c0        rjmp .+254    ; 0x124 <__bad_interrupt>
  ...
14  Using Arduino / Programming Questions / Re: Display floating point temperature on 7-segment display on: September 20, 2013, 04:32:24 pm
Multiply the float by 100 and convert it to an integer.

Code:
int intTemp = floatTemp * 100;

This will turn 12.3456 into 1234.
Now you can display the digits onto the 7 segment display and simply enable the dot before the last two digits.

How about if the temperature is 100.1?
15  Using Arduino / Programming Questions / Re: Arduino assembler programming on: August 15, 2013, 09:57:34 am
Inline Assembly is a good method to get your feet wet. However it has somewhat odd and confusing syntax.

Mixing C and assembly in AVR Studio is another method.

Check out the book, "Programming Microcontrollers using Assembly Language" for an excellent primer.

Goodluck...
Pages: [1] 2 3 ... 6