Hello, I'm trying to understand why a function created by Processor Expert stopped working.
#define byte unsigned char
byte ADC1_GetChanValue16(byte Channel,word *Value)
{
if (Channel >= 6) /* Is channel number greater than or equal to 6 */
return ERR_RANGE; /* If yes then error */
if (!OutFlg) /* Is output flag set? */
return ERR_NOTAVAIL; /* If no then error */
*Value = (word)((ADC1_OutV[Channel] << 6) / 200); /* Save measured values to the output buffer */
return ERR_OK; /* OK */
}
****** LIST FILE *******
Function: ADC1_GetChanValue16
Source : D:\CodeWarrior\SunTrack\Code\ADC1.C
Options : -BfaGapLimitBits0 -D_HCS12 -D__NO_FLOAT__ -Env"GENPATH=D:\CodeWarrior\SunTrack;D:\CodeWarrior\SunTrack\bin;D:\CodeWarrior\SunTrack\prm;D:\CodeWarrior\SunTrack\cmd;D:\CodeWarrior\SunTrack\Sources;C:\Programmi\Metrowerks\CodeWarrior CW12_V3.1\lib\HC12c\lib;C:\Programmi\Metrowerks\CodeWarrior CW12_V3.1\lib\HC12c\src;D:\CodeWarrior\SunTrack\Code;D:\CodeWarrior\SunTrack\doc;C:\Programmi\Metrowerks\CodeWarrior CW12_V3.1\lib\hc12c\include;C:\Programmi\Metrowerks\CodeWarrior CW12_V3.1\bin\Plugins\support\ProcessorExpert\PESL\HCS12;C:\Programmi\Metrowerks\CodeWarrior CW12_V3.1\bin\Plugins\support\ProcessorExpert;D:\CodeWarrior\SunTrack\src\common;D:\CodeWarrior\SunTrack\src\drivers\uart;D:\CodeWarrior\SunTrack\src\drivers\clock;C:\Programmi\Metrowerks\CodeWarrior CW12_V3.1\lib\HC12c\include" -Env"LIBPATH=C:\Programmi\Metrowerks\CodeWarrior CW12_V3.1\lib\HC12c\include" -EnvOBJPATH=D:\CodeWarrior\SunTrack\bin -EnvTEXTPATH=D:\CodeWarrior\SunTrack\bin -Lasm=%n.lst -Mb -ObjN=D:\CodeWarrior\SunTrack\SunTrack_Data\Lauterbach\ObjectCode\ADC1.C.o -WmsgSd1106 -WmsgSd1420 -WmsgSd4402 -WmsgSd5703
0000 3b PSHD
0001 3b PSHD
287: if (Channel >= 6) /* Is channel number greater than or equal to 6 */
0002 e687 LDAB 7,SP
0004 c106 CMPB #6
0006 2504 BCS *+6 ;abs = 000c
288: return ERR_RANGE; /* If yes then error */
0008 c602 LDAB #2
000a 202c BRA *+46 ;abs = 0038
289: if (!OutFlg) /* Is output flag set? */
000c b60000 LDAA OutFlg
000f 2604 BNE *+6 ;abs = 0015
290: return ERR_NOTAVAIL; /* If no then error */
0011 c609 LDAB #9
0013 2023 BRA *+37 ;abs = 0038
291: *Value = (word)((ADC1_OutV[Channel] << 6) / 200); /* Save measured values to the output buffer */
0015 87 CLRA
0016 59 ASLD
0017 59 ASLD
0018 b745 TFR D,X
001a ede20000 LDY ADC1_OutV:2,X
001e eee20000 LDX ADC1_OutV,X
0022 c606 LDAB #6
0024 160000 JSR _LSHL
0027 6e80 STX 0,SP
0029 1ae8c8 LEAX 200,Y
002c 34 PSHX
002d 35 PSHY
002e ee84 LDX 4,SP
0030 160000 JSR _LDIVU
0033 ee82 LDX 2,SP
0035 6c00 STD 0,X
292: return ERR_OK; /* OK */
0037 c7 CLRB
293: }
0038 1b84 LEAS 4,SP
003a 0a RTC
************************************
I use the function like this
unsigned int val = 0;
ADC1_GetChanValue16(4, &val);
Debuggin inside the function I get Channel always 0... and in val the corresponding of the calculation of ADC1_OutV[0]
Thinking coulb be a contant problem, I've used a local variable for passing the number 4, but it is the same.
Declaring a similar function thad does only the calculation in the same CODE and DATA SEG of the calling it works!!!
byte MyGetChanValue16(byte Channel,word *Value)
{
*Value = (word)((ADC1_OutV[Channel] << 6) / 200); /* Save measured values to the output buffer */
return ERR_OK; /* OK */
}
Personally I can't see the offset for the instruction LDY and LDX, but I'm not an Assembler developer.
001a ede20000 LDY ADC1_OutV:2,X
001e eee20000 LDX ADC1_OutV,X
I'm working with CW 3.1 fo HCS12 under WinXP SP2, but I've tried the CW 4.6 but the problem is still the same.
If can help, there is another strange thing it happen, to get the return value of same functions I have to declare the returning type. ie.
if((byte)ADC1_GetChanValue16(4, &val) != ERR_OK) { //code// }
otherwise I don't get the correct return