00001 /* $Id: PWM.c,v 1.00 2005/07/04 15:22:00 BorisK Exp $ 00002 * 00003 * Copyright (C) 2005 ONTRACK s.r.o. 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00018 * 02111-1307, USA. 00019 * 00020 * Written by Boris Kralik <kralikbo@yahoo.com>, 2005. 00021 */ 00022 #include "PWM.h" 00023 00024 void PWMCounterEnable(void){ PWM_TCR |= (1 << 0); } 00025 00026 /* Reset counter and prescaler */ 00027 /* enable counter and PWM, release counter from reset */ 00028 void PWMCounterReset(void) { PWM_TCR = 0x2;PWM_TCR = 0x9;} 00029 00030 void PWMEnable(void) { PWM_TCR |= (1 << 3); } 00031 00032 void PWMInitialize(PWM tPWM) 00033 { 00034 #if DBG 00035 UARTWriteStr("\n\rPWMInitialize"); 00036 #endif 00037 PWM_PR = tPWM.PR; /* Load prescaler */ 00038 PWM_MR0 = tPWM.MR0; /* set cycle rate to sixteen ticks */ 00039 PWM_MR1 = tPWM.MR1; /* set falling edge of PWM1*/ 00040 PWM_MR2 = tPWM.MR2; /* set falling edge of PWM2*/ 00041 PWM_MR3 = tPWM.MR3; /* set falling edge of PWM3*/ 00042 PWM_MR4 = tPWM.MR4; /* set falling edge of PWM4*/ 00043 PWM_MR5 = tPWM.MR5; /* set falling edge of PWM5*/ 00044 PWM_MR6 = tPWM.MR6; /* set falling edge of PWM6*/ 00045 PWM_LER = 0x21; /* enable shadow latch for match 5 */ 00046 PWM_LER |= (1 << 2); 00047 //PWM_EMR = 0x00210A8E; /* Match 1 and Match 2 outputs set high ???? */ 00048 PWMCounterReset(); 00049 } 00050 00051 uint8_t PWMpinsInitialize(uint8_t chWhich) 00052 { 00053 uint8_t ret=0; 00054 switch(chWhich) 00055 { 00056 case 1: 00057 #if DBG 00058 UARTWriteStr("\n\rPWM1."); 00059 #endif 00060 PCB_PINSEL0 &= 0xE; 00061 PCB_PINSEL0 |= (1 << 1); //PWM1 00062 break; 00063 PWM_PCR |= (1 << 9); 00064 case 2: 00065 PCB_PINSEL0 &= 0xBFFF; 00066 PCB_PINSEL0 |= (1 << 15);//PWM2 00067 #if DBG 00068 UARTWriteStr("PWM2."); 00069 #endif 00070 PWM_PCR |= (1 << 10); 00071 break; 00072 case 3: 00073 PCB_PINSEL0 &= 0xB; 00074 PCB_PINSEL0 |= (1 << 3); //PWM3 00075 #if DBG 00076 UARTWriteStr("\n\rPWM3."); 00077 #endif 00078 PWM_PCR |= (1 << 11); 00079 break; 00080 case 4: 00081 #if DBG 00082 UARTWriteStr("\n\rPWM4."); 00083 #endif 00084 PCB_PINSEL0 &= 0xEFFFF; 00085 PCB_PINSEL0 |= (1 << 17);//PWM4 00086 PWM_PCR |= (1 << 12); 00087 break; 00088 case 5: 00089 #if DBG 00090 UARTWriteStr("\n\rPWM5."); 00091 #endif 00092 PCB_PINSEL1 &= 0x7FF; 00093 PCB_PINSEL1 |= (1 << 10);//PWM5 00094 PWM_PCR |= (1 << 13);/*PWM channel 5 single edge control,output enabled */ 00095 break; 00096 case 6: 00097 #if DBG 00098 UARTWriteStr("\n\rPWM6."); 00099 #endif 00100 PCB_PINSEL0 &= 0xBFFFF; 00101 PCB_PINSEL0 |= (1 << 19);//PWM6 00102 PWM_PCR |= (1 << 14); 00103 break; 00104 default: 00105 PCB_PINSEL0 &= 0xBFFFF; 00106 PCB_PINSEL0 |= (1 << 19);//PWM6 00107 PCB_PINSEL1 &= 0x7FF; 00108 PCB_PINSEL1 |= (1 << 10);//PWM5 00109 PCB_PINSEL0 &= 0xEFFFF; 00110 PCB_PINSEL0 |= (1 << 17);//PWM4 00111 PCB_PINSEL0 &= 0xB; 00112 PCB_PINSEL0 |= (1 << 3); //PWM3 00113 PCB_PINSEL0 &= 0xBFFF; 00114 PCB_PINSEL0 |= (1 << 15);//PWM2 00115 PCB_PINSEL0 &= 0xE; 00116 PCB_PINSEL0 |= (1 << 1); //PWM1 00117 PCB_PINSEL0 &= 0xABFFA; 00118 PCB_PINSEL0 |= (1 << 15); 00119 PWM_PCR |= (1 << 14); //PWM6 00120 PWM_PCR |= (1 << 13); //PWM5 00121 PWM_PCR |= (1 << 12); //PWM4 00122 PWM_PCR |= (1 << 11); //PWM3 00123 PWM_PCR |= (1 << 10); //PWM2 00124 PWM_PCR |= (1 << 9); //PWM1 00125 break; 00126 } 00127 return ret; 00128 }
1.4.7