0

i have a problem converting assembly code for microchip pic into C language it is two parts first part is

movlw HIGH RevTable ; get MS byte of table

and the table is

RevTable
        retlw B’00000000’ ; invalid
        retlw B’00100001’ ; phase /6
        retlw B’00000110’ ; phase /4
        retlw B’00100100’ ; phase /5
        retlw B’00011000’ ; phase /2
        retlw B’00001001’ ; phase /1
        retlw B’00010010’ ; phase /3
        retlw B’00000000’ ; invalid

so what does that mean? i can not understand it

the second question is

incfsz ADC,w ; if ADC is 0xFF we’re at full speed - skip timer add

how it could be in the C thanks a lot

  • 2
    Can we C your `C` code so far – Hanky Panky Apr 14 '13 at 16:58
  • for the second question the assembly is Loop call ReadADC ; get the speed control from the ADC incfsz ADC,w ; if ADC is 0xFF we’re at full speed - skip timer add goto PWM ; add Timer0 to ADC for PWM movf DriveWord,w ; force on condition goto Drive ; continue and the C is void main (void) { char ADCReading; Initialize(); Commutate(); //determine present motor position ADCReading = ReadADC(); //get the speed control from the ADC if(ADCReading == ) } – Mohamed ZIEDAN Apr 14 '13 at 17:14
  • for the first question Commutate movlw SensorMask ; retain only the sensor bits andwf SensorPort,w ; get sensor data xorwf LastSensor,w ; test if motion sensed btfsc STATUS,Z ; zero if no change return ; no change - back to the PWM loop xorwf LastSensor,f ; replace last sensor data with current btfss DirectionBit ; test direction bit goto FwdCom ; bit is zero - do forward commutation ; reverse commutation movlw HIGH RevTable ; get MS byte of table movwf PCLATH ; prepare for computed GOTO movlw LOW RevTable ; get LS byte of table goto Com2 – Mohamed ZIEDAN Apr 14 '13 at 17:17
  • and the C is void Commutate (void) { char result; result = (SensorPort&SensorMask); if((result^LastSensor) != 0) { LastSensor = result; if (DirectionBit == 0) { } else { } } else { /*do nothing*/ } } – Mohamed ZIEDAN Apr 14 '13 at 17:18
  • The first part can be simply done using a switch/case statement. The second is simply adding one to ADC and checking if it reached 255 using an if/else statement. – The Byzantine Apr 15 '13 at 03:59

1 Answers1

4

Your code sample is insufficient so I can't tell you all about:

movlw HIGH RevTable ; get MS byte of table

This is only a part of computed table jump. Your asm code must look something like:

movlw HIGH RevTable
movwf PCLATH            ;set high byte RevTable address
movf  TableIndex, w
movwf PCL               ;set low byte RevTable address this is computed table jump
;The return value is in wreg so one from RevTable table depend of TableIndex value

In c something like:

char RevTable[] = {'0','6','4','5','2','1','3','0'};

char TableIndex = 1;
char ValueFromTable;

ValueFromTable = RevTable[TableIndex] ;

The second part of code:

incfsz ADC,w ; if ADC is 0xFF we’re at full speed - skip timer add

Here is missing the second asm instruction which is executed or not depend of ADC value, something like:

 if (ADC != 255) ...
GJ.
  • 10,810
  • 2
  • 45
  • 62