Timer1 in CTC mode

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi...

 

I need to run 2 stepper motor for my project. I am using Atmega328P and L293d to do so.

 

I used to AVR446 to run the motor and its works fine for 1st motor. I geenrate interupt using TIMER1_COMPA_vect. and its work fine

as both the motor needs to be run at different speed, so i think to use TIMER1_COMPB_vect for Motor 2.

 

But on digging datasheet i have found ". In CTC mode the counter is cleared to zero when the counter value (TCNT1) 
matches either the OCR1A (WGM13:0 = 4) or the ICR1(WGM13:0 = 12)"

 

TCNT1 become zero once it matches with OCR1A, so my question is

 

1) How i can use the TIMER1_COMPB_vect in CTC mode, I feel it should be clear once its match with the bigger OCR1x counter

   and if not soo, what is the use of TIMER1_COMPB_vect.

2) How i can use single timer to run two motors at different speed. in which mode ??

 

Code attached.. I didnt run the TIMER1_COMPB_vect  yet but code added

 

Rgds

 

Attachment(s): 

Goswami Sourabh,

The Creator....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your conclusion is correct, CTC mode will not work for you. There's a number of solutions:
1. Dds technique. Uses only one timer for multiple motors
2. Use the compare channels with the timer in normal mode.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a lot for such quick reply..

 

What is Dds technique...any abbreviation ??

 

and then what is the use of TIMER1_COMPB_vect. how we can use OCR1B ?? 

 

rgds

Goswami Sourabh,

The Creator....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1. Dds Google dds stepper motor
2. In the compa/b isrs, you add the time period value to ocr1a/b to get the frequency you want.