array access in C code

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
nils
Posts: 33
Joined: Fri Nov 02, 2007 11:03 am
Contact:

array access in C code

Post by nils »

Hello

I am using the AVR programmer with an Atmega32 and the LCD E-Block. Then I use the Custom Component to implement a lookup table called aSineWave inside the GetDefine dummies.
In the Custom Component function TestWave I try to access this array, but I do not get anywhere. I tried to print it out on the LCD, but it seems to be everytime 0 and am now out of options to get it running, so that I would like you to have a look at the Flowcode file and my edited Custom Component file.
thanks in advance

cheers,
nils

PS: I will use this later on to feed a DAC chip with the SPI, and found out that nothing changed at the SPI output :/ and sorry for posting it first in the ARM forum, was a bit confused yesterday because of this not so trivial problem.

edit: see next post for my files.
Last edited by nils on Wed Apr 23, 2008 9:57 am, edited 1 time in total.
Custom_Code.c help needed? -> http://tinyurl.com/2y2mzq
Flowchart high quality vector graphic output =>>http://tinyurl.com/6sx2sx

nils
Posts: 33
Joined: Fri Nov 02, 2007 11:03 am
Contact:

Re: array access in C code

Post by nils »

hi again

I just wrote a very small C program to see what was going on, because I couldn't get it running with the microcontroller. first I have to achknowledge, that I should have set the variables to both unsigned char to avoid any confusion with signed values. changing this, the output on my computer just looks fine, and I have no clue why this is not working on the LCD, because it seems as if every value of the array is zero, which it is definitely not.

now I attached my sample Flowcode program including the updated Custom Component code and the C program which tests the array output.
still I have no idea how to resolve this problem :/

cheers,
nils
Attachments
Archive.zip
(5.56 KiB) Downloaded 605 times
Custom_Code.c help needed? -> http://tinyurl.com/2y2mzq
Flowchart high quality vector graphic output =>>http://tinyurl.com/6sx2sx

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: array access in C code

Post by Benj »

Hello Nils

Are you simulating or running your program on the hardware? C code cannot be simulated from inside Flowcode.

nils
Posts: 33
Joined: Fri Nov 02, 2007 11:03 am
Contact:

Re: array access in C code

Post by nils »

yes, I already came across this pitfall when I began using C code ;) I am not simulating now and working with the actual hardware bits: AVR programmer and LCD E-Block.

I do have really now clue what is going on with arrays implemented in the Custom Component, so I tried to do the same thing without the controller but in pure C on the commandline. et voilΓ , it works on the commandline!!
what I tried next was putting the array inside my Custom Component function, but this had the same result.

so what I wanted to do was:
- going through the array step by step
- assigning to the tmp variable 128 + actual array value
- displaying tmp on the LCD
- delaying the for loop

and I expected to show something like this:
128 <255ms later> 129 <255ms later> 130 ... and so on
and I got
128 <255ms later> 128 <255ms later> 128 ...

which tells me, that the array values HAVE to be zero and I have no clue whatsoever what is going wrong.

hope this clears something up, if you have further questions, just ask. thanks for your help in advance

cheers,
nils
Custom_Code.c help needed? -> http://tinyurl.com/2y2mzq
Flowchart high quality vector graphic output =>>http://tinyurl.com/6sx2sx

nils
Posts: 33
Joined: Fri Nov 02, 2007 11:03 am
Contact:

Re: array access in C code

Post by nils »

ok, here it comes. after I took a look in some FAQ' about AVR gcc I found the answer I was looking for. I have no idea why it doesn't work the other way round.

Code: Select all


// this include is needed, to get access to the program functions
// and special keywords
#include <avr/pgmspace.h>

// table for sine wave of the first arc from 0 to pi/2
const unsigned char pgmSineWave[] PROGMEM = {0,
1,3,4,6,7,9,10,12,14,15,
17,18,20,21,23,24,26,28,29,31,
32,34,35,37,38,40,41,43,44,46,
47,48,50,51,53,54,56,57,58,60,
61,63,64,65,67,68,69,71,72,73,
74,76,77,78,79,81,82,83,84,85,
87,88,89,90,91,92,93,94,95,96,
97,98,99,100,101,102,103,104,105,106,
107,108,108,109,110,111,112,112,113,114,
115,115,116,117,117,118,118,119,119,120,
121,121,122,122,122,123,123,124,124,124,
125,125,125,126,126,126,126,127,127,127,
127,127,127,127,127,127,127};

void TestWave(){
/*Macro_TestWave_Start*/
	int i;
    unsigned char tmp;
    
	for(i=0;i<=127;i++){
   		tmp = pgm_read_byte(&pgmSineWave[i]);
  	 	FCD_LCDDisplay0_PrintNumber(tmp);
		delay_ms(255);
		FCD_LCDDisplay0_Cursor(0, 0);	
	}
/*Macro_TestWave_End*/
}
This code shows basically my test function to see output on the LCD, and now it works like a chamr when using the special functions and constructs. hope I could help. If any questions arise, don't hesitate.

cheers,
nils, who is now going to implement the sine wave generation into his DAC project :-D

references:
http://www.nongnu.org/avr-libc/user-manual/ and in german
http://www.mikrocontroller.net/articles ... 28Flash.29
Custom_Code.c help needed? -> http://tinyurl.com/2y2mzq
Flowchart high quality vector graphic output =>>http://tinyurl.com/6sx2sx

Post Reply