electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » Microcontrollers and Programmable Logic
Atari Pokey Project
Post new topic   Reply to topic Moderators: State Machine
Page 1 of 1 [25 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
skrasms



Joined: Feb 21, 2008
Posts: 121
Location: Portland, OR

PostPosted: Wed Jun 11, 2008 12:35 pm    Post subject: Atari Pokey Project
Subject description: Interfacing a Pokey into a modular synth
Reply with quote  Mark this post and the followings unread

I've been working on this project for a while, and I've been stuck on the same problem for so long that I need outside help. The project is a synth module that opens up an Atari Pokey chip for VC control of pitch/volume with controls for waveforms. It is simple enough on paper, and I have successfully made the microcontroller code for controlling everything the Pokey can do. The problem is the VC control part. I am using a dsPIC30F4013 as the brain, and it has plenty of channels available for sampling analog voltages. I am running into all kinds of noise/strangeness on the VC signals as they are sampled. The data I end up with is very noisy and inaccurate. Since I am trying to have VC pitch the errors are very audible. I put in a pretty big averaging filter (5 samples) with a little feedback to stop the LSB from toggling, but I am still getting both noise and, from some inputs, bad values.

Would anyone be interested in helping? I know I will have to make information available about what I've done so far, but right now I haven't made any progress in a couple months because of this noise issue. Opening the project up is the only way I know it will get done Smile
Back to top
View user's profile Send private message
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20536
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Wed Jun 11, 2008 1:59 pm    Post subject: Reply with quote  Mark this post and the followings unread

Are you using multiple analog inputs?

If so, do you reserve enough setup time after switching the input channel and before you start the actual sample process (needed to level the sampling capacitor to the actual input value)?

_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
skrasms



Joined: Feb 21, 2008
Posts: 121
Location: Portland, OR

PostPosted: Wed Jun 11, 2008 2:37 pm    Post subject: Reply with quote  Mark this post and the followings unread

Blue Hell wrote:
Are you using multiple analog inputs?

If so, do you reserve enough setup time after switching the input channel and before you start the actual sample process (needed to level the sampling capacitor to the actual input value)?


Thank you for responding so quickly!

I had no idea there needed to be a delay between switching and sampling. I just have a delay for the sampling itself. Like this:
Code:

ADCHS = (channel to sample);
ADCON.F1 = 1; //start sampling
Delay_us(1)
ADCON.F1 = 0;//stop sampling, start conversion
while(ADCON1.F0==0){} //wait for conversion to finish


So I need to put another delay between changing ADCHS and ADCON.F1? What length of delay is normal?

The datasheet for the micro is here.
Back to top
View user's profile Send private message
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20536
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Wed Jun 11, 2008 3:53 pm    Post subject: Reply with quote  Mark this post and the followings unread

You have the delay already ... a micro second seems adequate as well, provided that the output impedance of the circuit feeding the processor analog input is low enough, for 1 us it might be allowed as high as 4k7.

How many bits of noise do you have?

_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
bugfight



Joined: Aug 02, 2007
Posts: 188
Location: Arlington, TX USA

PostPosted: Wed Jun 11, 2008 6:12 pm    Post subject: Reply with quote  Mark this post and the followings unread

are you using a switching psu? they can cause noise on analog lines...
Back to top
View user's profile Send private message
skrasms



Joined: Feb 21, 2008
Posts: 121
Location: Portland, OR

PostPosted: Thu Jun 12, 2008 9:33 am    Post subject: Reply with quote  Mark this post and the followings unread

Blue Hell wrote:
You have the delay already ... a micro second seems adequate as well, provided that the output impedance of the circuit feeding the processor analog input is low enough, for 1 us it might be allowed as high as 4k7.

How many bits of noise do you have?


I wrote a program to keep track of the highest/lowest values picked up by the A/D, and the results show some promise that it's a software problem. Feeding a constant DC voltage to the A/D I used the built-in code that came with my dev kit compared with my own code.

Taking highest minus the lowest for each case (the A/D is 12-bit, so these are out of 4095):
Dev kit code: 4
My code: 56

I am not using the dev kit code because it is very slow and blocks other processes. If I go that route then I cannot run other code while I wait for the conversion to happen.
So I would like to fix my code, but I am not sure where to start. All my A/D code together looks like this:

Code:

//initialization of registers
  ADPCFG = 0x000F;
  TRISD = 0x0;
  TRISB = 0x20; //PORTB.5 is input
 
  ADCON1 = 0;
  ADCSSL = 0;
  ADCON3 = 0x1002;
  ADCON2 = 0;
  ADCON1.F15 = 1;

//sampling (this part is in a loop)
  ADCHS = 5;
  ADCON1.F1 = 1;
  Delay_us(1);
  ADCON1.F1 = 0;
  while(ADCON1.F0==0){}
  adcInput1 = ADCBUF0;


I am willing to bet that I initialized something incorrectly.
Back to top
View user's profile Send private message
skrasms



Joined: Feb 21, 2008
Posts: 121
Location: Portland, OR

PostPosted: Thu Jun 12, 2008 5:42 pm    Post subject: Reply with quote  Mark this post and the followings unread

I did some more testing later in the day, and now I'm getting about the same large range of error for both the built in code and my code. I am not sure what changed.

The analog signal was pretty clean last time I checked on a scope. I'll see if I can get a measure of how noisy it is.
Back to top
View user's profile Send private message
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20536
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Thu Jun 12, 2008 6:03 pm    Post subject: Reply with quote  Mark this post and the followings unread

Oh I missed this one earlier today for some reason ... a delta of four is not too bad, 56 is a lot ... erm ... ad measurements tend to get messed up when you're developing and the board is connected to the PC (due to grounding trouble), could that be the problem?
_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
skrasms



Joined: Feb 21, 2008
Posts: 121
Location: Portland, OR

PostPosted: Thu Jun 12, 2008 6:39 pm    Post subject: Reply with quote  Mark this post and the followings unread

I disconnected the computer to see. Letting it run a few times I got a maximum peak-peak swing of around 56 again.
Back to top
View user's profile Send private message
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20536
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Thu Jun 12, 2008 7:16 pm    Post subject: Reply with quote  Mark this post and the followings unread

It's bed time for me now .. I hear birds waking up ... will see if I can find anything in the data sheets later. It's all a bit different from the pic18 I'm used to ... but I'll be using pic24/30 in the future myself, so this will not be wasted time .

Speaking about waste, for optimal performance on the pic18 I've always been using a timer interrupt to start the conversion and an ad interrupt to stuff the measurements into an array for use by the program itself. That way you don't need waits at all, the processor load will be evened out better, but it's not entirely for free of course.

_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
skrasms



Joined: Feb 21, 2008
Posts: 121
Location: Portland, OR

PostPosted: Fri Jun 13, 2008 9:27 am    Post subject: Reply with quote  Mark this post and the followings unread

Blue Hell wrote:

Speaking about waste, for optimal performance on the pic18 I've always been using a timer interrupt to start the conversion and an ad interrupt to stuff the measurements into an array for use by the program itself. That way you don't need waits at all, the processor load will be evened out better, but it's not entirely for free of course.


The code I posted is a little misleading because it's just to test the A/D. In my actual program there is other code running while the sampling and conversion take place.

I was using interrupts for a while in the beginning, but it got messy because some of the code can't be interrupted. For example, writing a 16-bit frequency to the Pokey needs two consecutive write cycles. If an interrupt falls between the write cycles then there is a small span of time where the frequency glitches because it doesn't have all its data. It took me a while to figure out why it sounded like there was some crazy FM going on in the beginning. Instead of constantly switching interrupts on and off I made everything run sequentially.

That's my reasoning anyway :)
Back to top
View user's profile Send private message
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20536
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Fri Jun 13, 2008 2:19 pm    Post subject: Reply with quote  Mark this post and the followings unread

skrasms wrote:
That's my reasoning anyway :)


There are pros and cons everywhere always ... but I was going to have a look at the data sheet for the initialization code, doing that now ...

_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20536
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Fri Jun 13, 2008 2:30 pm    Post subject: Reply with quote  Mark this post and the followings unread

... I see you are setting ADCON1 to zero, meaning form[1:0] is set to zero as well .. I can't find if that means

Signed fractional, Fractional, Signed integer or integer result format ... is there some other manual describing this ?

When it's set to signed fractional or fractional the AD result is left aligned. meaning large jumps in values for small changes in the LSB.

_________________
Jan

Last edited by Blue Hell on Fri Jun 13, 2008 2:35 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20536
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Fri Jun 13, 2008 2:35 pm    Post subject: Reply with quote  Mark this post and the followings unread

Ok I found a reference manual for the pic24/30 form[1:0] = 00 is OK to select integer format, so it's not that.
_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20536
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Fri Jun 13, 2008 3:22 pm    Post subject: Reply with quote  Mark this post and the followings unread

I split it out a bit ...

Code:

ADPCFG : $000f

  AD inputs 15 .. 4 used as amalog
  AD inputs  4 .. 0 used as digital

ADCON1 : $0000

  ADON      : 0   = AD module is off
  ADSIDL    : 0   = Continue module operation in idle mode
  FORM[1:0] : 00  = unsigned integer format, right aligned result
  SSRC[2:0] : 000 = Clearing sample bit ends sampling and starts conversion
  ASAM      : 0   = sampling begins when sample bit is set
  SAMP      : 0   = S&H is holding
  DONE      : 0   = no effect
 

ADCSSL : $0000

  No channels selected for auto scan mode


ADCON3 : $1002

  AD clock derrived from system clock

  Auto sample time = 16 TAD

  TAD = 3 * Tcy
 

ADCON2 : $0000

  VCFG[2:0] : 000  = Use Avdd and Avss as a voltage reference.
  CSCNA     : 0    = do not (auto) scan inputs
  BUFS      : 0    = only valid when BUFM = 1
  SMPI[3:0] : 0000 = Interrupts at the completion of conversion of every ...
  BUFM      : 0    = Always starts filling he buffer from the start address
  ALTS      : 0    = MUX A control bits select analog analog input for conversion
 

ADCON1.F15 = 1 -> turn on the AD module


  NOTE :
 
  To return from the actrive mode from the off mode a wait is needed for the analog circuitry to stabilize ...
  as this is no in the loop this should only be a problem the first couple of times.
 
  this time is 20 us (AD63 - Tdpu)

ADCHS = 5 -> select channel 5 for sampling

ADCON1.F1 = 1 -> start sampling

Delay 1us

ADCON1.F1 = 0 -> stop sampling, start conversion

wait for ADCON1.F0 to go 1 (conversion completed)

ADCBUF0 -> value  read the converted value


Everything seems OK, except for the 20 us delay after turning on the DA converter, but that should take care of itself after a couple of samples.

Another thing is the conversion times that are set to be derrived from the system clock, so :

What system clock frequency are you using, and do you have the PLL on etc. ?

_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
skrasms



Joined: Feb 21, 2008
Posts: 121
Location: Portland, OR

PostPosted: Fri Jun 13, 2008 4:24 pm    Post subject: Reply with quote  Mark this post and the followings unread

Thank you very much for helping!

Right now I'm using a 10MHz crystal with the 8x PLL enabled.

I have experimented with the ADCS register on ADCON3, but without any improvements.

The datasheet says ADCS should be 2*(Tad/Tcy) - 1
I thought Tcy was 1/clock, in this case 1/80Mhz = 12.5ns
Tad must be at least 667ns according to the datasheet.

So ADCS = 105, which isn't possible given ADCS is only 6 bits. I tried increasing ADCS to the maximum to see if anything at least improved, but
ADCS values greater than 0x10 are freezing the micro.

Additionally I tried changing to a 4x PLL from 8x so I could set ADCS properly, but the LCD code I have doesn't play well at that speed.
Back to top
View user's profile Send private message
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20536
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Fri Jun 13, 2008 4:32 pm    Post subject: Reply with quote  Mark this post and the followings unread

Ah, ok, but you could assign the internal AD RC oscillator for the AD timing, I think?
_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
skrasms



Joined: Feb 21, 2008
Posts: 121
Location: Portland, OR

PostPosted: Fri Jun 13, 2008 4:42 pm    Post subject: Reply with quote  Mark this post and the followings unread

Blue Hell wrote:
Ah, ok, but you could assign the internal AD RC oscillator for the AD timing, I think?


The datasheet says the ADRC control is bit 7 of ADCON3. I tried
ADCON3 = 0x1080
but with that I'm not getting any data at all.
Back to top
View user's profile Send private message
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20536
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Fri Jun 13, 2008 5:12 pm    Post subject: Reply with quote  Mark this post and the followings unread

I don't know if you've seen the family reference manual already, it's sort of impossible to find on the microshit site Rolling Eyes http://ww1.microchip.com/downloads/en/DeviceDoc/70046E.pdf - it explains the control registers a bit at least ... I must say that I've seen better docs, if not that documentation sucks in this case ... but .. the good news is that section 18.25 of the doc linked above has design tips ...

Quote:

Question 1: How can I optimize the system performance of the A/D converter?
Answer:
1. Make sure you are meeting all of the timing specifications. If you are turning the module
off and on, there is a minimum delay you must wait before taking a sample. If you are
changing input channels, there is a minimum delay you must wait for this as well, and
finally, there is TAD, which is the time selected for each bit conversion. This is selected in
ADCON3 and should be within a certain range, as specified in the Electrical Characteristics.
If TAD is too short, the result may not be fully converted before the conversion is
terminated, and if TAD is made too long, the voltage on the sampling capacitor can decay
before the conversion is complete. These timing specifications are provided in the
“Electrical Specifications” section of the device data sheets.
2. Often, the source impedance of the analog signal is high (greater than 10 kΩ), so the
current drawn from the source by leakage, and to charge the sample capacitor, can affect
accuracy. If the input signal does not change too quickly, try putting a 0.1 μF capacitor on
the analog input. This capacitor will charge to the analog voltage being sampled and
supply the instantaneous current needed to charge the 18 pF internal holding capacitor.
3. Put the device into Sleep mode before the start of the A/D conversion. The RC clock
source selection is required for conversions in Sleep mode. This technique increases
accuracy, because digital noise from the CPU and other peripherals is minimized.


and 18.26 says :

Quote:

This section lists application notes that are related to this section of the manual. These
application notes may not be written specifically for the dsPIC30F Product Family, but the
concepts are pertinent and could be used with modification and possible limitations. The current
application notes related to the 12-bit A/D Converter module are:
Title Application Note #
Using the Analog-to-Digital (A/D) Converter AN546
Four Channel Digital Voltmeter with Display and Keyboard AN557
Understanding A/D Converter Performance Specifications AN693


those ANs might be findable ... Laughing

_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
skrasms



Joined: Feb 21, 2008
Posts: 121
Location: Portland, OR

PostPosted: Fri Nov 28, 2008 11:09 pm    Post subject: Reply with quote  Mark this post and the followings unread

I still don't have good results with this yet. I don't understand why it is so difficult.

Makes me wonder if maybe it's not my fault... Question

_________________
Software and Hardware Design
Back to top
View user's profile Send private message
Lofi Ninja



Joined: Oct 25, 2008
Posts: 143
Location: Jupiter

PostPosted: Fri Jul 24, 2009 10:59 am    Post subject: Reply with quote  Mark this post and the followings unread

Did this project go any further ? I have a couple of Pokey's that needs a home ! And they don't mind to be noisy Wink
_________________
www.youtube.com/user/lofininja
Back to top
View user's profile Send private message
skrasms



Joined: Feb 21, 2008
Posts: 121
Location: Portland, OR

PostPosted: Sun Jul 26, 2009 8:38 pm    Post subject: Reply with quote  Mark this post and the followings unread

I gave up on using the dsPIC's A/D. I followed every app note and data sheet, but still got noisy/skewed results. I found that by increasing the sampling time about 5x I got much better data, but that ruined the chip's quoted sample rate.

I switched to a dedicated A/D converter. I'm still working on the updated circuit board.

_________________
Software and Hardware Design
Back to top
View user's profile Send private message
Lofi Ninja



Joined: Oct 25, 2008
Posts: 143
Location: Jupiter

PostPosted: Mon Jul 27, 2009 4:20 am    Post subject: Reply with quote  Mark this post and the followings unread

Is there any schematics and software for the old one available ?
_________________
www.youtube.com/user/lofininja
Back to top
View user's profile Send private message
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20536
Location: The Netherlands, Enschede
Audio files: 147
G2 patch files: 318

PostPosted: Tue Jul 28, 2009 2:56 pm    Post subject: Reply with quote  Mark this post and the followings unread

skrasms wrote:
I switched to a dedicated A/D converter.


Too bad, but good to see you're still on it Cool

_________________
Jan
Back to top
View user's profile Send private message Visit poster's website
CYBERYOGI =CO=Windler



Joined: Aug 05, 2012
Posts: 10
Location: Germany

PostPosted: Sun Aug 05, 2012 9:22 pm    Post subject:   Reply with quote  Mark this post and the followings unread

Ah, the mysterious unique sound of POKEY... I would love to build an entire organ sounding like that.

I wrote a long AtariAge article about it:
POKEY timbres: Sound programming info needed! (Is there a FAQ?)

Has anybody already made a software synthesizer with enhanced pokey sounds (filters, more timbres, switchable tone scale etc.)?

_________________
Code:
MAY THE SOFTWARE BE WITH YOU!
*============================================================================*
CYBERYOGI Christian Oliver(=CO=) Windler
(teachmaster of LOGOLOGIE - the first cyberage-religion!)
!
*=============================ABANDON=THE=BRUTALITY==========================*
{http://weltenschule.de/e_index.html}
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: State Machine
Page 1 of 1 [25 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » Microcontrollers and Programmable Logic
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
e-m mkii

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use