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@4:f72c51a2108c, 2014-03-29 (annotated)
- Committer:
- joGenie
- Date:
- Sat Mar 29 13:52:23 2014 +0000
- Revision:
- 4:f72c51a2108c
- Parent:
- 3:17a4ceb30535
- Child:
- 5:6313ddd0dfdd
Bouton avec interrupt fonctionnel.; Ajoute de la classe analyzer pour analyser les donn?es de l'acc?l?rom?tre;
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 | 4:f72c51a2108c | 67 | unsigned short* values; |
| joGenie | 0:d80295a0bcc2 | 68 | |
| joGenie | 4:f72c51a2108c | 69 | values = Accelerometer_C_getAccelValue(accelerometer); |
| joGenie | 0:d80295a0bcc2 | 70 | |
| joGenie | 4:f72c51a2108c | 71 | pc.printf("\n\r x: %d, y: %d, z: %d; ", values[0],values[1],values[2]); |
| joGenie | 4:f72c51a2108c | 72 | |
| joGenie | 4:f72c51a2108c | 73 | // Analyze data |
| joGenie | 4:f72c51a2108c | 74 | Analyzer_C_setMinMax(values, analyzer); |
| joGenie | 2:d7784cc39c81 | 75 | |
| joGenie | 4:f72c51a2108c | 76 | delete values; |
| joGenie | 4:f72c51a2108c | 77 | } |
| joGenie | 4:f72c51a2108c | 78 | |
| joGenie | 4:f72c51a2108c | 79 | LPC_TIM3->IR |= 0xFF; // Reset timer |
| joGenie | 0:d80295a0bcc2 | 80 | } |
| joGenie | 0:d80295a0bcc2 | 81 | |
| joGenie | 0:d80295a0bcc2 | 82 | void initialize() |
| joGenie | 0:d80295a0bcc2 | 83 | { |
| joGenie | 4:f72c51a2108c | 84 | |
| joGenie | 4:f72c51a2108c | 85 | // CAPTURE |
| joGenie | 4:f72c51a2108c | 86 | // Enable the pins on the device to use TIMER CAP2.0 on pin 30 |
| joGenie | 4:f72c51a2108c | 87 | LPC_PINCON->PINSEL0 |= 3<<8; //set pin 30 capture 2.0 |
| joGenie | 4:f72c51a2108c | 88 | LPC_SC->PCONP |= (1 << 22); // Timer2 power on |
| joGenie | 0:d80295a0bcc2 | 89 | |
| joGenie | 4:f72c51a2108c | 90 | //LPC_TIM2->MCR |= 3; //interrupt and reset control |
| joGenie | 4:f72c51a2108c | 91 | LPC_TIM2->TC = 0; // clear timer counter |
| joGenie | 4:f72c51a2108c | 92 | LPC_TIM2->PC = 0; // clear prescale counter |
| joGenie | 4:f72c51a2108c | 93 | LPC_TIM2->PR = 0; // clear prescale register |
| joGenie | 4:f72c51a2108c | 94 | LPC_TIM2->MR0 = SystemCoreClock / 100; //match pour rebound |
| joGenie | 4:f72c51a2108c | 95 | |
| joGenie | 4:f72c51a2108c | 96 | LPC_TIM2->IR |= 0xFF; // Clear CR0 interrupt flag |
| joGenie | 4:f72c51a2108c | 97 | LPC_TIM2->CCR = (0x05 << 0); // enable cap2.0 rising-edge capture; interrupt on cap2.0 p.496 |
| joGenie | 4:f72c51a2108c | 98 | LPC_TIM2->TCR = (1 << 1); // reset timer |
| joGenie | 4:f72c51a2108c | 99 | LPC_TIM2->TCR = 1; // enable timer |
| joGenie | 0:d80295a0bcc2 | 100 | |
| joGenie | 4:f72c51a2108c | 101 | NVIC_EnableIRQ(TIMER2_IRQn); //enable timer2 interrupt |
| joGenie | 4:f72c51a2108c | 102 | NVIC_SetVector(TIMER2_IRQn, uint32_t(interruptCapture)); |
| joGenie | 0:d80295a0bcc2 | 103 | |
| joGenie | 4:f72c51a2108c | 104 | // TIMER 3 |
| joGenie | 4:f72c51a2108c | 105 | LPC_SC->PCONP |=1<<23; //timer3 power on |
| joGenie | 4:f72c51a2108c | 106 | |
| joGenie | 4:f72c51a2108c | 107 | LPC_TIM3->MCR |= 3; //interrupt and reset control |
| joGenie | 4:f72c51a2108c | 108 | LPC_TIM3->TC = 0; // clear timer counter |
| joGenie | 4:f72c51a2108c | 109 | LPC_TIM3->PC = 0; // clear prescale counter |
| joGenie | 4:f72c51a2108c | 110 | LPC_TIM3->PR = 0; // clear prescale register |
| joGenie | 4:f72c51a2108c | 111 | LPC_TIM3->MR0 = SystemCoreClock / 20; //100 msec ?? |
| joGenie | 4:f72c51a2108c | 112 | |
| joGenie | 4:f72c51a2108c | 113 | LPC_TIM3->IR |= 0xFF; // Clear MR0 interrupt flag |
| joGenie | 4:f72c51a2108c | 114 | LPC_TIM3->TCR = (1 << 1); //reset Timer3 |
| joGenie | 4:f72c51a2108c | 115 | LPC_TIM3->TCR = 0; //disable timer |
| joGenie | 0:d80295a0bcc2 | 116 | |
| joGenie | 4:f72c51a2108c | 117 | //NVIC_EnableIRQ(TIMER3_IRQn); //enable timer3 interrupt |
| joGenie | 1:feae56685ab1 | 118 | NVIC_SetVector(TIMER3_IRQn, uint32_t(interruptMatch)); |
| joGenie | 0:d80295a0bcc2 | 119 | } |
| joGenie | 0:d80295a0bcc2 | 120 | |
| joGenie | 0:d80295a0bcc2 | 121 | int main() |
| joGenie | 0:d80295a0bcc2 | 122 | { |
| joGenie | 3:17a4ceb30535 | 123 | |
| joGenie | 3:17a4ceb30535 | 124 | Analyzer analyzer; |
| joGenie | 1:feae56685ab1 | 125 | initialize(); |
| joGenie | 1:feae56685ab1 | 126 | |
| joGenie | 1:feae56685ab1 | 127 | while(true) |
| joGenie | 1:feae56685ab1 | 128 | { |
| joGenie | 0:d80295a0bcc2 | 129 | } |
| joGenie | 0:d80295a0bcc2 | 130 | } |
