Controlor for Humanoid. Walking trajectory generator, sensor reflection etc.

Dependencies:   Adafruit-PWM-Servo-Driver MPU6050 RS300 mbed

Revision:
5:0ca9f1bc1fb0
Parent:
3:84e5335fab91
Child:
7:7c0621d33781
--- a/Source3.cpp	Thu Aug 30 12:41:50 2012 +0000
+++ b/Source3.cpp	Tue Sep 18 06:48:47 2012 +0000
@@ -3,19 +3,20 @@
 
 #include "LPC17xx.h"
 #include "mbed.h"
+//#include "PowerControl.h"
 
-const uint32_t SRV_PERIOD = 2500 - 1;//���/8
-const uint32_t SRV_MAX_DUTY = 2100 - 1;//�f���[�e�B�[�ő�l
-const uint32_t SRV_MIN_DUTY = 900 - 1;//�f���[�e�B�[�ŏ��l
+const uint32_t SRV_PERIOD = 2500 - 1;//
+const uint32_t SRV_MAX_DUTY = 2100 - 1;//
+const uint32_t SRV_MIN_DUTY = 900 - 1;//
 
-const uint8_t SRV_IDX_SHIFT = 3;//74HC238�C���f�b�N�X�̓�͒[�q��(A,B,C)
-const uint8_t SRV_IDX_NUM = 1 << SRV_IDX_SHIFT;//&#65533;C&#65533;&#65533;&#65533;f&#65533;b&#65533;N&#65533;X&#65533;&#784;&#65533;(8)
-const uint8_t SRV_IDX_MASK = SRV_IDX_NUM - 1;//&#65533;w&#65533;&#65533;ch&#65533;&#777;&#65533;3bit&#65533;&#65533;&#65533;&#65533;}&#65533;X&#65533;N&#65533;&#65533;&#65533;&#37053;&#65533;&#1986;&#770;&#65533;&#65533;
-const uint8_t SRV_BANK_NUM = 3;//PWM&#65533;&#65533;&#65533;&#790;{&#65533;&#65533;
-const uint8_t SRV_CH_NUM = SRV_IDX_NUM * SRV_BANK_NUM;//&#65533;&#65533;&#65533;&#65533;&#148;\&#65533;&#515;T&#65533;[&#65533;{&#65533;&#65533;&#65533;[&#65533;^&#65533;&#65533;
+const uint8_t SRV_IDX_SHIFT = 3;//
+const uint8_t SRV_IDX_NUM = 1 << SRV_IDX_SHIFT;//
+const uint8_t SRV_IDX_MASK = SRV_IDX_NUM - 1;//
+const uint8_t SRV_BANK_NUM = 3;//
+const uint8_t SRV_CH_NUM = SRV_IDX_NUM * SRV_BANK_NUM;//
 
-volatile uint8_t SRV_Idx = 0;//&#65533;T&#65533;[&#65533;{&#65533;&#1538;&#65533;&#1410;&#65533;&#65533;p&#65533;&#771;J&#65533;E&#65533;&#65533;&#65533;^
-volatile uint32_t SRV_dutyTable[SRV_BANK_NUM][SRV_IDX_NUM];//&#65533;f&#65533;&#65533;&#65533;[&#65533;e&#65533;B&#65533;[&#65533;l
+volatile uint8_t SRV_Idx = 0;//
+volatile uint32_t SRV_dutyTable[SRV_BANK_NUM][SRV_IDX_NUM];//
 
 const uint32_t SRV_PWMTable[SRV_BANK_NUM][SRV_IDX_NUM]={
 {0,SRV_PERIOD,0,SRV_PERIOD,0,SRV_PERIOD,0,SRV_PERIOD},
@@ -25,6 +26,7 @@
 
 void Init_PWM(void);
 void SetDuty(uint8_t ch, uint32_t duty);
+void main_th(void);
 
 #endif  //PWM_H_2012_08_28_
 
@@ -34,6 +36,8 @@
 }
 #endif
 
+Ticker flip;
+
 int main(void) {
     
     for(int i = 0; i < SRV_CH_NUM; i++)
@@ -42,8 +46,16 @@
     }
     
     Init_PWM();
+    flip.attach(&main_th,5.0);
     
-    while (1);
+    while (1) {
+        //SetDuty(1,SRV_MAX_DUTY);
+        //sleep();
+    }
+}
+
+void main_th(void) {
+    SetDuty(1,0);
 }
 
 void PWM1_IRQHandler (void) {
@@ -75,6 +87,8 @@
 
     LPC_SC->PCLKSEL0 &= ~(3 << 12); // PCLK_TIMER0 ck/4 (00)
     LPC_SC->PCONP |= (1 << 6); // PCPWM1
+    
+    LPC_PWM1->IR |= (1<<0);//reset PWMMR0 flag
     LPC_PWM1->TCR = (1 << 1);//reset
     LPC_PWM1->PR = SystemCoreClock / 4 / 1000000 - 1; // prescale 1000kHz(1us&#65533;&#65533;&#65533;&#65533;)&#65533;&#65533;&#65533;&#65533;&#65533;&#273538;&#386;&#579;^&#65533;C&#65533;}&#65533;J&#65533;E&#65533;&#65533;&#65533;^&#65533;&#65533;J&#65533;E&#65533;&#65533;&#65533;g&#65533;A&#65533;b&#65533;v&#65533;&#65533;&#65533;&#37033;&#65533;&#386;&#65533;&#65533;&#65533;&#65533;&#1874;&#65533;
     LPC_PWM1->CTCR = 0;
@@ -88,14 +102,16 @@
     //LPC_PWM1->MR5 = SRV_MAX_DUTY;//(SRV_MAX_DUTY + SRV_MIN_DUTY) / 2;
     //LPC_PWM1->MR6 = SRV_MAX_DUTY;//(SRV_MAX_DUTY + SRV_MIN_DUTY) / 2;
 
-    LPC_PWM1->IR |= (1<<0);//reset PWMMR0 flag
-
-    NVIC_EnableIRQ(PWM1_IRQn);//enable
-
     LPC_PWM1->TCR = (1 << 0)|(1 << 3); // enable
     LPC_PWM1->PCR |= (0x3F << 9);//1-6 pwm
+    LPC_PWM1->LER |= 0x7E;
 
-    __enable_irq();
+    //__enable_irq();
+    //__disable_irq();
+    //NVIC_DisableIRQ(PWM1_IRQn);
+    
+    NVIC_SetPriority(PWM1_IRQn,0);//priority level (high)0~255(low)
+    NVIC_EnableIRQ(PWM1_IRQn);//enable
 }
 
 void SetDuty(uint8_t ch, uint32_t duty){