Pages: [1] 2   Go Down
Author Topic: aMTP32M - help with bit clock  (Read 2195 times)
0 Members and 1 Guest are viewing this topic.
Mumbai
Offline Offline
Newbie
*
Karma: 0
Posts: 12
mootif adjustment
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

i'm trying to get control an Aplus chip aMTP32M (stores audio samples) with UNO having never gone down on binary before. I have tried a few things with SPI, know about MOSI and SCK and read much in the forums and tried to apply what I recently picked up from a my mini-project with shift registers. However, i'm might be looking at it so much that i missed the simple answer  [alt. m just a dunce.]  The pic aptly describes my question. Any input to ease my death is appreciated...


* bit-clock.png (11.44 KB, 792x166 - viewed 44 times.)
Logged

DeFenestrated

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 503
Posts: 19095
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What's the question? Post your code and describe what is or isn't happening.
Logged


Mumbai
Offline Offline
Newbie
*
Karma: 0
Posts: 12
mootif adjustment
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, sure. This chip (I believe assigned through software) requires just 2 lines, data and clock. I need to produce this sequence of signals from Arduino to trigger the playback of particular tracks. Sending just 00000000, 00000001, etc. to trigger track 1, track 2, respectively. The chip will play, but not based on the commands I send it. So, my question is what is the proper way to send serial based on the model I provided in the image?
I am interested in just having a simple test code run cleanly.


Code:
int clockPin = 13;
int dataPin = 11;

int i = 0;
byte b = B00000000;

void setup() {
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
digitalWrite(clockPin, LOW);

if(i==0){
  b = B00000000;
}
if(i==1){
  b = B00000001; 
}
if(i==2){
  b = B00000010; 
}

shiftOut(dataPin, clockPin, MSBFIRST, (b, BIN)); 
Serial.println(b, BIN);
 delay(10000);
i++;
  if(i>=2){
    i=0; 
  }
}
Logged

DeFenestrated

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 503
Posts: 19095
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You've lost me a bit with the Serial.println.

And this:

Code:
if(i==2){
  b = B00000010;  
}

Binary is just another way of looking at a number. You may as well have written:

Code:
if(i==2){
  b = 2;  
}

You can see that doesn't achieve much, right?

You are confusing a number of things here. I suggest you read this for a start:

http://www.gammon.com.au/spi

Then post a link to this device. If you are still confused we can talk then. Hint: you don't want to do Serial.println. You are swapping from SPI to async serial. They are different things.
Logged


Mumbai
Offline Offline
Newbie
*
Karma: 0
Posts: 12
mootif adjustment
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick, thanks for the link, it DID clarify protocols. I have included code to I am running based on what I figured from the readings. My intent is to use the SPI library. From some examples, it appears the library takes care of the pin assignments. After playing around with the settings, I found one mode which changed the track, but it was more like a toggle between two tracks, not a sequence. So, if I am using the SPI functions correctly, I'm thinking the problem is either with the chip, which can be set for 4 different types of communication, or I am using the wrong serial protocol. I'm not able to find more documentation then states serial, but the diagram seems to illustrate a synchronous protocol, minus a latch. Let me know what you think, if you think the code checks out, I will make a trip back to the local Aplus distributor to double check how it was programmed.

 
Code:
#include <SPI.h>
//int clockPin = 13; //SCK
//int dataPin = 11; //MOSI
int ss = 10; //slave select

void setup() {
  //pinMode(clockPin, OUTPUT);
  //pinMode(dataPin, OUTPUT);
  //pinMode(ss, OUTPUT);
digitalWrite(ss,LOW);
  //SPI.setBitOrder(MSBFIRST);
  //SPI.setClockDivider(SPI_CLOCK_DIV4); //default value = 4
  SPI.setDataMode(SPI_MODE3);
  /*
  mode 0 >> CPOL = 0 & CPHA = 0 (plays song #1 loop)
  mode 1 >> CPOL = 0 & CPHA = 1 (plays song #1 loop)
  mode 2 >> CPOL = 1 & CPHA = 0 (plays song #2 loop)
  mode 3 >> CPOL = 1 & CPHA = 1 (alternates between #2 and #3)
  */
  SPI.begin();
}

void loop() {
  for(int i=0; i<=5; i++){
    delay(2000);
    SPI.transfer(i);
    delay(2000);
Logged

DeFenestrated

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 503
Posts: 19095
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The code looks OK, as far as it goes. Can you post a link to the chip datasheet?
Logged


Mumbai
Offline Offline
Newbie
*
Karma: 0
Posts: 12
mootif adjustment
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the link to the product page:
http://www.aplusinc.com.tw/pro-multi2.html

And, here is the link to the datasheet PDF:
http://www.aplusinc.com.tw/pro-download/aMTPxxM-Datasheet_V1.0_20111223.pdf

I found the serial info to be a little vague, but maybe you can make sense of it. Perhaps this doesn't need a clock at all.(?)
Logged

DeFenestrated

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 503
Posts: 19095
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How have you got it wired?
Logged


Mumbai
Offline Offline
Newbie
*
Karma: 0
Posts: 12
mootif adjustment
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry for the hold, but I wanted to check back with the distributor. The chip is mounted on PCB, with circuits for a basic amp, for it is normally designed to be placed in a prayer box. 
So, I goofed, misunderstanding his accent and my funky Hindi comprehension skills. He programmed it for Key Trigger mode, not Serial. This requires a little more soldering. The pins on the chip PD1,PD2,PB0,etc. [as mapped out in the chip documentation] can be connected directly with Digi Outs of the Arduino. Of course, this code looks different and has a 30 track limit. i'm including sample code which uses a Digi In from the chip's BUSY signal pin to cue generation of a random track number. Please let me know if my coding can be better. m always wanting to improve.
Anyway, now that that worked, I will have the chip re-programmed and try out the SPI code in a few days.
 
Code:
const int track[] = {
  8, 9, 10, 11, 12, 13 };//PB0,PB1,PB2,PB3,PD1,PD2
int trackCount = 8;//number of samples
int busy = 7;//PD0 out
int val = LOW;

void setup() {
  Serial.begin(9600);
  for (int Pin = 0; Pin < trackCount; Pin++){
    pinMode(track[Pin], OUTPUT);
  }
  pinMode(busy, INPUT);
  randomSeed(analogRead(0));
}
 
void loop() {
  val = digitalRead(busy);
  if(val==LOW){
    int randNumber = random(trackCount);
      if(randNumber<=5){
        digitalWrite(track[randNumber], HIGH);
        delay(50);
        digitalWrite(track[randNumber], LOW);
        //Serial.print("single ");
        //Serial.println(track[randNumber]);
        //Serial.print("rand ");
        //Serial.println(randNumber);
      }
      if(randNumber>5){
        digitalWrite(track[(randNumber - 6)], HIGH);
        digitalWrite(track[(randNumber - 5)], HIGH);
        delay(50);
        digitalWrite(track[(randNumber - 6)], LOW);
        digitalWrite(track[(randNumber - 5)], LOW);
        //Serial.print("double ");
        //Serial.print(track[(randNumber - 6)]);
        //Serial.println(track[(randNumber - 5)]);
        //Serial.print("rand ");
        //Serial.println(randNumber);
      }
      delay(100);
  }
}


* 2012-04-21 15-32-32.jpg (527.14 KB, 1600x1200 - viewed 41 times.)
Logged

DeFenestrated

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 503
Posts: 19095
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if(randNumber<=5){
...
  }
 if(randNumber>5){

You could put in an "else". If the number is not <= 5 it must be > 5 right?

Code:
if(randNumber<=5){
...
 else {
Logged


Mumbai
Offline Offline
Newbie
*
Karma: 0
Posts: 12
mootif adjustment
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, and in following the same logic, the else if statements could continue to handle the 30 track max. for a chip programmed in key trigger mode. The chip was re-programmed to accept CPU serial mode, but the code using the SPI library from before is not triggering playback. I've tried modes besides what seems like the apparent one SPI.setDataMode(SPI_MODE3); but still no response. I also tried slowing down the clock divider but to no avail. I'm a little stumped; the image in from the datasheet represents a synchronous transfer minus a latch, right?
What to do?

 
Code:
#include <SPI.h>
/*
int clockPin = 13; SCK  = PB0 out
int dataPin = 11; MOSI = PB1 out
*/
int ss = 10; //slave select
int busy = 7; //PD0 busy signal
 
void setup() {
  //pinMode(clockPin, OUTPUT);
  //pinMode(dataPin, OUTPUT);
  pinMode(ss, OUTPUT);
  digitalWrite(ss,LOW);
  pinMode(busy, INPUT);
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV8); //default value = 4
  SPI.setDataMode(SPI_MODE3);
  /*
  mode 0 >> CPOL = 0 & CPHA = 0
  mode 1 >> CPOL = 0 & CPHA = 1
  mode 2 >> CPOL = 1 & CPHA = 0 
  mode 3 >> CPOL = 1 & CPHA = 1
  */
  SPI.begin();
}

void loop() {
  for(int i=0; i<=5; i++){
    SPI.transfer(i);
    delay(5000);
  }
 
}


* bit-clock.png (11.44 KB, 792x166 - viewed 28 times.)
Logged

DeFenestrated

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 503
Posts: 19095
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you draw your exact wiring and/or produce a photo?
Logged


Mumbai
Offline Offline
Newbie
*
Karma: 0
Posts: 12
mootif adjustment
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I included a photo in an earlier post, but I think it is impossible to follow. A simple layout follows. of course, it does not have the schematic for the board the aMTP32M is mounted on, but I am going pin-to-pin.


* aMTP_Arduino.png (32.7 KB, 901x636 - viewed 38 times.)
Logged

DeFenestrated

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 503
Posts: 19095
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No ground wire?
Logged


Mumbai
Offline Offline
Newbie
*
Karma: 0
Posts: 12
mootif adjustment
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, the ground is shared with the other components on the board. So Arduino is providing the 5v and gnd.
Logged

DeFenestrated

Pages: [1] 2   Go Up
Jump to: