Record/Playback Potentiometer Movement

So. I bought a few digital potentiometers, (the MCP42050, which communicates over SPI (http://ww1.microchip.com/downloads/en/DeviceDoc/11195c.pdf). I was looking to interface these with an arduino by first;

recording the playback of a mechanical potentiometer,

then playing this 'recording' continuously with the digital pot as an output.

i'd also like to be able to change the speed of playback. it's an audio application.. and i had no idea where to start..

Just remember that recording the analog pot will give you an integer value in the 0 - 1023 range that is not directly related to the resistance of the analog pot, you would then have to transform / map that value to one of the possible values on the digital pot.

An analog pot has in theory an infinit number of "positions" but after you read it it with the ADC it has 1024 distinct values. Most digital potentiometers has at the most 256 position so when you map your 1024 to 256 you will loose something in the conversion.

This may result in unwanted "zipper" noise and other ugly things.

The same thing will happen when you sample the analog pot in the first place. Unless you sample it very frequently (which will require a lot of RAM) you will end up with a "staircase model" of the original continous anlog signal.

It's possible but don't expect to your playback to sound just like what you recorded.

That is good advice from MikMo as it cuts down what you have to store.

While you can sample the pot at regular intervals this is an inefficient way of storing things. This is especially important as there is a limited amount of memory in the arduino.
A better method is to record a pot value only when it changes and also record the time from previous pot value.
Then playing back is simple after a delay of the time you output the new value.

thanks for the advice..

In regards to the space thing... i was thinking of only sampling the movement during the time a button is held.. more of a set and release type thing... btw, it's a guitar type project.

This is very interesting and almost the same thing i am trying to achieve.

i want to record my motion movements using either a joystick or the nunchuck or analog pot meters and be able to play back the recorded movement. I allready have all of those working with the arduino so the problem is being able to store whats being done with them and play it back at some point with a button or similar.

Would this be possible using a datalogger and some clever code?

I found the idea on this blog:

It's the 'hollow earth' pedal.. it's a really good idea for any instrument really..
there's a link to the code here (in BASIC), coded in Bascom, which I'll have to download soon to have a look at:

https://www.blogger.com/comment.g?blogID=3684765422590821364&postID=1574569669604670118

But, Vegard, post your code if you don't mind... Are you using digital pots as well..?

I just downloaded the code and bascom program..

'Looping waveshaper

'Init
$regfile = "m88def.dat"
$crystal = 8000000
$baud = 19200

Config Timer0 = Pwm , Prescale = 1 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up       'config timer0
Set Tccr0a.wgm01                                            'double pwm duty frequency so that it's out of audible range


Config Adc = Single , Prescaler = Auto , Reference = Internal
Start Adc
Config Pind.7 = Input                                       'config record button
Config Pind.5 = Input                                       'config punch-in toggle

'Variables
Dim Wavesample As Word
Dim Loopspeed As Word
Dim Waveloop(940) As Byte
Dim Sampleposition As Word
Dim Looplength As Word
Dim Limitreached As Boolean

'give default "quiet" sample on turn-on
Sampleposition = 0
Waveloop(1) = 255
Looplength = 1
Limitreached = 0

Wavesample = Getadc(1)
Wavesample = Wavesample / 4
Waveloop(sampleposition) = Wavesample


'Main loop
Mainloop:
Do
   If Pind.7 = 1 Then Limitreached = 0
   Sampleposition = Sampleposition + 1
   Pwm0a = Waveloop(sampleposition)
   If Pind.7 = 0 And Limitreached = 0 Then
      If Pind.5 = 1 Then Goto Recordloop
      If Pind.5 = 0 Then Goto Punchloop
   End If
   If Sampleposition = Looplength Then Sampleposition = 0
   Loopspeed = Getadc(0) / 6
   Loopspeed = Loopspeed + 2                                'sample speed pot value and do stuff with it
   Waitms Loopspeed
Loop


'Record new loop
Recordloop:
Sampleposition = 1
Do
   Wavesample = Getadc(1)
   Wavesample = Wavesample / 4
   Waveloop(sampleposition) = Wavesample
   Pwm0a = Waveloop(sampleposition)
   If Pind.7 = 1 Then
      Looplength = Sampleposition
      Sampleposition = 0
      Goto Mainloop
   End If
   If Sampleposition = 940 Then
      Limitreached = 1
      Looplength = Sampleposition
      Sampleposition = 0
      Goto Mainloop
   End If
   Sampleposition = Sampleposition + 1
   Loopspeed = Getadc(0) / 6
   Loopspeed = Loopspeed + 2
   Waitms Loopspeed
Loop


'Punch-in loop
Punchloop:
Do
   Wavesample = Getadc(1)
   Wavesample = Wavesample / 4
   Waveloop(sampleposition) = Wavesample
   Pwm0a = Waveloop(sampleposition)
   If Pind.7 = 1 Then
      Goto Mainloop
   End If
   If Sampleposition = Looplength Then
      Sampleposition = 0
   End If
   Sampleposition = Sampleposition + 1
   Loopspeed = Getadc(0) / 6
   Loopspeed = Loopspeed + 2
   Waitms Loopspeed
Loop


End