elaborating on point 4 above:
I wrote the following code:
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
static unsigned char sample_number=0;
static unsigned char sine_table[64]={32,33,35,36,38,39,40,42,43,45,46,47,49,50,51,52,53,54,55,56,57,58,59,60,60,61,61,62,62,62,62,62,62,62,62,62,62,62,61,61,60,60,59,58,57,56,55,54,53,52,51,50,49,47,46,45,43,42,40,39,38,36,35,33};
interrupt void TimerTOF(void);
void main(void) {
TSC = 0x20; // Prescale 1, TIM disabled
TMOD = 0x0040; //64
TCH0 = 0x0020; // 50 percent duty
TSC0 = 0x1A; // Unbuffered PWM, clear O/P on compare
TSC_TSTOP = 0; // Enable TIM counter
EnableInterrupts;
while(1);
}
interrupt void TimerTOF (void)
{
TCH0=sine_table[sample_number];
sample_number++;
if (sample_number>=64){
sample_number=0;
}
}
Now:
a. I have used a 64 value sine table pre generated.
b. Running the code as it is causes nothing but a 50% duty cycle pwm.
c. calling the TimerTOF function just before the poll (while(1); ) and after EnableInterrupts causes a memory error: Link Error: L1102: Out of allocation space in segment RAM at address 0x140;
d. declaring the sine_table as const and then doing c causes the link error to disappear. however, the generated wave is not changing in duty cycle according to the sine lookup table. Infact, a contsant duty cycle of <10% is obtained.