Show Posts
|
|
Pages: 1 ... 3 4 [5] 6
|
|
64
|
Using Arduino / Project Guidance / Help with multiplexer (74HC4051)
|
on: August 03, 2012, 04:56:40 pm
|
I am using an IC that has a data input of 8 bit. Instead of using 8 pins on my Arduino I want to use a multiplexer. So I connected it in the same way it's here: http://www.arduino.cc/es_old/Tutoriales/74HC4051but instead of doing a analogRead at the end, I do a digitalWrite to the "COM OUT/IN" pin on the multiplexer. And when trying to write a certain 8 bit value it doesn't work. I did a test reading a control pin on the multiplexer outputs but it's not even stable, it's erratic. Is it possible to use this multiplexer in the way I want? What's wrong???? Thanks!
|
|
|
|
|
65
|
Using Arduino / Programming Questions / Re: Problem with reading back from PROGMEM, HELP?
|
on: July 27, 2012, 01:54:40 pm
|
I used the example for Strings documented here: http://arduino.cc/en/Reference/PROGMEMThe problem seems to be giving it a variable instead of a constant where it is "i" here: strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); I really don't know why it does that, here it is used like that and it is suposed to work fine: for (int i = 0; i < 6; i++) { strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); // Necessary casts and dereferencing, just copy. Serial.println( buffer ); delay( 500 ); } Anyway... I resolved it by putting a number instead of "i" Thanks
|
|
|
|
|
66
|
Using Arduino / Programming Questions / Re: Problem with reading back from PROGMEM, HELP?
|
on: July 27, 2012, 12:37:52 pm
|
now, I "commented" some of the definition lines of PROGMEM at the beginning to check if it was memory problem and also I added this on the trouble line: printLog("menuIndex",menuIndex); // <--- ADDED THIS strcpy_P(buffer, (char*)pgm_read_word(&(menuOption[noteNumb]))); // <--- THIS LINE IS TROUBLE Serial.println(buffer); printLog("menuIndex",menuIndex); // <--- ADDED THIS
Its giving me trash on the Serial Monitor, and the programm crashes (on Arduino), it doesn't responds anymore.
|
|
|
|
|
67
|
Using Arduino / Programming Questions / Problem with reading back from PROGMEM, HELP?
|
on: July 27, 2012, 12:33:17 pm
|
I want to store a lot of strings for displaying it on an LCD, so first I do this: prog_char string_0[] PROGMEM = "1-Tempo"; prog_char string_1[] PROGMEM = "2-Lider gordo"; prog_char string_2[] PROGMEM = "3-Envolvente"; prog_char string_3[] PROGMEM = "3b-Forma de env"; ... etc etc prog_char string_34[] PROGMEM = "C#"; prog_char string_35[] PROGMEM = "C"; prog_char string_36[] PROGMEM = "B"; prog_char string_37[] PROGMEM = "A#"; prog_char string_38[] PROGMEM = "A";
PROGMEM const char *menuOption[] = {string_0,string_1,string_2,string_3,... etc etc ,string_38}; char buffer[16];
then when I want to display one of the strings on the LCD: strcpy_P(buffer, (char*)pgm_read_word(&(menuOption[21]))); lcd.print(buffer); and that seems to work fine. but when I want to return one of those strings back from a function I get a strange behavior String getNoteName(int pitch){ int oct = ((pitch-33)/12)+1; //33=A1 int noteNumb = pitch-((12*(oct+2))-3); noteNumb=noteNumb+38; //Index 38 is A, 37 is A#, 36 is B and so on... String noteName; strcpy_P(buffer, (char*)pgm_read_word(&(menuOption[noteNumb]))); // <--- THIS LINE IS TROUBLE! Serial.println(buffer); noteName = String(buffer); noteName.concat(oct); return noteName;
What that function does is you give it the note number and it returns the note name, for example "A4". The problem is that the line I point there is, somehow, changing the value for menuIndex when I do this: strcpy_P(buffer, (char*)pgm_read_word(&(menuOption[menuIndex]))); Serial.println(buffer); lcd.print(buffer); also when I print buffer to Serial it prints this: XüCcB6·Ø§9hV®º«U<·ÌWc½míýu>ör1 Any idea???? Very weird, I am not writing on the memory, always reading... or that is what I intend... Could it be that I am getting low on memory? my sketch is 19.300 bytes according to the bottom of the compiler Thanks!
|
|
|
|
|
68
|
Using Arduino / Project Guidance / Balance like knob?
|
on: July 23, 2012, 01:08:37 am
|
|
I am working on a small synth and I wanted to have one knob that detunes one oscillator from the main note. If someone detunes it and then wants to put it back to where it was, on a normal potentiometer you will have to use your ear. So I was thinking of having a potentiometer/knob like the one on some radios where you control the balance: When you reach the normal (center) position it clicks and goes to the exact middle, if you want to move it from the center the knob resists a little.
Could I buy it somewhere? What's called?
BONUS: Also what about ribbon resistor? A band that gets different R values depending on where you press it.
Thanks!
|
|
|
|
|
69
|
Using Arduino / General Electronics / Re: [SOLVED] Help with the AY-3-8910 IC datasheet!
|
on: July 20, 2012, 02:39:56 am
|
OH YEAH! The problem was the way I was sending the address for the registers. I used a library for fast pin switching so I didn't have to use PORT manipulation. Right now I reached a point where you can play a note with a button and you can change pitch of the note with a pot. Again, thank you very much to all, especially Majenco and Telecommando for taking the time to help me! For future generations  I will paste the entire code here: #include <digitalWriteFast.h> //then you can use digitalWriteFast(pin,HIGH/LOW), //digitalReadFast(pin), pinMode(pin,INPUT/OUTPUT), //digitalWriteFast2(pin,HIGH/LOW), digitalReadFast2(pin), //pinMode2(pin,INPUT/OUTPUT)very much as you have used the built-in commands. //The object code will not only be faster, but actually smaller as well.
//----CLOCK OUTPUT ON PIN 3 const int freqOutputPin = 3; const int ocr2aval = 3; const int prescale = 1; const float period = 2.0 * prescale * (ocr2aval+1) / (F_CPU/1.0e6); const float freq = 1.0e6 / period; //---------
const int dataPins[] = {4,5,6,7,8,9,10,11}; const int bc1Pin=12; const int bdirPin=13; //-------
const int pitchPin=A0; float oldPitch=-1; int oldPitchDec=-1; const int playPin=A1;
void setup() { //---for the clock output pinMode(freqOutputPin, OUTPUT); Serial.begin(9600); TCCR2A = ((1 << WGM21) | (1 << COM2B0)); TCCR2B = (1 << CS20); TIMSK2 = 0; OCR2A = ocr2aval;
Serial.print("Period = "); Serial.print(period); Serial.println(" microseconds"); Serial.print("Frequency = "); Serial.print(freq); Serial.println(" Hz"); //---- pinMode (bc1Pin,OUTPUT); pinMode (bdirPin,OUTPUT); pinMode (pitchPin,INPUT); Serial.begin(9600); inactiveModeFun(); setDataOutFun(); resetICFun(); testSoundA(); }
void loop() { float pitch = analogRead(pitchPin); pitch=(pitch/1023)*15; int pitchDec=(pitch-int(pitch))*255; if (analogRead(playPin) < 16) { writeICFun(13,0); } delay(100); if (int(pitch)!=int(oldPitch)) { oldPitch=pitch; Serial.print("Course: "); Serial.println(int(pitch)); writeICFun(1,int(pitch)); writeICFun(3,int(pitch)); writeICFun(5,int(pitch)); } if (pitchDec-oldPitchDec<10 || pitchDec-oldPitchDec>-10){ oldPitchDec=pitchDec; //Serial.print("Fine: "); //Serial.println(pitchDec); writeICFun(0,int(pitchDec)); writeICFun(2,int(pitchDec)); writeICFun(4,int(pitchDec)); } }
void writeICFun(int reg,int valor) { //maneja valor integer, lo convierte y lo pasa a la otra
writeBusFun(reg); //buscar dir latchModeFun(); inactiveModeFun(); writeBusFun(valor); //darle varlor writeModeFun(); inactiveModeFun(); } void writeBusFun(int valor) { for (int x=0;x<8;x++) { digitalWriteFast2(dataPins[x],bitRead(valor,x)); } }
byte readICFun(int reg) { writeBusFun(reg); //buscar dir latchModeFun(); inactiveModeFun(); readModeFun(); byte valorByte=readBusFun(); //mira valores inactiveModeFun(); return valorByte;
} byte readBusFun() { setDataInFun(); byte valorByte=0; for (int x=0;x<8;x++) { bitWrite(valorByte,x,digitalRead(dataPins[x])); } setDataOutFun(); return valorByte; }
void inactiveModeFun(){ digitalWriteFast2(bdirPin,LOW); digitalWriteFast2(bc1Pin,LOW) } void readModeFun(){ digitalWriteFast2(bdirPin,LOW); digitalWriteFast2(bc1Pin,HIGH) } void writeModeFun(){ digitalWriteFast2(bdirPin,HIGH); digitalWriteFast2(bc1Pin,LOW) } void latchModeFun() { digitalWriteFast2(bdirPin,HIGH); digitalWriteFast2(bc1Pin,HIGH) } void setDataOutFun(){ for (int x=0;x<8;x++) { pinMode(dataPins[x],OUTPUT); } } void setDataInFun(){ for (int x=0;x<8;x++) { pinMode(dataPins[x],INPUT); } } void testSoundA(){ writeICFun(0,0); writeICFun(1,6); //delay(6); writeICFun(2,0); writeICFun(3,6); writeICFun(4,0); writeICFun(5,6); writeICFun(6,1); writeICFun(7,int(B11111000)); writeICFun(8,16); writeICFun(9,16); writeICFun(10,16); writeICFun(11,0); writeICFun(12,50); writeICFun(13,0); } void resetICFun(){ for (int x=0;x<6;x++){ writeICFun(x,0); } } There might be some variables named in spanish language but I changed that, so it's the minority.
|
|
|
|
|
70
|
Using Arduino / General Electronics / Re: How to use a 2-pin crystal for IC clock?
|
on: July 20, 2012, 02:32:58 am
|
Thanks a lot for that long and detailed reply, it was very helpful!!! Now I understand why were the readings like that, so let's suppose that the clock works. Your connections to the Arduino should be similar to Figure 11 in the data sheet, 8 data lines and 3 control. It's also possible to control the chip with only 2 control lines, see Section 2.3 Next, I would see if I could write to and read from a register. If you can't do that, there's probably something wrong either with your wiring or code. The connections between PSG and Arduino are like that, and I already tied BC2 to +5v, so I already use only 2 control lines. YOU KNOW WHAAAAAAT??? I tryed again with your test tone and it WORKS!!!I will paste entire and corrected code on this post: http://arduino.cc/forum/index.php?topic=114412
|
|
|
|
|
71
|
Using Arduino / General Electronics / Re: Help with the AY-3-8910 IC datasheet!
|
on: July 19, 2012, 05:54:56 pm
|
|
Hahaha, I'm glad you took responsibility for that! No problem, I'll try again replacing all those "1111" with "0000" on the register addresses and report back. I saw somewhere else that the high order bits were all "1" but maybe it was something else...
|
|
|
|
|
72
|
Using Arduino / General Electronics / Re: Help with the AY-3-8910 IC datasheet!
|
on: July 19, 2012, 01:03:36 pm
|
I know I am asking so many things, but please be patient with me, I am new to Arduino! I tried with a clock circuit and also with a code clock using PIN 3 of Arduino. I get no sound from any channel, could you please take a look at this code and tell me if I am in the right direction??? On the main loop, just to test for sound on Channel A I do this: void loop() { delay(3000); writeICFun(7,62); //Mixer: channel A only writeICFun(1,50); //Channel A course pitch writeICFun(8,15); //Volume A to max } To write a value to a register I use these functions: void writeICFun(int reg,int valor) { //address to R01 is 11110001. If reg=1, then we need to add: 11110000 -> 240(dec) reg=reg+240;
inactiveModeFun(); Serial.println("Write on Reg number: "); writeBusFun(reg); //sends address of register latchModeFun(); inactiveModeFun(); Serial.println("Value to write :"); writeBusFun(valor); //send value writeModeFun(); inactiveModeFun(); }
void writeBusFun(int value) { Serial.println(value,BIN); for (int x=0;x<8;x++) { digitalWrite(dataPins[x],bitRead(value,x)); } Serial.println("-FIN Write-"); } void inactiveModeFun(){ digitalWrite(bdirPin,0); digitalWrite(bc1Pin,0); } void readModeFun(){ digitalWrite(bdirPin,0); digitalWrite(bc1Pin,1); } void writeModeFun(){ digitalWrite(bdirPin,1); digitalWrite(bc1Pin,0); } void latchModeFun() { digitalWrite(bdirPin,1); digitalWrite(bc1Pin,1); } Thanks a lot!
|
|
|
|
|
73
|
Using Arduino / General Electronics / Re: How to use a 2-pin crystal for IC clock?
|
on: July 18, 2012, 10:13:15 pm
|
NEED HELP AGAIN! Ok, I did the clock circuit like the one on page 29 of the Ay-3-8910 datasheet: http://www.michael-george-hart.com/articles/computerscience/AY-3-8910_8912-Programmable_Sound_Generator.pdfDifference is that I used a 4mhz crystal, and PIN 13 (after the inverter) goes to the PSG (in order to get 1mhz) and PIN 1 goes to PIN 11 because I don't need it's 2mhz output, no other output. Also, I used a 330ohm R (instead of 300ohm) and 22pF capacitor (instead of 20pF) but that shouldn't be a problem, right? Now, I think it is not working, if I connect the output to an Arduino PIN and do a Serial.print(digitalRead(1)) the amount of 0's and 1's I get is not even, for instance I get: 00110001100111 and so on... Is there another way of testing if it works? I followed the write and read procedures as majenco told me on another post ( http://arduino.cc/forum/index.php/topic,114412.0.html) but it's not working right, and of course there is no sound coming from the channels. If it's useful I could paste some code to check if it's right. Help?? Thanksssssssss!
|
|
|
|
|
74
|
Using Arduino / General Electronics / Re: How to use a 2-pin crystal for IC clock?
|
on: July 18, 2012, 12:53:01 pm
|
|
Ok, that's some useful information... from what I see on the clock circuit in the AY-3-8910 datasheet, I should connect PIN 13 to the PSG to get 1mhz. I have a 4mhz crystal, so PIN 1 should get an output of 2mhz and PIN 13 an output of 1mhz in my case.
Can't wait the store gets open so I can buy what I need! I already have some coding to test a tone.
|
|
|
|
|
75
|
Using Arduino / General Electronics / Re: How to use a 2-pin crystal for IC clock?
|
on: July 17, 2012, 09:48:53 pm
|
|
Oh... I never saw there was a clock circuit in the Ay-3-8910 datasheet. Its in Section 4.2 (page 29)
What if I have a 4mhz crystal? The same values of R and C should work, right?
In my case, do I need to connect PIN 13 of the CD4013 to the ground? Because I don't need a clock on my microcomputer (Arduino)
Ok, tomorrow I'll try that!
Thanks, all!
|
|
|
|
|