Controlor for Humanoid. Walking trajectory generator, sensor reflection etc.
Dependencies: Adafruit-PWM-Servo-Driver MPU6050 RS300 mbed
Diff: Source3.cpp
- Revision:
- 7:7c0621d33781
- Parent:
- 5:0ca9f1bc1fb0
diff -r 0ca9f1bc1fb0 -r 7c0621d33781 Source3.cpp --- a/Source3.cpp Tue Sep 18 06:48:47 2012 +0000 +++ b/Source3.cpp Tue Sep 18 16:16:23 2012 +0000 @@ -1,42 +1,12 @@ -#ifndef PWM_H_2012_08_28_ -#define PWM_H_2012_08_28_ - #include "LPC17xx.h" #include "mbed.h" -//#include "PowerControl.h" - -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;// -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;// +#include "pwm.h" -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}, -{0,0,SRV_PERIOD,SRV_PERIOD,0,0,SRV_PERIOD,SRV_PERIOD}, -{0,0,0,0,SRV_PERIOD,SRV_PERIOD,SRV_PERIOD,SRV_PERIOD} -}; - -void Init_PWM(void); -void SetDuty(uint8_t ch, uint32_t duty); +Ticker flip; void main_th(void); -#endif //PWM_H_2012_08_28_ - -#ifdef __cplusplus -extern "C" { - void PWM1_IRQHandler(); -} -#endif - -Ticker flip; +extern volatile uint8_t SRV_Idx; +extern volatile uint32_t SRV_dutyTable[SRV_BANK_NUM][SRV_IDX_NUM]; int main(void) { @@ -56,71 +26,4 @@ void main_th(void) { SetDuty(1,0); -} - -void PWM1_IRQHandler (void) { - - LPC_PWM1->MR1 = SRV_PWMTable[0][SRV_Idx]; - LPC_PWM1->MR2 = SRV_PWMTable[1][SRV_Idx]; - LPC_PWM1->MR3 = SRV_PWMTable[2][SRV_Idx]; - LPC_PWM1->MR4 = SRV_dutyTable[0][SRV_Idx]; - LPC_PWM1->MR5 = SRV_dutyTable[1][SRV_Idx]; - LPC_PWM1->MR6 = SRV_dutyTable[2][SRV_Idx]; - - LPC_PWM1->LER |= 0x7E; - - LPC_PWM1->IR |= (1<<0); // reset PWMMR0 flag - - SRV_Idx++; - - if(SRV_Idx >= SRV_IDX_NUM){ - SRV_Idx = 0; - } -} - -void Init_PWM(void) { - LPC_PINCON->PINSEL3 &= ~(3 << 4); // GPIO (00) - LPC_GPIO1->FIODIR |= (1 << 18); // output - - LPC_PINCON->PINSEL4 |= 0x555; // GPIO (00) - LPC_GPIO2->FIODIR |= 0x3F; // output - - 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����)�����񂲂ƂɃ^�C�}�J�E���^��J�E���g�A�b�v���邩�Ƃ����ݒ� - LPC_PWM1->CTCR = 0; - LPC_PWM1->MCR |= (1 << 1)|(1 << 0); // MR0R, MR0 - - LPC_PWM1->MR0 = SRV_PERIOD; // PWM(74HC238��G1)���2500us - //LPC_PWM1->MR1 = SRV_MAX_DUTY;//SRV_PERIOD; // �؂�ւ����(74HC238��A)1 - //LPC_PWM1->MR2 = SRV_MAX_DUTY;//SRV_PERIOD; // �؂�ւ����(74HC238��B) - //LPC_PWM1->MR3 = SRV_MAX_DUTY;//SRV_PERIOD; // �؂�ւ����(74HC238��C) - //LPC_PWM1->MR4 = SRV_MAX_DUTY;//(SRV_MAX_DUTY + SRV_MIN_DUTY) / 2; //PWM(74HC238��G1)�f���[�e�B�[(�j���[�g����) - //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->TCR = (1 << 0)|(1 << 3); // enable - LPC_PWM1->PCR |= (0x3F << 9);//1-6 pwm - LPC_PWM1->LER |= 0x7E; - - //__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){ - if(ch >= SRV_CH_NUM){ - return; - }else if(duty < SRV_MIN_DUTY){ - duty = SRV_MIN_DUTY; - }else if(duty > SRV_MAX_DUTY){ - duty = SRV_MAX_DUTY; - } - SRV_dutyTable[ch >> SRV_IDX_SHIFT][ch & SRV_IDX_MASK] = duty; } \ No newline at end of file