Hello FC,
I am not sure why you need to scale the ADC reading from 0 to 99. Since you are using an 8-bit result, why not simply divide this by 2 (shift right) to give 128 table entries for PWM value - a marginally larger table size. A divide by 4 would give 64 table entries.
I notice that you are handling the timer data as separate high and low bytes within the table. An alternative may be to have 16-bit entries in the pwm_table array variable.
A further comment - since you are using a substantial amount of inline assembly code within your ISR, I would tend to do the whole ISR using inline assembly, rather than mix.
See if the following code will work as intended.
volatile unsigned char duty_cycle;
const unsigned int pwm_table[128] = {0x0000,
.
.
0xFFFF};
__interrupt void isrVadc(void)
{
asm {
ldx ADCRL // clear COCO flag
lsrx // range 0-127
stx duty_cycle
lslx // word index for table
lda pwm_table,x
sta TPMC0VH
lda pwm_table+1,x
sta TPMC0VL
}
}
Regards,
Mac