-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
90 lines (71 loc) · 2.29 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* File: main.c
* Author: Matti
*
* Created on July 28, 2021, 12:02 PM
*/
#include <pic18f26k83.h>
#include <stdbool.h>
#include <stdint.h>
#include "setup.h"
/* ****************** MAIN ****************** */
void main(void){
// Define vars
uint16_t results;
uint16_t zero;
bool firstcross = false;
uint8_t periods = [0, 0, 0, 0, 0];
uint8_t count = 0;
setpin(); // PORT B Setting: Set all the pins in port B to Output
timer0_init();
LED1_on();
LED2_on();
LED3_on();
//setup ADC
ADCON0bits.FM = 1; //right justify
ADCON0bits.CS = 1; //FRC Clock
ADPCH = 0x00; //RA0 is Analog channel UPDATE
TRISAbits.TRISA0 = 1; //Set RA0 to input UPDATE
ANSELAbits.ANSELA0 = 1; //Set RA0 to analog UPDATE
ADCON0bits.ON = 1; //Turn ADC On
ADCON0bits.GO = 1; //Start conversion
while (ADCON0bits.GO); //Wait for conversion done
zero = (ADRESH<<8) + ADRESL; //Read result
// Turn off lights to indicate 0 set
LED1_off();
LED2_off();
LED3_off();
while(true){
//while (count < 5){
ADCON0bits.GO = 1; //Start conversion
while (ADCON0bits.GO); //Wait for conversion done
results = (ADRESH<<8) + ADRESL; //Read result
if (results*0.95 > zero){
LED1_on();
}
}
/* Pseudo code time WOOO HOOO
* Define vars and whatnot
* [x]Setup ADC
* [x]Define what our 0 crossing val is
* []sample guitar input (probably within own loop so theres minimum commands between samples)
* []determine freq
* []determine which string we are probably tuning
* []turn servo x degrees, proportional to how off the tuning
* [] show lights whether high low on
* [] restart loop until string tuned
* [] loop some more so can do all strings
*
*
* Timer things: set value in timer0 counter to 0 when we start timing, read value at end, convert to hz
*
*/
}
}
static void __interrupt() interrupt_handler(){
if (PIE3bits.TMR0IE == 1 && PIR3bits.TMR0IF == 1) {
timer0_handle_interrupt();
PIR3bits.TMR0IF = 0;
}
}
/* THE END */