init.c

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 //_____  I N C L U D E S ___________________________________________________
00012 
00013 #ifdef __ICCAVR__ // IAR C Compiler
00014 #include "config.h"
00015 #include "inavr.h"
00016 #endif
00017 
00018 #ifdef __GNUC__  // GNU C Compiler
00019 #include "config_for_gcc.h"
00020 #include <avr/io.h>
00021 #endif
00022 
00023 #include "lib_mcu/comparator/comparator_drv.h"
00024 
00025 
00029 void init(void)
00030 {
00031    /*************************************************************************************/
00032    /*           ports direction configuration                                           */
00033    /*************************************************************************************/
00034 
00035    DDRB = 0xC3;
00036 //   DDRC = 0x89; MC200
00037    DDRC = 0x8A; //MC100
00038    DDRD = 0x01;
00039 //   DDRE = 0x02; // MC200
00040    DDRE = 0x04; // MC100
00041 
00042    PORTC = 0x06;     /* enable pull up */
00043 
00044    /*************************************************************************************/
00045    /*     Timer 0 Configuration : generates the sampling fréquency                      */
00046    /*************************************************************************************/
00047    TCCR0A = (1<<WGM01);   // mode CTC : Clear Timer on Compare
00048    TCCR0B = (1<<CS02);    // f_quartz = 8 MHz / 256 = 32 kHz
00049 //      OCR0A = 0x20;          // one interruption every 1.056ms @8 Mhz
00050 //      OCR0A = 0x10;          // one interruption every 0.544ms @8 Mhz
00051 //      OCR0A = 0x08;          // one interruption every 0.288ms @8 Mhz (0.144ms @16 Mhz)
00052 //   OCR0A = 0x02;          // one interruption every 48µS @16 Mhz
00053    OCR0A = 0x03;          // one interruption every 64µS @16 Mhz
00054 
00055 // !! 48µS is too quick for GCC , please use at least 64µS 
00056 //                                and adjust Prescaler_Main_Tick
00057 //                                in mc_drv.c
00058 
00059 
00060    TIMSK0 = (1<<OCIE0A);  // allow interruption when timer=compare
00061 
00062    init_comparator0();
00063    init_comparator1();
00064    init_comparator2();
00065 
00066 
00067 //    initialize external interrupts /* MC200 */
00068 
00069 //   EICRA =(0<<ISC21)|(1<<ISC20)|(0<<ISC11)|(1<<ISC10)|(0<<ISC01)|(1<<ISC00);
00070 //   EIFR = (1<<INTF2)|(1<<INTF1)|(1<<INTF0); // clear possible IT due to config
00071 //   EIMSK=(0<<INT2)|(1<<INT1)|(1<<INT0);
00072 
00073    Enable_interrupt();            // allow interruptions
00074 }

Generated on Tue Sep 16 18:11:19 2008 for Atmel BLDC Sinusoidal on ATAVRMC100 by  doxygen 1.5.3