View previous topic :: View next topic |
Author |
Message |
richi-d
Joined: 28 Aug 2007 Posts: 106
|
PIC24 ARRAY READ OUT doesn´t work |
Posted: Fri Jul 10, 2009 6:21 am |
|
|
Hi Following problem: DUMMY2 doesn´t get the value of PWM_INK_ZAEHLER[1]
Compiler Version is PCD 4.089
MPLAB 8.33
Any ideas?
MAIN
Code: | // V01 10.03.2009
#include <24FJ128GA106.h>
//#device adc=10
#include <string.h>
#include <math.h>
#include <Main_V01.h>
void main()
{
DUMMY32BIT_1 = 100000;
WEGDIFFERENZ = 500;
TASK_NR = 1;
for(;;)
{
PWM_INK_ZAEHLER[TASK_NR] = DUMMY32BIT_1 / WEGDIFFERENZ;
DUMMY2 = PWM_INK_ZAEHLER[TASK_NR];
}// for(;;)
}//Main() |
HEADER
Code: |
#FUSES FRC_PLL,NOPROTECT,NOIESO,NOJTAG,ICSP1,DEBUG
#use delay (clock=32000000)
unsigned int WEGDIFFERENZ;
long DUMMY32BIT_1;
long PWM_INK_ZAEHLER[11];
char TASK_NR;
long DUMMY2; |
Last edited by richi-d on Fri Jul 10, 2009 7:53 am; edited 1 time in total |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Fri Jul 10, 2009 7:11 am |
|
|
unsigned int WEGDIFFERENZ;
WEGDIFFERENZ is 8 bit
WEGDIFFERENZ = 500;
WEGDIFFERENZ now = 500 - 256 = 244
TASK_NR = 1;
C arrays have a zero based index so an array of
long PWM_INK_ZAEHLER[11];
Has indexex from 0 to 10 giing you 11 values.
PWM_INK_ZAEHLER[0];
to
PWM_INK_ZAEHLER[10];
The following will not fail but will cause problems as it is wrong!
PWM_INK_ZAEHLER[11]; |
|
|
richi-d
Joined: 28 Aug 2007 Posts: 106
|
Take care!! PIC24 |
Posted: Fri Jul 10, 2009 7:49 am |
|
|
HI,
at PCD and PIC24 "unsigned int" is a 16bit value...
and why is PWM_INK_ZAEHLER[11]; wrong? This is the declaration of the variable...
First read, then answer! |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Fri Jul 10, 2009 7:53 am |
|
|
So what are the values you are seeing and how are you viewing them ? Which debugger ? |
|
|
richi-d
Joined: 28 Aug 2007 Posts: 106
|
|
Posted: Fri Jul 10, 2009 7:54 am |
|
|
Not the values are the problem, this is the problem:
DUMMY2 = PWM_INK_ZAEHLER[TASK_NR];
The assembler code is wrong! Try it and look! |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Jul 10, 2009 9:07 am |
|
|
Your code seems to compile correctly in most recent PCD V4.093.
Code: | ... DUMMY2 = PWM_INK_ZAEHLER[TASK_NR];
002C8: MOV.B 834,W0L
002CA: CLR.B 1
002CC: SL W0,#2,W0
002CE: MOV #808,W4
002D0: ADD W0,W4,W0
002D2: MOV #836,W4
002D4: MOV [W0++],[W4++]
002D6: MOV [W0++],[W4++] |
There are however several unfixed PCD bugs, some have been reported about 8 months ago. |
|
|
richi-d
Joined: 28 Aug 2007 Posts: 106
|
|
Posted: Fri Jul 10, 2009 12:25 pm |
|
|
This is what 4.089 makes:
Code: | 002C4 BFC832 mov.b 0x0832,0x0000
002C6 EF6001 clr.b 0x0001
002C8 DD0042 sl 0x0000,#2,0x0000
002CA 208064 mov.w #0x806,0x0008
002CC 400004 add.w 0x0000,0x0008,0x0000
002CE 208344 mov.w #0x834,0x0008
002D0 780230 mov.w [0x0000++],0x0008
002D2 780230 mov.w [0x0000++],0x0008 |
Is there a chance to get a workarround? My update time is off.
How can I implement the ASM code?
This works:
Code: | #define NOP #asm NOP #endasm; |
but not the lines above... |
|
|
Ttelmah Guest
|
|
Posted: Fri Jul 10, 2009 2:56 pm |
|
|
The point that was being made about PWM_INK_ZAEHLER[11], was that your code, does not limit 'TASK_NR' at all, You will be pulling semi random values, from memory, once this gets past 10....
Best Wishes |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Jul 10, 2009 3:05 pm |
|
|
Curiously, I never saw the reported PCD bug. I found that the line of code is also compiled correctly by PCD V4.084. Possibly, it's a bug exclusive to V4.089. In this case, I won't see much sense in designing a workaround.
Generally, PCD assembler is working, but some minor syntax issues must be managed.
P.S.: I don't understand some discussions about wrong index ranges, because the example code uses a fixed index of 1. |
|
|
richi-d
Joined: 28 Aug 2007 Posts: 106
|
|
Posted: Sat Jul 11, 2009 3:51 am |
|
|
FvM and Ttelmah, what should I do now? I don´t understand what you want to tell me... |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Jul 11, 2009 7:46 am |
|
|
Try with any other PCD version than V4.089 (older or newer). |
|
|
|