Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » AVR-GCC
  • » [avr-gcc-list] I need some help I am trying to use interrupts but...sigh!! [RSS Feed]

#1 March 19, 2008 17:47:14

a.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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


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.htmlSent from the AVR - gcc mailing list archive at Nabble.com.



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#2 March 19, 2008 18:33:33

David K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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


On Mon, Mar 17, 2008 at 09:28:47PM -0700, atifplus wrote:
>
> 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

> PORTB |= (0 << PB3)|(0 << PB4);

Do you really believe you can OR a 0 into bit locations PB3 and PB4?

This is what I think you intended:

PORTB &= ~( (1<<PB3) | (1<PB4) );

--
David Kelly N4HHE,
========================================================================
Whom computers would destroy, they must first drive mad.


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#3 March 20, 2008 14:29:26

a.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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


Thats right I used exactly what you wrote 2 days ago.
:)
This fourm take long to get hte reply but yes that solved the problem Thanks
for the response


David Kelly wrote:
>
> On Mon, Mar 17, 2008 at 09:28:47PM -0700, atifplus wrote:
>>
>> 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
>
>> PORTB |= (0 << PB3)|(0 << PB4);
>
> Do you really believe you can OR a 0 into bit locations PB3 and PB4?
>
> This is what I think you intended:
>
> PORTB &= ~( (1<<PB3) | (1<PB4) );
>
> --
> David Kelly N4HHE,
> ========================================================================
> Whom computers would destroy, they must first drive mad.
>
>
> _______________________________________________
> AVR-GCC-list mailing list
> AVR-GCC-l***@*ongnu.org
>http://lists.nongnu.org/mailman/listinfo/avr-gcc-list>
>

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



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#4 March 22, 2008 08:48:55

Joerg W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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


atifplus <> wrote:

> This fourm take long to get hte reply ...

This is simply because you did not subscribe to the list, and the list
server holds messages from unsubscribed users for moderator approval.
You should have got a message telling you this right after sending
your mail(s).

(Alas, this policy is quite essential to keep the spam rate low.)

--
cheers, J"org .-.-. --... ...-- -.. . DL8DTLhttp://www.sax.de/~joerg/NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

  • Root
  • » AVR-GCC
  • » [avr-gcc-list] I need some help I am trying to use interrupts but...sigh!! [RSS Feed]

Board footer

Moderator control

Enjoy the 16th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support