Ok here is a little background.
What I am making is a system to multiplex 4 control voltages for analog sysnthesizers on an analog audio output from a computer soundcard.
there will be a custom waveform sent from the PC from a soniccore scope, or VST device with parts of the waveforms level modulated by various signals in the music software.
The original idea was so that control voltages which change slowly could be sent through AC couple d/a converters in the music equipment.
There is a negative pulse which triggers the interrupt via a compatator, (sort of like analog TV signal) then the arduino sends out 4 pulses in order which trigger sample and hold ICs (LF398AN)
those will extract the values on the audio waveform at the given time.
the input device is set up to never let the modulation levels go below the negative trigger value. this way i can still get (probably) 20 bits resolution out of a 24 bit d/a converter.
What i have done in this test is cause the trigger interrupt with a function generator at 1 KHZ, then the ISR contains sequential DelayMicrosecond delays which then trigger the sampling pins.
this would be fine and dandy but unlike the scope picture provided, the delays will be set up to cover most of the cycle, and i would like to use the arduinos analog inputs to get an approximation of what voltages each sample and hold are at. and display it on the LCD.
of course with the arduino spending most of its time counting microseconds there will be no time to measure the voltages.
I was wondering if i can make the interrupt reliably reset a counter which only sends interrupt of its own which have their own ISR to set the trigger pins. so the arduino will have plenty of cycles to do other things.
The thing is If the interrupt can reset a clock, can it reset it exactly the same each time? the timing will be important.
If not, i could either:
not bother with the LCD,
Use led VU meter ICs (expensive, and only 10 segments)
get another arduino
do the triggers with some ICs (which i dont want to do because it will not be adjustable without farting about with variable resistors and capacitors)
here is the test code.
#include <LCD4Bit.h>
#undef int
#include <stdio.h>
LCD4Bit lcd = LCD4Bit(2);
const int V1pin=0;
const int V2pin=1;
const int V3pin=2;
const int V4pin=3;
const int Trigpin1=3;
const int Trigpin2=4;
const int Trigpin3=5;
const int Trigpin4=6;
int pin13 = 0; //heartbeat, remove
int T1 = 100; //Actual microsecond delay in interrupt//
void setup(void){
lcd.init(); //initialize the LCD
pinMode(Trigpin1, OUTPUT);
pinMode(Trigpin2, OUTPUT);
pinMode(Trigpin3, OUTPUT);
pinMode(Trigpin4, OUTPUT);
attachInterrupt(0, blink, RISING);
lcd.clear();
}
void loop(void){
int V1;
int V2;
int V3;
int V4;
int val1;
int val2;
int val3;
int val4;
char buffer[64];
lcd.commandWrite(2); //bring the cursor to the starting position
val1 = analogRead(V1pin);
val2 = analogRead(V2pin);
val3 = analogRead(V3pin);
val4 = analogRead(V4pin);
V1 = (val1/10.24);
V2 = (val2/10.24);
V3 = (val3/10.24);
V4 = (val4/10.24);
sprintf(buffer,"V1: %d V2: %d ",V1,V2);
lcd.printIn(buffer);
lcd.commandWrite(128+0x40); // move to 1st char on 2nd line
sprintf(buffer,"V3: %d V4: %d ",V3,V4);
lcd.printIn(buffer); //send the string to the LCD
// set & invert pin 13 to flash LED
digitalWrite(13,pin13 ? HIGH : LOW);
pin13=!pin13; //heartbeat, remove //
delay(10);
}
void blink() //needs to be fixed. delays eat all the cycles
{
delayMicroseconds(T1);
digitalWrite(Trigpin1, HIGH);
delayMicroseconds(T1);
digitalWrite(Trigpin2, HIGH);
delayMicroseconds(T1);
digitalWrite(Trigpin3, HIGH);
delayMicroseconds(T1);
digitalWrite(Trigpin4, HIGH);
delayMicroseconds(T1);
digitalWrite(Trigpin1, LOW); //drop all to 0
digitalWrite(Trigpin2, LOW);
digitalWrite(Trigpin3, LOW);
digitalWrite(Trigpin4, LOW);
}
(notice high tech method of making the scope screen darker by putting thumb partly over the flash!)
the reason the scope input looks like a stair step is because i wanted to see the timing of the triggers so i put them through a resistor mixer, in the final version the trigger pins will go low in order as well.
If anyone understood what i was blathering about and possibly knows what i am trying to do please let me know