Proyecto de Tesis en Mecatrónica. Universidad Técnica del Norte. Ernesto Palacios <mecatronica.mid@gmail.com>
Dependencies: EthernetNetIf HTTPServer QEI_hw RPCInterface mbed
main.cpp@1:186187f69295, 2012-03-23 (annotated)
- Committer:
- Yo_Robot
- Date:
- Fri Mar 23 03:16:06 2012 +0000
- Revision:
- 1:186187f69295
- Parent:
- 0:8c5c37feacb8
- Child:
- 2:a1b556d78a7f
Works as toggle BUT no output yet
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yo_Robot | 1:186187f69295 | 1 | // Example to set up an PTO based on the LPC TIMER0 external match register, ernestop |
Yo_Robot | 1:186187f69295 | 2 | |
Yo_Robot | 1:186187f69295 | 3 | #include "mbed.h" |
Yo_Robot | 1:186187f69295 | 4 | |
Yo_Robot | 1:186187f69295 | 5 | Serial pc( USBTX, USBRX ); |
Yo_Robot | 1:186187f69295 | 6 | DigitalOut myled( LED1 ); |
Yo_Robot | 1:186187f69295 | 7 | |
Yo_Robot | 1:186187f69295 | 8 | void Setup_PTO_Timer0(); |
Yo_Robot | 1:186187f69295 | 9 | |
Yo_Robot | 1:186187f69295 | 10 | int main() { |
Yo_Robot | 1:186187f69295 | 11 | |
Yo_Robot | 1:186187f69295 | 12 | int six = 0; |
Yo_Robot | 1:186187f69295 | 13 | six |= 15UL << 8; // New Value 16 |
Yo_Robot | 1:186187f69295 | 14 | pc.printf( "\n 1 << 8 = %d ", six ); |
Yo_Robot | 1:186187f69295 | 15 | |
Yo_Robot | 1:186187f69295 | 16 | Setup_PTO_Timer0(); |
Yo_Robot | 1:186187f69295 | 17 | |
Yo_Robot | 1:186187f69295 | 18 | while(1) { |
Yo_Robot | 1:186187f69295 | 19 | |
Yo_Robot | 1:186187f69295 | 20 | int test = ( (uint32_t)LPC_TIM0->EMR & 4 ) >> 2 ; |
Yo_Robot | 1:186187f69295 | 21 | if( test ) |
Yo_Robot | 1:186187f69295 | 22 | myled = 1; |
Yo_Robot | 1:186187f69295 | 23 | else |
Yo_Robot | 1:186187f69295 | 24 | myled = 0; |
Yo_Robot | 1:186187f69295 | 25 | |
Yo_Robot | 1:186187f69295 | 26 | wait(0.05); |
Yo_Robot | 1:186187f69295 | 27 | |
Yo_Robot | 1:186187f69295 | 28 | } |
Yo_Robot | 1:186187f69295 | 29 | } |
Yo_Robot | 1:186187f69295 | 30 | |
Yo_Robot | 1:186187f69295 | 31 | void Setup_PTO_Timer0(){ |
Yo_Robot | 1:186187f69295 | 32 | |
Yo_Robot | 1:186187f69295 | 33 | // power up TIMER0 (PCONP[1]) |
Yo_Robot | 1:186187f69295 | 34 | LPC_SC->PCONP |= 1 << 1; |
Yo_Robot | 1:186187f69295 | 35 | |
Yo_Robot | 1:186187f69295 | 36 | // reset and set TIMER0 to timer mode |
Yo_Robot | 1:186187f69295 | 37 | LPC_TIM0->TCR = 0x2; |
Yo_Robot | 1:186187f69295 | 38 | LPC_TIM0->CTCR = 0x0; |
Yo_Robot | 1:186187f69295 | 39 | |
Yo_Robot | 1:186187f69295 | 40 | // set prescaler |
Yo_Robot | 1:186187f69295 | 41 | LPC_TIM0->PR = 1000; |
Yo_Robot | 1:186187f69295 | 42 | |
Yo_Robot | 1:186187f69295 | 43 | // calculate period (1 interrupt every second) |
Yo_Robot | 1:186187f69295 | 44 | uint32_t period = ( SystemCoreClock / 4000 ); |
Yo_Robot | 1:186187f69295 | 45 | |
Yo_Robot | 1:186187f69295 | 46 | // set Extyernat match register |
Yo_Robot | 1:186187f69295 | 47 | LPC_TIM0->MR2 = period; |
Yo_Robot | 1:186187f69295 | 48 | LPC_TIM0->MR3 = period * 2; |
Yo_Robot | 1:186187f69295 | 49 | |
Yo_Robot | 1:186187f69295 | 50 | LPC_TIM0->MCR |= 1 << 10; // reset on MR3 |
Yo_Robot | 1:186187f69295 | 51 | |
Yo_Robot | 1:186187f69295 | 52 | LPC_TIM0->EMR |= 15UL << 8; // Toogle Pin MAT2.2 |
Yo_Robot | 1:186187f69295 | 53 | // and MAT2.3 |
Yo_Robot | 1:186187f69295 | 54 | |
Yo_Robot | 1:186187f69295 | 55 | LPC_PINCON->PINSEL0 |= 15UL << 16; //Set Funtcion to MAT2.2 |
Yo_Robot | 1:186187f69295 | 56 | // and MAT2.3 |
Yo_Robot | 1:186187f69295 | 57 | |
Yo_Robot | 1:186187f69295 | 58 | //Start the Timer 0 |
Yo_Robot | 1:186187f69295 | 59 | LPC_TIM0->TCR = 1; |
Yo_Robot | 1:186187f69295 | 60 | |
Yo_Robot | 1:186187f69295 | 61 | //OUTPUT ON PIN_5 AND PIN_6 |
Yo_Robot | 1:186187f69295 | 62 | // OF MBED WILL TOGGLE EVERY |
Yo_Robot | 1:186187f69295 | 63 | // SECOND... I hope! |
Yo_Robot | 1:186187f69295 | 64 | } |
Yo_Robot | 1:186187f69295 | 65 | |
Yo_Robot | 1:186187f69295 | 66 | |
Yo_Robot | 1:186187f69295 | 67 |