Go Down

Topic: Strange behavior using TVout (Read 574 times) previous topic - next topic


First time posting, so please be patient...

I want to use the TVout library to display some data captured through an electret mic, and do an fft later.
After some troubleshooting, I found an "unused" array causes TVout not to display anything.
I'm using the UNO and the working code is below (displays some pixels dancing on the screen).
If I uncomment the wtf line, nothing ever gets to the tv (not even what I send on setup()!!!).

Any ideas will be greatly appreciated, I'm stuck here. The wtf array would be used as imaginary part for the fft or fix_fft function later on.

Code: [Select]

#include <TVout.h>
#include <fontALL.h>
#include <fix_fft.h>

TVout TV;
const int SCR_HEI = 96;
const int SCR_WID = 120;
const int size = 128;
char data[size];
char oldData[size];
char wtf[size];
char oldHistogram[size];
const int AN_PIN = 0;

void setup() {
  for (int i=0; i< size;i++) {
    oldHistogram[i] = 0;
    oldData[i] = 0;

void loop() {
  int i = 0;
  int j,k = 0;
  static long tt;
  int val;
  i = 0;
  while (i < size) {
    if (micros() > tt + 100) {
      val = analogRead(AN_PIN);
      data[i] = val / 4 - 128;
      if (i > 0 && i <= SCR_WID) {
        int valorYs1 = map(data[i-1], -128, 128, 0, SCR_HEI);
        int valorYs0 = map(data[i], -128, 128, 0, SCR_HEI);
        // clears line from last loop, draws new line and stores data for next loop
        TV.draw_line(i-1, oldData[i-1], i, oldData[i], 0);
        TV.draw_line(i-1, valorYs1, i, valorYs0, 1);
        oldData[i-1] = valorYs1;
//      wtf[i] = 0;
      tt = micros();


I would suspect that you run out of RAM.  I'm surprised it only fails when there is code to set the contents of wtf[].  Perhaps the compiler is smart enough that it doesn't allocate space for arrays that are never referenced.

Check the value returned by TVout.begin().  If you get 0 then you're fine.  If you get 4 it means there wasn't enough RAM available to allocate the screen buffer and you have to use a smaller width or height.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


Well I'll be damned! I didn't even realize TVout.begin returned something.

It is indeed returning 4, I guess I'll need some pruning on the code.

Any leads on how to estimate used memory? Or can we trust the size message after compiling (given all declared objects are used)?

Thanks a lot, this was really bugging me.


Sep 07, 2011, 01:07 pm Last Edit: Sep 07, 2011, 01:10 pm by wildbill Reason: 1
The message at the end of compilation gives the size of your executable - the amount of flash memory it will consume. Your issue is with how much RAM you're using and there is far less of it available - only 2K on an UNO for example. Search the forums for freemem - there are a number of implementations of functions to tell you how much RAM remains.

Edit: typo

Go Up