Time to revisit this old thread of mine, as I now have a cool use for frequency detection in my ongoing guitar project 'X'.
Basically, I want a PIC on my cct to establish when the same guitar note has been played for 'x' seconds (user configurable) - once this condition has been met, then the PIC will inoke some cool 'stuff' to kick in!
I parked this 'early exploratory thread' having gotten the comparator/frequency detect to work simply on a basic 12f683 - back then interrupts were fairly new to me...whilst now I don't pretend that I'm interrupt savvy (I don't need to be thanks to Darrel's routines!)...I think it's time to revisit & try to apply to the more advanced PIC I'm using now - a 16F690.
Now looking at the comparator module on the 16f690 datasheet - wooooaaah.....a bit scary. So a couple of early questions before I have a pop at this tonight.
Due to the layout of my board, pin 7 looks like a prime candidate for getting my analogue signal into the PIC - could someone please confirm that this is indeed a valid comparator input pin?!!
Ok, wrt what signal I'm feeding into the comparator - essentially with no guitar signal present the quiescent voltage will be +4V (which is also the PIC rail voltage) - in my cct config, a diode half wave rectifies the guitar signal so when a signal is present ....the PIC will just see negative portions of the signal.
So, with respect to the voltage to 'flip' the comparator - I guess, I'd need something in the region of +3V? (ie any incoming signal with a negative swing of 1V will flip the comparator). a quick look at the datasheet suggests there are 16 'reference levels' that can be used internally within the PIC - cool, looks like that should be ok (I'll need to have a dabble with the VRCON register)
Ok, now assuming I get the comparator 'flipping' at the right voltage level .....what to do with it to get the most dependable frequency detection going on.
Just to reiterate - I would like to to detect when the guitar frequency has NOT changed for 'x' seconds (the' x' being user selectable selectable by a pot - I have this particular bit covered off already)
I see that DT's interrupts have a comparator interrupt....presumably that can be brought into play here?
So what would be a good building block here?
1. Start a countdown timer configured for 'x' seconds. (as mentioned above)
2. start looping (say a 300ms loop...whatever time window is needed to detect individual fret frequencies for the frequency range of guitar ...approx 70Hz thru 1300khz))
3. Clear comparator 'count' (a program variable)
4. Enable comparator interrupts
5. Start counting comparator interrupts
6. Stop loop, compare present number of comparator interrupt count with previous ...
i) if comparator count is 'within limits' then keep repeating (same note has been held held)
ii) if 'outside limits...then reset step 1 countdown timer (ie a different note detected, so reset & start again)
7. countdown timer expires - condition therefore met (ie same note held for x seconds)....go and invoke some cool stuff!!
Any thoughts, problems etc? (I should point out that the guitar has a sustain device onboard, so the note can/will ring on forever - also such a sustained note is pretty sinuisoidal, stable....so the comparator should flip reasonably dependably)
Bookmarks