All About Circuits Forum  

Go Back   All About Circuits Forum > Electronics Forums > General Electronics Chat

Notices

General Electronics Chat Discussion forum for general chat about anything electronics related, including asking questions about material in the All About Circuits E-book, Worksheets, and Videos.

Reply   Post New Thread
 
Thread Tools Display Modes
  #11  
Old 03-23-2012, 01:31 PM
kripanand kripanand is offline
Junior Member
 
Join Date: Mar 2012
Posts: 13
Default

yupp I heared the beep sound every time but no motion on the motor
Reply With Quote
  #12  
Old 03-23-2012, 03:12 PM
jrm jrm is offline
Junior Member
 
Join Date: Oct 2011
Posts: 38
Default

I don't know codevision but it looks like you have several problems.

All of your ports are configured as inputs and are in tri state mode. What port/pin are you using for the output on the AVR?

Your Timer mask register is set to 00000000 meaning the timer interrpupt is not enabled.

TCCRO needs some help. If I'm reading it correctly the only thing you have changed is cs02bits which is the 256 prescale. Com01 com00 need to be set according to where and how you want the output. The DDR for the output port needs to be set as an output. The way you have it now there is no output; it is set for normal port operation.

I'm assuming you are using timer0. Timer0 with a prescale of 256 @ 8mhz overflows every 8 milliseconds. Using a compare match of 100 with a top of 255 and that prescale gives you a 3ms duration. Not gonna work.


So break out the data sheet for the chip and look at:
DDRx
TCCRO
TIMSK
TCNTO
OCRO

Also make sure your fuse bit clkdiv8 is not set on your chip or you will be running at 1mhz instead of 8mhz and you will pull all of your hair out.
Reply With Quote
  #13  
Old 03-23-2012, 07:18 PM
hspalm hspalm is offline
Senior Member
 
Join Date: Feb 2010
Location: Oslo, Norway
Posts: 186
Default

PORTB pin 3 is actually configured as output.

But yes, you have several problems. You have no WGM bits set, these registers is what decides what mode your timer is in. In your case, for fast PWM the bits WGM00 and WGM01 should be set to 1.

You still have a PWM frequency of 120Hz which is more than double what the ESC is expecting.

And you should really read those hints posted earlier on initializing an ESC, I was not aware of this!

And, your pulses is varying from 4 to ~7 milliseconds, if my math is correct, which the ESC don't understand, it needs 1-2ms pulses.
Reply With Quote
  #14  
Old 03-24-2012, 03:58 AM
kripanand kripanand is offline
Junior Member
 
Join Date: Mar 2012
Posts: 13
Default

okkk I got your statement .and thnx to u all for their suggestions.

but tell me one thing if I am wrong about the ESCs. there are 3 pins out from the ESC and 2 pins for the battery for Li-Po battery.these 3 pins which are connected to atmega16 are
PWM Pulse
Vcc and
Gnd pin
I connected the PWM pin to Timer0 which is 8 bit timer at Pin no. 4 and Vcc, Gnd to their pins 10,11.

Do I really need to initialise the port should I ?. because I did the PWM pulses generation in Dc motor controll also and I did nothing like initialising of port in dc motor ...or do I need to initialise the 16 bit timer for ESC....please help .....!!!!!
Reply With Quote
  #15  
Old 03-24-2012, 09:47 AM
kripanand kripanand is offline
Junior Member
 
Join Date: Mar 2012
Posts: 13
Default

void main ()
{
TCCR0|= (1<<WGM00)| (1<<WGM01) | (1<<COM00)| (1<<CS02)| (1<<CS00);
TCNT0=0x00;
OCR0=0x00;

//Set OC0 PIN as output. It is PB3 on ATmega16
DDRB|= (1<<PB3);

while (1)
{

Delay_ms(20);

OCR0=10;

Delay_ms(20);

OCR0=12;

Delay_ms(20);

OCR0=0;

Delay_ms(20);

}












I made this effort by reading last all for your post prescaling timer0 by 1024 and giving the pulse after every 20 ms. and also use the WGM bit, COM and CS bit ...please tell me the error ...I did not burn this program yet !!!
Reply With Quote
  #16  
Old 03-24-2012, 10:31 AM
hspalm hspalm is offline
Senior Member
 
Join Date: Feb 2010
Location: Oslo, Norway
Posts: 186
Default

The 16bit timer you can just leave ut of the picture, continue with the 8 bit timer 0. I don't have the time to re-calculate your new timer values, but I can see your code is not yet implementing the initialization of the ESC.

I added initialization routine before main-loop. I edited OCR0 values to values I think are more correct. I also upped your delay times in the main loop, did you expect to see any change in speeds with 20 ms delays between changes? Or, did you might think that the pulses need to change values every 50Hz (thus 20ms delays)? In either case, the frequency is fixed by the CS-bits, you only set the duty cycle with OCR0 register. I also removed last delay in loop because you had one on the top also making it delay two times , one right after the other.

Only setting COM00 bit is a reserved setting with fast PWM mode, referring to the datasheet. I set COM01 instead, which clears OC0 at top of counter and sets it at the bottom, this is called non-inverting PWM.



void main ()
{
TCCR0|= (1<<WGM00)| (1<<WGM01) | (1<<COM01)| (1<<CS02)| (1<<CS00);
TCNT0=0x00;
OCR0=0x00;

//Set OC0 PIN as output. It is PB3 on ATmega16
DDRB|= (1<<PB3);

//ESC initializing
OCR0 = 7; //0-speed signal at div1024 according to my calculations
Delay_ms(5000); //wait 5 seconds for beep

while (1)
{

Delay_ms(2000);

OCR0=7;

Delay_ms(2000);

OCR0=14;

Delay_ms(2000);

OCR0=0;

}
Reply With Quote
  #17  
Old 03-24-2012, 04:56 PM
kripanand kripanand is offline
Junior Member
 
Join Date: Mar 2012
Posts: 13
Default

okkk

let me try this one I will tell you tomorrow it works or not

thnx for your reply and code
Reply With Quote
  #18  
Old 03-26-2012, 11:29 AM
kripanand kripanand is offline
Junior Member
 
Join Date: Mar 2012
Posts: 13
Default

not again still there is something missing in this code.. please look that code one more time . I am still not getting the movement in ESC.. pleaseeee....help .........
Reply With Quote
  #19  
Old 03-26-2012, 12:40 PM
hspalm hspalm is offline
Senior Member
 
Join Date: Feb 2010
Location: Oslo, Norway
Posts: 186
Default

Sorry pal. I'm not saying my code is guaranteed to work, and I can not program this for you. If you have access to an oscilloscope that would be handy, if not it's just a shot in the dark when you simply connect the ESC (btw we can not be sure your wiring is okay either).

Read this page
http://extremeelectronics.co.in/avr-...crocontroller/

See that code? I can not guarantee it to work, but it's the first hit when googling "servo control avr" (what we told you to do, implicitly).

Now delete the whole of main() function and replace with

Code:
void main()
{
   //Configure TIMER1
   TCCR1A|=(1<<COM1A1)|(1<<COM1B1)|(1<<WGM11);        //NON Inverted PWM
   TCCR1B|=(1<<WGM13)|(1<<WGM12)|(1<<CS11)|(1<<CS10); //PRESCALER=64 MODE 14(FAST PWM)

   ICR1=4999;  //fPWM=50Hz (Period = 20ms Standard).

   DDRD|=(1<<PD4)|(1<<PD5);   //PWM Pins as Out

    OCR1A = 250;
    _delay_ms(5000);

   while(1)
   {

      OCR1A=250;   //no speed
      _delay_ms(3000);

      OCR1A=500;  //full speed
      _delay_ms(3000);

   }
}
Select All
This must be compiled in AVR Studio, so download that along with winavr package. You also need to switch your crystal for a 16MHz. Your PWM output is now PORT D pin 5
Reply With Quote
  #20  
Old 03-26-2012, 02:20 PM
kripanand kripanand is offline
Junior Member
 
Join Date: Mar 2012
Posts: 13
Default

o.k. thanx a lot for your effort let me try My best this time

I tell you tomorrow ....whether its gonna work...

Hope at last something works....
Reply With Quote
Reply   Post New Thread

Tags
, , ,


Related Site Pages
Section Title
Worksheet Servo motor systems
Worksheet AC motor control circuits
Textbook Synchronous Motors : Ac Motors


Similar Threads
Thread Thread Starter Forum Replies Last Post
servo motor controlling with atmega16 stylediva Embedded Systems and Microcontrollers 1 01-31-2012 04:23 PM
Controlling a 12V load - simple transistor or SSR? BurninBri General Electronics Chat 7 11-10-2011 06:29 PM
video camera for atmega16 mihaio07 Embedded Systems and Microcontrollers 1 03-09-2011 12:03 AM
Controlling 12V with 0.5V signal Georacer The Projects Forum 19 09-23-2010 04:14 PM
How to configure ATmega16 to run with external crystal oscillator sinoj Embedded Systems and Microcontrollers 4 06-06-2007 12:38 AM

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:21 AM.


User-posted content, unless source quoted, is licensed under a Creative Commons Public Domain License.
Powered by vBulletin
Copyright ©2000 - 2014, vBulletin Solutions, Inc.