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.
Dependencies: mbed PowerControl
Fork of Projet_S5 by
main.cpp@5:6313ddd0dfdd, 2014-04-03 (annotated)
- Committer:
- joGenie
- Date:
- Thu Apr 03 14:28:33 2014 +0000
- Revision:
- 5:6313ddd0dfdd
- Parent:
- 4:f72c51a2108c
- Child:
- 6:ef8bfca9e69b
Value in char;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| joGenie | 0:d80295a0bcc2 | 1 | #include "accelerometer.h" |
| joGenie | 3:17a4ceb30535 | 2 | #include "analyzer.h" |
| joGenie | 0:d80295a0bcc2 | 3 | #include "interrupt.h" |
| joGenie | 0:d80295a0bcc2 | 4 | |
| joGenie | 0:d80295a0bcc2 | 5 | Serial pc(USBTX, USBRX); |
| joGenie | 1:feae56685ab1 | 6 | DigitalOut led1(LED1); |
| joGenie | 4:f72c51a2108c | 7 | DigitalOut led2(LED2); |
| joGenie | 4:f72c51a2108c | 8 | DigitalOut led4(LED4); |
| joGenie | 4:f72c51a2108c | 9 | DigitalIn button(p30); |
| joGenie | 1:feae56685ab1 | 10 | |
| joGenie | 0:d80295a0bcc2 | 11 | void *accelerometer = Accelerometer_C_new(); |
| joGenie | 4:f72c51a2108c | 12 | void *analyzer = Analyzer_C_new(); |
| joGenie | 4:f72c51a2108c | 13 | bool rebound = true; |
| joGenie | 4:f72c51a2108c | 14 | bool appuyer = false; |
| joGenie | 0:d80295a0bcc2 | 15 | |
| joGenie | 1:feae56685ab1 | 16 | extern "C" void interruptCapture(void) |
| joGenie | 0:d80295a0bcc2 | 17 | { |
| joGenie | 4:f72c51a2108c | 18 | if(rebound && !appuyer) |
| joGenie | 1:feae56685ab1 | 19 | { |
| joGenie | 4:f72c51a2108c | 20 | LPC_TIM2->TC = 0; // clear timer counter |
| joGenie | 4:f72c51a2108c | 21 | LPC_TIM2->PC = 0; // clear prescale counter |
| joGenie | 4:f72c51a2108c | 22 | LPC_TIM2->PR = 0; // clear prescale register |
| joGenie | 4:f72c51a2108c | 23 | LPC_TIM2->MCR |= 0x03; // interrupt and reset control |
| joGenie | 4:f72c51a2108c | 24 | LPC_TIM2->CCR = 0; //no capture interupt |
| joGenie | 4:f72c51a2108c | 25 | rebound = false; |
| joGenie | 4:f72c51a2108c | 26 | } |
| joGenie | 4:f72c51a2108c | 27 | else if(!rebound && !appuyer) |
| joGenie | 0:d80295a0bcc2 | 28 | { |
| joGenie | 4:f72c51a2108c | 29 | led1 = 1; |
| joGenie | 4:f72c51a2108c | 30 | LPC_TIM2->MCR = 0; |
| joGenie | 4:f72c51a2108c | 31 | LPC_TIM2->CCR = (0x06 << 0); //falling edge |
| joGenie | 4:f72c51a2108c | 32 | |
| joGenie | 4:f72c51a2108c | 33 | LPC_TIM3->TC = 0; // clear timer counter |
| joGenie | 4:f72c51a2108c | 34 | LPC_TIM3->PC = 0; // clear prescale counter |
| joGenie | 4:f72c51a2108c | 35 | LPC_TIM3->PR = 0; // clear prescale register |
| joGenie | 4:f72c51a2108c | 36 | LPC_TIM3->IR |= 0xFF; |
| joGenie | 4:f72c51a2108c | 37 | LPC_TIM3->TCR = 0x01; //enable timer 3 |
| joGenie | 4:f72c51a2108c | 38 | |
| joGenie | 4:f72c51a2108c | 39 | appuyer = true; |
| joGenie | 4:f72c51a2108c | 40 | NVIC_EnableIRQ(TIMER3_IRQn); // Enable timer3 interrupt |
| joGenie | 0:d80295a0bcc2 | 41 | } |
| joGenie | 4:f72c51a2108c | 42 | else |
| joGenie | 4:f72c51a2108c | 43 | { |
| joGenie | 4:f72c51a2108c | 44 | led1 = 0; |
| joGenie | 4:f72c51a2108c | 45 | LPC_TIM2->CCR = (0x05 << 0); //rising edge |
| joGenie | 4:f72c51a2108c | 46 | |
| joGenie | 4:f72c51a2108c | 47 | LPC_TIM3->TC = 0; // clear timer counter |
| joGenie | 4:f72c51a2108c | 48 | LPC_TIM3->PC = 0; // clear prescale counter |
| joGenie | 4:f72c51a2108c | 49 | LPC_TIM3->PR = 0; // clear prescale register |
| joGenie | 4:f72c51a2108c | 50 | LPC_TIM3->IR |= 0xFF; |
| joGenie | 4:f72c51a2108c | 51 | LPC_TIM3->TCR = 0; //disable timer 3 |
| joGenie | 4:f72c51a2108c | 52 | |
| joGenie | 4:f72c51a2108c | 53 | appuyer = false; |
| joGenie | 4:f72c51a2108c | 54 | rebound = true; |
| joGenie | 4:f72c51a2108c | 55 | NVIC_DisableIRQ(TIMER3_IRQn); // Disable timer3 interrupt |
| joGenie | 4:f72c51a2108c | 56 | } |
| joGenie | 4:f72c51a2108c | 57 | |
| joGenie | 1:feae56685ab1 | 58 | |
| joGenie | 1:feae56685ab1 | 59 | LPC_TIM2->IR |= 0xFF; |
| joGenie | 0:d80295a0bcc2 | 60 | } |
| joGenie | 0:d80295a0bcc2 | 61 | |
| joGenie | 1:feae56685ab1 | 62 | extern "C" void interruptMatch(void) |
| joGenie | 0:d80295a0bcc2 | 63 | { |
| joGenie | 4:f72c51a2108c | 64 | if(button) |
| joGenie | 4:f72c51a2108c | 65 | { |
| joGenie | 4:f72c51a2108c | 66 | led4 = !led4; |
| joGenie | 5:6313ddd0dfdd | 67 | char* values; |
| joGenie | 0:d80295a0bcc2 | 68 | |
| joGenie | 4:f72c51a2108c | 69 | values = Accelerometer_C_getAccelValue(accelerometer); |
| joGenie | 5:6313ddd0dfdd | 70 | |
| joGenie | 5:6313ddd0dfdd | 71 | Analyzer_C_setMinMax(values, analyzer); |
| joGenie | 0:d80295a0bcc2 | 72 | |
| joGenie | 4:f72c51a2108c | 73 | pc.printf("\n\r x: %d, y: %d, z: %d; ", values[0],values[1],values[2]); |
| joGenie | 4:f72c51a2108c | 74 | |
| joGenie | 4:f72c51a2108c | 75 | // Analyze data |
| joGenie | 4:f72c51a2108c | 76 | Analyzer_C_setMinMax(values, analyzer); |
| joGenie | 2:d7784cc39c81 | 77 | |
| joGenie | 4:f72c51a2108c | 78 | delete values; |
| joGenie | 4:f72c51a2108c | 79 | } |
| joGenie | 4:f72c51a2108c | 80 | |
| joGenie | 4:f72c51a2108c | 81 | LPC_TIM3->IR |= 0xFF; // Reset timer |
| joGenie | 0:d80295a0bcc2 | 82 | } |
| joGenie | 0:d80295a0bcc2 | 83 | |
| joGenie | 0:d80295a0bcc2 | 84 | void initialize() |
| joGenie | 0:d80295a0bcc2 | 85 | { |
| joGenie | 4:f72c51a2108c | 86 | |
| joGenie | 4:f72c51a2108c | 87 | // CAPTURE |
| joGenie | 4:f72c51a2108c | 88 | // Enable the pins on the device to use TIMER CAP2.0 on pin 30 |
| joGenie | 5:6313ddd0dfdd | 89 | LPC_PINCON->PINSEL0 |= 3 << 8; //set pin 30 capture 2.0 |
| joGenie | 5:6313ddd0dfdd | 90 | LPC_SC->PCONP |= (1 << 22); // Timer2 power on |
| joGenie | 0:d80295a0bcc2 | 91 | |
| joGenie | 5:6313ddd0dfdd | 92 | //LPC_TIM2->MCR |= 3; //interrupt and reset control |
| joGenie | 4:f72c51a2108c | 93 | LPC_TIM2->TC = 0; // clear timer counter |
| joGenie | 4:f72c51a2108c | 94 | LPC_TIM2->PC = 0; // clear prescale counter |
| joGenie | 4:f72c51a2108c | 95 | LPC_TIM2->PR = 0; // clear prescale register |
| joGenie | 4:f72c51a2108c | 96 | LPC_TIM2->MR0 = SystemCoreClock / 100; //match pour rebound |
| joGenie | 4:f72c51a2108c | 97 | |
| joGenie | 5:6313ddd0dfdd | 98 | LPC_TIM2->IR |= 0xFF; // Clear CR0 interrupt flag |
| joGenie | 5:6313ddd0dfdd | 99 | LPC_TIM2->CCR = (5 << 0); // enable cap2.0 rising-edge capture; interrupt on cap2.0 p.496 |
| joGenie | 5:6313ddd0dfdd | 100 | LPC_TIM2->TCR = (1 << 1); // reset timer |
| joGenie | 5:6313ddd0dfdd | 101 | LPC_TIM2->TCR = 1; // enable timer |
| joGenie | 0:d80295a0bcc2 | 102 | |
| joGenie | 5:6313ddd0dfdd | 103 | NVIC_EnableIRQ(TIMER2_IRQn); // Enable timer2 interrupt |
| joGenie | 4:f72c51a2108c | 104 | NVIC_SetVector(TIMER2_IRQn, uint32_t(interruptCapture)); |
| joGenie | 0:d80295a0bcc2 | 105 | |
| joGenie | 4:f72c51a2108c | 106 | // TIMER 3 |
| joGenie | 5:6313ddd0dfdd | 107 | LPC_SC->PCONP |= 1 << 23; // Timer3 power on |
| joGenie | 4:f72c51a2108c | 108 | |
| joGenie | 5:6313ddd0dfdd | 109 | LPC_TIM3->MCR |= 3; // Interrupt and reset control |
| joGenie | 5:6313ddd0dfdd | 110 | LPC_TIM3->TC = 0; // clear timer counter |
| joGenie | 5:6313ddd0dfdd | 111 | LPC_TIM3->PC = 0; // clear prescale counter |
| joGenie | 5:6313ddd0dfdd | 112 | LPC_TIM3->PR = 0; // clear prescale register |
| joGenie | 5:6313ddd0dfdd | 113 | LPC_TIM3->MR0 = SystemCoreClock / 20; |
| joGenie | 4:f72c51a2108c | 114 | |
| joGenie | 5:6313ddd0dfdd | 115 | LPC_TIM3->IR |= 0xFF; // Clear MR0 interrupt flag |
| joGenie | 5:6313ddd0dfdd | 116 | LPC_TIM3->TCR = (1 << 1); // Reset Timer3 |
| joGenie | 5:6313ddd0dfdd | 117 | LPC_TIM3->TCR = 0; // Disable timer |
| joGenie | 0:d80295a0bcc2 | 118 | |
| joGenie | 5:6313ddd0dfdd | 119 | //NVIC_EnableIRQ(TIMER3_IRQn); // Enable timer3 interrupt |
| joGenie | 1:feae56685ab1 | 120 | NVIC_SetVector(TIMER3_IRQn, uint32_t(interruptMatch)); |
| joGenie | 0:d80295a0bcc2 | 121 | } |
| joGenie | 0:d80295a0bcc2 | 122 | |
| joGenie | 0:d80295a0bcc2 | 123 | int main() |
| joGenie | 0:d80295a0bcc2 | 124 | { |
| joGenie | 3:17a4ceb30535 | 125 | |
| joGenie | 3:17a4ceb30535 | 126 | Analyzer analyzer; |
| joGenie | 1:feae56685ab1 | 127 | initialize(); |
| joGenie | 1:feae56685ab1 | 128 | |
| joGenie | 1:feae56685ab1 | 129 | while(true) |
| joGenie | 1:feae56685ab1 | 130 | { |
| joGenie | 0:d80295a0bcc2 | 131 | } |
| joGenie | 0:d80295a0bcc2 | 132 | } |
