Test session
Dependencies: FatFileSystem MCP23017 WattBob_TextLCD mbed
Fork of Assignment_2_herpe by
freq_task.cpp
00001 /** 00002 * Task for getting the frequency from digital input on pin13. 00003 * The frequency is calculated by counting the number of rises 00004 * on the pin. This is done using an interupt handler. 00005 * 00006 * Author: Jacob Baungard Hansen 00007 */ 00008 #include "freq_task.h" 00009 00010 FrequencyTask::FrequencyTask(int starting_offset, int frequency_ms, 00011 State * state) 00012 : Task(starting_offset, frequency_ms) { 00013 00014 this->state = state; 00015 this->count = 0; 00016 this->interrupt = new InterruptIn(p13); 00017 00018 } 00019 00020 FrequencyTask::~FrequencyTask() { 00021 delete this->interrupt; 00022 } 00023 00024 /** 00025 * This is called by the interupt, simply adds one to the count 00026 */ 00027 void FrequencyTask::counter() { 00028 this->count++; 00029 } 00030 00031 void FrequencyTask::action() { 00032 // reset the count 00033 this->count=0; 00034 // Enable the iterrupt 00035 this->interrupt->rise<FrequencyTask>(this, &FrequencyTask::counter); 00036 // wait for a specied amout of time 00037 wait_ms(SAMPLE_LENGTH_MS); 00038 // disable interrupts 00039 this->interrupt->rise(NULL); 00040 //interupt.rise<FrequencyTask>(this, NULL); This crashes, should report bug to ARM 00041 int freq = 0; 00042 if (this->count > 0) { 00043 freq = count/(SAMPLE_LENGTH_MS*0.001); 00044 } 00045 00046 this->state->set_freq(freq); 00047 }
Generated on Thu Jul 14 2022 10:33:15 by
1.7.2
