Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 1:feae56685ab1, committed 2014-03-27
- Comitter:
- joGenie
- Date:
- Thu Mar 27 15:36:48 2014 +0000
- Parent:
- 0:d80295a0bcc2
- Commit message:
- Projet S5;
Changed in this revision
| interrupt.h | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/interrupt.h Wed Mar 26 16:13:42 2014 +0000
+++ b/interrupt.h Thu Mar 27 15:36:48 2014 +0000
@@ -1,11 +1,17 @@
#ifndef INTERRUPT_H
#define INTERRUPT_H
-extern "C"
-{
-void interruptMatch();
-void interruptCapture();
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void interruptMatch(void);
+void interruptCapture(void);
+
+#ifdef __cplusplus
+}
+#endif
void initialize();
-}
+
#endif //INTERRUPT_H
\ No newline at end of file
--- a/main.cpp Wed Mar 26 16:13:42 2014 +0000
+++ b/main.cpp Thu Mar 27 15:36:48 2014 +0000
@@ -2,37 +2,67 @@
#include "interrupt.h"
Serial pc(USBTX, USBRX);
+DigitalOut led1(LED1);
+
void *accelerometer = Accelerometer_C_new();
bool capture = false;
+bool first = true;
+bool ready = false;
-extern "C" void interruptCapture()
+extern "C" void interruptCapture(void)
{
- capture = !capture;
-
- if (capture)
+ led1 = 1;
+ pc.printf("ALLO");
+ if ((LPC_TIM2->IR & 0x10) == 0x10) // Interrupt capture
+ {
+ ready = !ready;
+ if (first)
+ {
+ capture = !capture;
+ first = true;
+
+ LPC_TIM2->TC = 0; // clear timer counter
+ LPC_TIM2->PC = 0; // clear prescale counter
+ LPC_TIM2->PR = 0; // clear prescale register
+ LPC_TIM2->MCR |= 0x03; // interrupt and reset control
+ }
+
+ }
+ else if ((LPC_TIM2->IR & 0x01) == 0x01) // Interrupt match
{
- LPC_TIM3->TC = 0; // clear timer counter
- LPC_TIM3->PC = 0; // clear prescale counter
- LPC_TIM3->PR = 0; // clear prescale register
- LPC_TIM3->IR |= 0xFF;
-
- NVIC_EnableIRQ(TIMER3_IRQn); // Enable timer3 interrupt
-
+ if (ready)
+ {
+ if (capture)
+ {
+ LPC_TIM3->TC = 0; // clear timer counter
+ LPC_TIM3->PC = 0; // clear prescale counter
+ LPC_TIM3->PR = 0; // clear prescale register
+ LPC_TIM3->IR |= 0xFF;
+
+ NVIC_EnableIRQ(TIMER3_IRQn); // Enable timer3 interrupt
+ }
+ else
+ {
+ NVIC_DisableIRQ(TIMER3_IRQn); // Enable timer3 interrupt
+ }
+
+ ready = false;
+ first = false;
+ LPC_TIM2->MCR = 0;
+ }
}
- else
- {
- NVIC_DisableIRQ(TIMER3_IRQn); // Disable timer3 interrupt
- }
+
+ LPC_TIM2->IR |= 0xFF;
}
-extern "C" void interruptMatch()
+extern "C" void interruptMatch(void)
{
unsigned short* values;
values = Accelerometer_C_getAccelValue(accelerometer);
for(int i = 0; i < 3; i++)
- pc.printf("%d/n/r", values[i]);
+ pc.printf("%d\n", values[i]);
LPC_TIM3->IR |= 0x01; // Reset timer
@@ -41,26 +71,24 @@
void initialize()
{
// Set system control
- LPC_SC->PCONP |= (3 << 22); // Enable Timer2
+ LPC_SC->PCONP |= (3 << 22); // Enable Timer2 and Timer3
LPC_SC->PCLKSEL1 |= (1 << 12); // PClk Timer2 = CCLK
+ LPC_SC->PCLKSEL1 |= (1 << 14); // PClk Timer3 = CCLK
// Set pin connection
- LPC_PINCON->PINSEL0 |= (3 << 8) | (3<<20); // Pin 30 Capture and Pin X Match
+ LPC_PINCON->PINSEL0 |= (3 << 8) | (3 << 12) | (3 << 20); // Capture 2.0 and Match 2.0 and Match 3.0
// Set timer 2 for capture
LPC_TIM2->TC = 0; // clear timer counter
LPC_TIM2->PC = 0; // clear prescale counter
LPC_TIM2->PR = 0; // clear prescale register
- LPC_TIM2->TCR = (1 << 1); // reset timer
- LPC_TIM2->IR |= 0xFF; // Clear MR0 interrupt flag
+ LPC_TIM2->MR0 = SystemCoreClock / 10000;
+ LPC_TIM2->IR |= 0xFF; // Clear interrupt flag
LPC_TIM2->CCR |= (7 << 0); // enable cap2.0 rising-edge capture and falling-edge; interrupt on cap2.0
- LPC_TIM2->TCR = 1; // start Timer2
-
- NVIC_EnableIRQ(TIMER2_IRQn); //enable timer2 interrupt
// Set timer 3 for match
LPC_TIM3->MR0 = SystemCoreClock / 20;
- LPC_TIM3->MCR |= 0x03; //interrupt and reset control
+ LPC_TIM3->MCR |= 0x03; // interrupt and reset control
LPC_TIM3->TC = 0; // clear timer counter
LPC_TIM3->PC = 0; // clear prescale counter
LPC_TIM3->PR = 0; // clear prescale register
@@ -69,19 +97,17 @@
// Set call function
NVIC_SetVector(TIMER2_IRQn, uint32_t(interruptCapture));
- NVIC_SetVector(TIMER3_IRQn, uint32_t(interruptMatch));
+ NVIC_SetVector(TIMER3_IRQn, uint32_t(interruptMatch));
+
+ NVIC_EnableIRQ(TIMER2_IRQn); // enable timer2 interrupt
+ LPC_TIM2->TCR = 0x01; // start Timer2
}
int main()
{
- Accelerometer accel;
- while(1)
- {
- unsigned short* values;
- wait(0.1);
- values = accel.getAccelValue();
-
- for(int i = 0; i < 3; i++)
- pc.printf("%d/n/r", values[i]);
+ initialize();
+
+ while(true)
+ {
}
}