Proyecto de Tesis en Mecatrónica. Universidad Técnica del Norte. Ernesto Palacios <mecatronica.mid@gmail.com>

Dependencies:   EthernetNetIf HTTPServer QEI_hw RPCInterface mbed

Files at this revision

API Documentation at this revision

Comitter:
Yo_Robot
Date:
Fri Mar 23 03:16:06 2012 +0000
Parent:
0:8c5c37feacb8
Child:
2:a1b556d78a7f
Commit message:
Works as toggle BUT no output yet

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Feb 07 03:16:33 2012 +0000
+++ b/main.cpp	Fri Mar 23 03:16:06 2012 +0000
@@ -1,28 +1,67 @@
-#include "mbed.h"
-
-Serial     pc    ( USBTX, USBRX );
-DigitalOut enable( p7 );
-PwmOut     driver( p21);
-
-void ISR_Serial()
-{
-    float t;
-    pc.scanf( "%f", &t );
-    driver.period( t);
-}
-
-int main() 
-{
-    driver = 0.50;  //50% duty always for driver
-    enable = 1;
-    driver.period(0.5);
-    
-    pc.attach( &ISR_Serial );
-    
-    while(1)
-    {
-        
-        
-    }
-    
-}
+// 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!
+}
+
+
+