avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] I need some help I am trying to use interrupts but...sigh


From: atifplus
Subject: [avr-gcc-list] I need some help I am trying to use interrupts but...sigh!!
Date: Mon, 17 Mar 2008 21:28:47 -0700 (PDT)

so as long as my move variable is 1 2 3 or 4 the interrupt should keep
sending pulse accordingly but i am not getting anything on portB

#include <avr/io.h>
#include <avr/interrupt.h>
#define F_CPU 8000000UL  // 8 MHz
#include <util/delay.h>
#include <inttypes.h>
#include <avr/io.h>



volatile int movetype;
volatile uint16_t encoderL;  // global varialble will be updated by the
encoder sensor
volatile uint16_t encoderR;
volatile int LS; // previous value of sensor
volatile int RS; // previous value of sensor

// direction can be 1 = forward
// direction can be 2 = Back
// direction can be 3 = Left
// direction can be 4 = Right
// Pin B4 is the right motor
// Pin B3 is the left motor



// Timer1 interrupt service routine
ISR(TIMER1_COMPA_vect)
{
if (PORTB !=  RS)
    {
        RS = PINB0;
        encoderL++;
    }
if (PINB1 !=  LS)
    {
        LS = PINB1;
        encoderR++;
    }
}

// Timer0 compare interrupt service routine
ISR(TIMER0_COMP_vect)
{
if ( movetype == 1)
{
          PORTB |= (1 << PB3)|(1 << PB4);
          _delay_ms(2);
          PORTB |= (0 << PB3)|(0 << PB4);
          _delay_ms(1);
}
else if ( movetype == 2)
        {
                  PORTB = PORTB | ((1<<PB3)|(1<<PB4));
                  _delay_ms(1);
                  PORTB = PORTB | ((0<<PB3)|(0<<PB4));
                  _delay_ms(1);
        }
else if (movetype == 3)
        {
                 PORTB = PORTB | ((1<<PB3)|(1<<PB4));
                 _delay_ms(1);
                 PORTB = PORTB | ((1<<PB3)|(0<<PB4));
                 _delay_ms(1);
                 PORTB = PORTB | (0<<PB3);
        }
else if ( movetype == 4)
        {
                PORTB = PORTB | ((1<<PB3)|(1<<PB4));
                _delay_ms(1);
                PORTB = PORTB | ((0<<PB3)|(1<<PB4));
                _delay_ms(1);
                PORTB = PORTB | (0<<PB4);
        }
else
        PORTB = PORTB | ((0<<PB3)|(0<<PB4));
}


int main(void)
{

DDRB |= ((1<<PB3) | (1<<PB4) | (0<<PB1) | (0<<PB0));
TCCR1B |= (1 << WGM12); // Configure timer 1 for CTC mode
TCCR0 |= ((1 << WGM01)| (1 << CS02)| (1 << CS00));
OCR0 = 15626; // register intialized
TIMSK |= ((1 << OCIE1A) |  (1 << OCIE0)); // Enable CTC interrupt for Timer1
and Timer0
TCCR1B |= (1 << CS10) | (1 << CS11); // Start timer at Fcpu/64 in the table
to select the right division
OCR1A   = 0x03;//Set CTC compare value to 1Hz at 1MHz AVR clock, with a
prescaler of 64
sei(); // enable global interrupts

while(1)
        {
                movetype = 1;
                _delay_ms(1000);
                movetype = 3;
                _delay_ms(1000);
        }

return 0;
}

-- 
View this message in context: 
http://www.nabble.com/I-need-some-help-I-am-trying-to-use-interrupts-but...sigh%21%21-tp16114203p16114203.html
Sent from the AVR - gcc mailing list archive at Nabble.com.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]