Bit functions
The functions in this text file can be used with the C18 compiler to directly set, clear, and test bits of integers.
The functions in this text file can be used with the C18 compiler to directly set, clear, and test bits of integers.
Source and header for a project to measure rotation speed. The timing measurements are saved as ints (two bytes) to EEPROM.
Download the program to your PIC, remove the programmer and start up the fan. You should see LEDs on PORTB light up every time they cross the position sensor. When the LEDs stop lighting up, it's done taking measurements. All of the timing results are stored as ints (two bytes per measurement) in the EEPROM. To access the data, plug your programmer back in and go to Programmer -> Read EEDATA. Then, you can go to View -> EEPROM to view the EEPROM contents. Right click on Address 000 in the EEPROM view and select Export Table. Save the data to a text file, open it and copy the contents, and paste them into the spreadsheet located here to view the actual timer values for each rotation. It should reach a steady state around about EEPROM address 200.
Source code and header for an example project that displays text on a rotary POV using an external trigger (position sensing). Uses the value found from the timing measurement project above.
The function above will make your PIC run faster (16x faster!) Just copy & paste the declaration into your header, the function itself into your source file, and then call select16MHzClock() somewhere in the beginning of your main function to setup the 16MHz clock.