Skip to content

Commit

Permalink
Change pulse measurement to 16 MHz
Browse files Browse the repository at this point in the history
  • Loading branch information
laneboysrc committed Feb 28, 2014
1 parent e716a58 commit f9be745
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 25 deletions.
5 changes: 2 additions & 3 deletions firmware/pulse-measurement/pulse-measurement.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ extern void Output_result(void);
static void Init_hardware(void) {
//-----------------------------
// Clock initialization
// FIXME: do 32 MHz HW
OSCCON = 0b11110000; // 32MHz: 4x PLL enabled, 8 MHz HF, Clock determined by FOSC<2:0>
OSCCON = 0b01111000; // 16MHz: 4x PLL disabled, 8 MHz HF, Clock determined by FOSC<2:0>

//-----------------------------
// IO Port initialization
// FIXME: do 16F1825 ports
PORTA = 0;
LATA = 0;
ANSELA = 0;
APFCON0 = 0b10001000; // Use RC4/RA1 for UART TX/RX; RA3 for T1G
APFCON0 = 0b00000000; // Use RC4/RC5 for UART TX/RX; RA4 for T1G
APFCON1 = 0;
TRISA = 0b11111111; // Make all ports A input
TRISC = 0b11111111; // Make all ports C input
Expand Down
4 changes: 1 addition & 3 deletions firmware/pulse-measurement/servo-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
Called once during start-up of the firmware.
****************************************************************************/
void Init_input(void) {
// FIXME: Timer 1 at max speed; Single pulse gate mode

TMR1H = 0;
TMR1L = 0;

T1GCON = 0b11010000; // Single shot gate mode
T1CON = 0b01000001; // Timer1 runs on Fosc; Timer enabled
T1CON = 0b00100001; // Timer1 runs on Fosc/4; 1:4 pre-scaler; Timer enabled
}


Expand Down
112 changes: 93 additions & 19 deletions firmware/pulse-measurement/uart-output.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ static unsigned char tx_value;

static unsigned int val;

#define FOSC 32 // Osc frequency in MHz
#define BAUDRATE 38400 // Desired baudrate
#define BRGH_VALUE 1 // Either 0 or 1
#define SPBRG_VALUE (((10*FOSC*1000000/((64-(48*BRGH_VALUE))*BAUDRATE))+5)/10)-1
#define SPBRG_VALUE 104

static void UART_send(void);

Expand All @@ -17,8 +14,10 @@ static void UART_send(void);
Called once during start-up of the firmware.
****************************************************************************/
void Init_output(void) {
SPBRG = SPBRG_VALUE; // Baud Rate register, calculated by macro
BRGH = BRGH_VALUE;
BRG16 = 1;
BRGH = 1;
SPBRGH = SPBRG_VALUE >> 8;
SPBRGL = SPBRG_VALUE & 0xff;

SYNC=0; // Disable Synchronous/Enable Asynchronous
SPEN=1; // Enable serial port
Expand All @@ -36,28 +35,103 @@ void Init_output(void) {
****************************************************************************/
void Output_result(void) {
val = (TMR1H << 8) + TMR1L;

tx_value = val / 10000;

#if 0
tx_value = val & 0x0800 ? '1' : '0';
UART_send();

tx_value = val & 0x0400 ? '1' : '0';
UART_send();

tx_value = val & 0x0200 ? '1' : '0';
UART_send();
val = val % 10000;
tx_value = val / 1000;

tx_value = val & 0x0100 ? '1' : '0';
UART_send();
val = val % 1000;
tx_value = val / 100;

tx_value = ' ';
UART_send();
val = val % 100;
tx_value = val / 10;

tx_value = val & 0x0080 ? '1' : '0';
UART_send();

tx_value = val & 0x0040 ? '1' : '0';
UART_send();
tx_value = val % 10;

tx_value = val & 0x0020 ? '1' : '0';
UART_send();

tx_value = val & 0x0010 ? '1' : '0';
UART_send();

tx_value = val & 0x0008 ? '1' : '0';
UART_send();

tx_value = val & 0x0004 ? '1' : '0';
UART_send();

tx_value = val & 0x00012 ? '1' : '0';
UART_send();

tx_value = val & 0x0001 ? '1' : '0';
UART_send();
#endif


tx_value = 0;
while (val >= 9999) {
val -= 10000;
++tx_value;
}
tx_value += '0';
UART_send();

tx_value = 0;
while (val >= 1000) {
val -= 1000;
++tx_value;
}
tx_value += '0';
UART_send();

tx_value = 0;
while (val >= 100) {
val -= 100;
++tx_value;
}
tx_value += '0';
UART_send();

tx_value = 0;
while (val >= 10) {
val -= 10;
++tx_value;
}
tx_value += '0';
UART_send();

tx_value = val + '0';
UART_send();

tx_value = '\n';
UART_send();

for (val = 0; val < 1000; val++) {
;

#if 0
for (val = 0; val < 65500; val++) {
val = val - 33;
val = val + 42;
val = val - 145;
val = val + 33;
val = val - 42;
val = val + 145;
val = val - 33;
val = val + 42;
val = val - 145;
val = val + 33;
val = val - 42;
val = val + 145;
}

#endif
}


Expand Down

0 comments on commit f9be745

Please sign in to comment.