// Built with BFTC Rev. 1.0.0, lun 25 agosto 2014 16:16:16 /* Copyright 2014 Digital Technology Art SRL This file is part of Blackfin Toolchain (BFTC) project. BFTC is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. BFTC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Nome-Programma. If not, see <http://www.gnu.org/licenses/>. */ // Show how to implement a simple fast frequency meter on port PG0. // The meter is capable to work with a frequency higher then 1.5MHz // #include "main.h" #define PG_BIT PG0 // Bit used as input unsigned counter = 0; unsigned timebase = 1; // Interrupt service procedure // void PGCallback() { // Clear the interrupt request PPG_CLR = PG_BIT; counter++; } void gateCallback() { // Disable measure while display Set_PortGInterruptEnable(PG_BIT, false); printf("FREQUENCY = %6d Hz\n", counter/ timebase); // Clear the counter counter = 0; // Start the mesure Set_PortGInterruptEnable(PG_BIT, true); } unsigned char Menu() { printf("\n"); printf("COMMANDS ******************\n"); printf("0 - Time base 1s\n"); printf("1 - Time base 0.1s\n"); printf("> "); return GetChar_Uart0(); } int main(void) { int com; Set_PLL(16, 4); // CORE: 25MHz * 16 = 400MHz, SCLK: 400MHz / 4 = 100MHz Set_Port(); // Set the port according to project set Set_Uart0(115200); // printf is redirected to UART0 // Set an interrupt on the rising edge of the selected bit on PG port Set_PortGInterruptService(PG_BIT, PGCallback); Set_PortGInterruptEnable(PG_BIT, true); // Frequency meter gate Set_TimerInterruptService(TIMER_0, &gateCallback, 1000000); // Gate 1s Set_TimerEnable(TIMER_0, true); while(1) // Main loop { com = Menu(); switch(com) { case '0': Set_TimerInterruptService(TIMER_0, &gateCallback, 1000000); // Gate 1s timebase = 1; break; case '1': Set_TimerInterruptService(TIMER_0, &gateCallback, 100000); // Gate 0.1s timebase = 10; break; } } return 0; }
1.3.1