Serial.println( String(count) + String(", ") + String(diffCount) ) The time is usually 99.6us but sometimes I see a time as short as 82us and as long as 104us. The time from the leading edge to leading edge is the time from ISR to ISR. In the ISR I turned an LED on and then off. To minimize processor loading I removed all serial stuff. I am trying to learn mdeb and interrupts. You might have to change the ADC settings to get the sampling rate high enough if you use this to read analog values. Remember to keep the called function minimal since it is run in the interrupt-context.ītw. Which is pretty close to the expected value of 10000 function calls per second considering that we are using delay() and Serial.print() for debugging. Serial.println( String(count) + String(", ") + String(diffCount) ) This is quite simple and mostly handles same role as classic Arduino micros-function.īetter way is to use the Ticker-class to call a function periodically through an interrupt.Įxample of calling a function every 100us: #include ĬounterTicker.attach_us( ISRcounter, 100 ) // Call ISRcounter function every 100 us.ĭiffCount = count - lastCount // Count how many times ISRcounter was called. There is a precise clock/timer implemented in the MBED-OS through the HighResClock-class which offers precision to at least microseconds. NRF_PPI->CHENSET = ( 1UL << PPI_CHANNEL_T4 ) NRF_PPI->CH.TEP = ( uint32_t )&NRF_GPIOTE->TASKS_OUT NRF_PPI->CH.EEP = ( uint32_t )&NRF_TIMER4->EVENTS_COMPARE NRF_GPIOTE->CONFIG = ( GPIOTE_CONFIG_MODE_Task EVENTS_COMPARE and GPIOTE->TASKS_OUT NRF_TIMER4->CC = 16000000 / SAMPLES_PER_SECOND // Needs prescaler set to 0 (1:1) 16MHz clock NRF_TIMER4->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled PRESCALER = 0 NRF_TIMER4->BITMODE = TIMER_BITMODE_BITMODE_16Bit NRF_TIMER4->MODE = TIMER_MODE_MODE_Timer In my example in this article, the function to be interrupted will be passed in as a parameter #define SAMPLES_PER_SECOND (2000000) I have seen similar codes with Timer4 settingsīut I don't know how he calls PPI to work This is related to the accuracy of the sampled data What I need is a "fixed cycle" to read the data
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |