Audio-Video Pattern Generator

Hi Guys.
Im in desperate need of assistance. I am fighting a battle with an Arduino Uno.

I am trying to build a device that reads an audio signal and uses its value to define the size of objects drawn on a TV via the TVout library.

Both the audio and video are working successfully separately. I have built an amplifier that offsets the entire audio signal into the 0-5V range of the analog read pins and I have successfully printed its value via “Serial.println(voltage);” and I can see its value read perfectly. There is also an LED that triggers when the audio signal clips at 5V. If I remove all code and upload the demo from the TVout library it plays on the TV perfectly so cabling is fine. But when it comes to trying to attempt both at the same time everything freezes.

It seems the second you try and send any data to TV the Arduino freezes the read of the audio.

Is there anything obviously wrong in the following code or do you think i have reached the capabilities of the Uno?

int incomingAudio;
boolean clipping = 0;//zero = not clipping, one = currently clipping
int clippingCounter = 50;
#include <TVout.h>
#include <fontALL.h>

TVout TV;

void setup(){
 Serial.begin(9600);
 TV.begin(PAL,120,96);
 TV.select_font(font6x8);
}
void loop(){
 incomingAudio = analogRead(A0);//read input from A0
 float voltage = incomingAudio * (5.0 / 1023.0);
 Serial.println(voltage);
 TV.println(voltage);

if (incomingAudio == 0 || incomingAudio == 1023){//if clipping
   digitalWrite(13,HIGH);//set pin 13 high
   clipping = 1;//currently clipping
   clippingCounter = 50;//reset clippingCounteR
 }
 if (clipping){
   if (clippingCounter>0){
     clippingCounter--;//decrement clipping counter
   }
   else{//if clippingCounter has counted all the way down
     clipping = 0;//no longer clipping
     digitalWrite(13,LOW);//turn of clipping indicator
   }
 }
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

incomingAudio = analogRead(A0);

Delaying for a period equal to one and a half TV lines probably isn't helping

You will have to pardon my ignorance. All I am trying to do in that code it to print the value of “voltage” as text on the TV to test if both the Analog read of the audio and the video generation can happen at the same time. I haven’t too much experience yet.

Timing on TVout is, I imagine, very tight. A TV scanline in PAL is 64us long, but analogRead takes around 100us.

Right I think I understand. Is it possible to modify the analogRead to 64us? Would that have much of an impact of on the amount of task I give the Uno?

I know this is an old topic, but just wanted to provide some feedback on this. I have written my own video generation code and I do not use the TVOut library myself to generate video, but I assume the below is valid for TVOut as well:

  • Avoid using serial communications together with video out. Both libraries have strict timing requirements.

  • AnalogRead sample time can be decreased. I used code from The Arduino Cookbook to do that (which I recommend wholeheartedly) but you can also find material on the internet, for example here,

  • The last point is a more difficult one. On my code, I just skip several lines of video so that time can be used to do other things like reading analog inputs and other processing. Because we still need to generate HSync for every line, I basically set the video to black and return from the video interrupt right after HSYNC is done. It frees up about 50us (or a few hundred cycles) per line to do other stuff. So, you need to find out if this trick is also valid in TVOut, that is, whether you can return from interrupt before end of line is reached.

Hope this helps.