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

Committer:
Yo_Robot
Date:
2012-03-23
Revision:
1:186187f69295
Parent:
0:8c5c37feacb8
Child:
2:a1b556d78a7f

File content as of revision 1:186187f69295:

// Example to set up an PTO based on the LPC TIMER0 external match register, ernestop
 
#include "mbed.h"

Serial     pc( USBTX, USBRX );
DigitalOut myled( LED1 );

void Setup_PTO_Timer0();

int main() {
      
    int six = 0;
    six |= 15UL << 8; // New Value 16
    pc.printf( "\n 1 << 8 = %d ", six );
    
    Setup_PTO_Timer0();
    
    while(1) {
    
        int test = ( (uint32_t)LPC_TIM0->EMR & 4 ) >> 2 ;
        if( test )
          myled = 1;
        else
          myled = 0;
          
       wait(0.05);
    
    }
}

void Setup_PTO_Timer0(){
	
	// power up TIMER0 (PCONP[1])
    LPC_SC->PCONP |= 1 << 1; 

    // reset and set TIMER0 to timer mode
    LPC_TIM0->TCR  = 0x2; 
    LPC_TIM0->CTCR = 0x0; 

    // set prescaler
    LPC_TIM0->PR = 1000;

    // calculate period (1 interrupt every second)
    uint32_t period = ( SystemCoreClock / 4000 ); 

	// set Extyernat match register
    LPC_TIM0->MR2 = period;
    LPC_TIM0->MR3 = period * 2;
    
    LPC_TIM0->MCR |= 1 << 10;    // reset on MR3
    
    LPC_TIM0->EMR |= 15UL << 8;  // Toogle Pin MAT2.2 
                               //  and MAT2.3

    LPC_PINCON->PINSEL0 |= 15UL << 16;  //Set Funtcion to MAT2.2 
                                      // and MAT2.3 

    //Start the Timer 0
    LPC_TIM0->TCR = 1;

    //OUTPUT ON PIN_5 AND PIN_6
    // OF MBED WILL TOGGLE EVERY 
    // SECOND...   I hope!
}