I'm using a dsPIC33F (Microchip) to sample a 555-timer signal. I've tried square, triangular, and "sinusoidal" signal shapes, but always have the same problem: the ADC samples the waveform correctly, but the result is always half of the expected frequency.

For example, my input is 440Hz, and when I plot what the ADC writes to the buffer, I get:

enter image description here

Without the lines it is:

enter image description here

On the oscilloscope I read it as 440Hz. My sampling frequency is 8kHz (which I checked with the oscilloscope by toggling a pin), and as I change it, the sampled values change to reflect that, so I'm almost certain I'm using the correct timer to trigger the ADC. Since each point represents 1/8000 = 0.000125s, the above graphs show a waveform with a period of 36*.000125=0.0045, or 222Hz.

I feel like the conversion time should have no effect, as long as it's shorter than 0.000125s. I'm confident that it is, and have tried different conversion times with no change. I know it's not the most efficient way of doing things, but to start I also convert only one sample at a time before triggering an interrupt and writing to the buffer. I'm not sure if that would matter.

If anyone has any ideas, I'd be grateful.

  • 2
    \$\begingroup\$ When you checked the sampling frequency by toggling a pin, did you toggle the pin at the sampling rate, and measure the output waveform frequency as 8kHz? That would mean that the sampling clock is 16kHz. \$\endgroup\$ – Justin Jul 9 '15 at 19:02
  • \$\begingroup\$ Wow, I figured it would be a dumb mistake, but I had hoped something a bit more respectable than that. Thank you. I wish I'd asked sooner. \$\endgroup\$ – MrUser Jul 9 '15 at 19:15
  • \$\begingroup\$ Glad you got it sorted out. I converted my comment to an answer so the question can be marked as resolved. \$\endgroup\$ – Justin Jul 9 '15 at 19:19

When you toggle a pin at a certain rate, the resulting waveform will have a frequency at half of the toggle rate. So if your output waveform was a 8kHz square wave, then your ADC sample rate is actually 16kHz, which explains the factor of 2 error.

| improve this answer | |
  • \$\begingroup\$ It can be pretty easy to forget to toggle twice for a single period. \$\endgroup\$ – Nick Williams Jul 9 '15 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.