After developing the code on the PIC16F877A for my tachometer, I decided to use the PIC16F688 since it was cheaper and smaller. Below is the code to run Timer 1.
// PIC16F688
// Flash LED with Timer 1
// RoboSlave.Blogspot.com 6/2011
// -----------------------------------------------------------------------
// Includes
// -----------------------------------------------------------------------
#include "system.h" // Include general file
// -----------------------------------------------------------------------
// Configuration Bits
// -----------------------------------------------------------------------
#pragma DATA _CONFIG, _PWRTE_OFF & _WDT_OFF & _CPD_OFF & _HS_OSC & _CP_OFF
#pragma CLOCK_FREQ 20000600
// -----------------------------------------------------------------------
// Defines
// -----------------------------------------------------------------------
#define TimerLED portc.0
// -----------------------------------------------------------------------
// Interrupt
// -----------------------------------------------------------------------
void interrupt( void )
{
if( pir1 & (1<<TMR1IF) ) // Handle timer1 interrupt
{
TimerLED = !TimerLED; // Toggle Timer LED
pir1.TMR1IF = 0; // Reset interrupt flag
}
}
// -----------------------------------------------------------------------
// Main Program
// -----------------------------------------------------------------------
void main( void )
{
ansel = 0x00; //Configure portC as I/O
cmcon0 = 0xFF; //Configure portC as I/O
trisc = 0x00; //Configure port C
portc = 0x00; //Initialize port C
tmr1h = 0x00; //should be cleared before enabling interrupts
tmr1l = 0x00;
intcon.GIE = 1; //Global Interrupt Enable bit
intcon.PEIE = 1; //Peripheral Interrupt Enable bit
pie1.TMR1IE = 1; //Timer1 Overflow Interrupt Enable bit
t1con = 0b00010001;
while (1)
{
}
}
Saturday, June 18, 2011
Friday, June 17, 2011
Tachometer Board and Programming
Since the last post, I have been working on getting version 1.0 tachometer board up and running. It turns out that creating the schematic and laying out the board in one night is too fast for a novice like me. I made a number of simple mistakes that doomed the board from the schematic level.
Bad Schematic (REV -) |
Fixed Board |
Labels:
Project 4 - Tachometer
Subscribe to:
Posts (Atom)