Controlor for Humanoid. Walking trajectory generator, sensor reflection etc.
Dependencies: Adafruit-PWM-Servo-Driver MPU6050 RS300 mbed
Diff: Source3.cpp
- 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;//�C���f�b�N�X�̐�(8) -const uint8_t SRV_IDX_MASK = SRV_IDX_NUM - 1;//�w��ch�̉�3bit����}�X�N���邽�߂̂�� -const uint8_t SRV_BANK_NUM = 3;//PWM���̖{�� -const uint8_t SRV_CH_NUM = SRV_IDX_NUM * SRV_BANK_NUM;//����”\�ȃT�[�{���[�^�� +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;//�T�[�{�؂�ւ��p�̃J�E���^ -volatile uint32_t SRV_dutyTable[SRV_BANK_NUM][SRV_IDX_NUM];//�f���[�e�B�[�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����)�����񂲂ƂɃ^�C�}�J�E���^��J�E���g�A�b�v���邩�Ƃ����ݒ� 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){