Like to include a concept in my atmega32 code.

Thread Starter

mahmud1994

Joined Jul 16, 2017
23
C:
#include <avr/io.h>
#include <avr/interrupt.h>


int main(void)
{
   DDRB = 0xFF;
  
   TCCR1A |= 1<<WGM11;
   TCCR1B |= 1<<WGM12 | 1<<WGM13 | 1<<CS10;
   TIMSK  |= 1<<OCIE1A;
  
   ICR1 = 4000;
  
   sei();
  
   while (1)
   {
     if (TCNT1 > 1000 && TCNT1 <2400)
     {
       if(TCNT1 >= 2000 && bit_is_set(PORTB,PINB0)) PORTB &= ~(1<<PINB0);
       if(TCNT1 >= 2000 && bit_is_set(PORTB,PINB1)) PORTB &= ~(1<<PINB1);
       if(TCNT1 >= 2000 && bit_is_set(PORTB,PINB2)) PORTB &= ~(1<<PINB2);
       if(TCNT1 >= 2000 && bit_is_set(PORTB,PINB3)) PORTB &= ~(1<<PINB3);
      
     }
    
    
   }
}

ISR(TIMER1_COMPA_vect)
{
   PORTB = 0xFF;
}

This is my code. how can i implement this concept into this code. Suppose when PINB0 on and off for 20 ms and when it cross the 20ms on time. On that time, on time will decrease and off time increase. When PINB0 on time start to decrease PINB1 wave start to increase. When PINB1 on time reached to 20ms, PINB0 will stop generation and PINB1 on time start to decrease from 20ms, PINB2 wave will start generation. these process will go on for PINB3. and keep repeating. and what can be done if we need the process for reverse direction. suppose it will start from PINB3 to PINB0

Moderatots note : used code tags
 
Top