Actually you gave me a good idea and eventually I have sorted out.
To answer your question: I stick with your project because you draw my attention, I consider it a nice start point to develop later more complex code or perhaps simpler.
You are right; it has to do with import/export data, not with the PIC and code, but is related with the project, to understand it and see where people may stumble if someone wants to replicate your tests.
I see the correct number in terminal, I guess. I see numbers but no idea if they are correct, because they come and go fast :) , anyway here is what I have done:
- Used RealTerm, set up the serial port as 115200 baud rate, 8bit of data, odd, 2bit stop, then on Display int16, then went to Capture, set to capture in capture.txt for 60s, but not as HEX.
- Then in Audacity I just went to Import Raw Data, Signed 16bit PCM, Little-endian, 1 Channel Mono, Sample Rate 44100 Hz, Start offset 0 bytes, Amount to Import 100%.
- And I got the same wave as in your .raw file above, the same frequency, of course less cycles and not sync with yours, which is logical.
- The same I could do it with Tera Term.
It did not cross to my mind to try to import as Raw Data the .txt file; I thought it must be always .raw file.
Everything is fine now, looks good. The exporting to .raw or text seems that involves saving first as uncompressed WAV file: https://www.hellomico.com/getting-started/convert-audio-to-raw/
. I will investigate that later.
Next I went to Audacity, Analyze, Sample Data Export, I have tried 100K samples with Data (CSV) and also Time Indexed (txt) and I have imported that resulted file in Excel with Data, From Text and after I arranged the samples I got a nice sine wave.
I am not hijacking your post; I just wanted to understand it in detail, with everything that is related with it, meaning replicating in detail and see the generated data, if it is genuine sine.
I have tried also Adobe Audition, where we can see and analyze even nicer the waveform. I measured the frequency by “hand” placing the cursors and I got 0.342s, around 2.92Hz as you mentioned above.
Do you mind if I come later with a different code, maybe simpler or better written, which does the same as yours or if I analyze the practical aspects/implications of the existing code?
Here is the result:https://goo.gl/oUdAhP