Thanks for your response. However, I don't think you actually read my code nor the contents of my discussion in details... I based my code off of those the attached document. You might have been directly responsible for those documents, because I have seen your responses in similar discussions, which I very much appreciate the documents, they're plenty helpful.
Now, to simplify my question, well a part of my question, for now, I recreated a simpler case. I am only interested in getting one module to work, for now, more questions will ensue when I get this working. My code is presented below.
My questions are:
1) Why does the following code work for when updating FTMx_CnV for "x" equals 0 and only 0 but not for "x" equal 1 and 2? Just a reminder, I am only using one module for this simple case.
1a) Are there additional registers to set up for FTMx_CnV for "x" equals 1 and 2, or do they just need to be set up slightly differently?
1b) Does FTM0 module need to be enabled in order for this work although I am only interested in using FTM1?
2) I inspected the connections with an oscilloscope just to make I have set up all the ports correctly, which I have because I was able to, for some reason, update FTM1_MOD and observed the change in PWM period. So this questions is related to (1) why does it update FTM1_MOD but not FTM1_CnV?
3) How can I successfully update FTMx_CnV for "x" equals 1 and 2 when only one module is desired to be operational at the moment?
void InitPWM(void)
{
SIM_SCGC6 |= SIM_SCGC6_FTM1_MASK;
PORTA_PCR8 = PORT_PCR_MUX(3); // FTM1_CH0 which is A34
PORTA_PCR9 = PORT_PCR_MUX(3);
FTM1_CONF |= FTM_CONF_BDMMODE(4);
FTM1_FMS &= ~FTM_FMS_WPEN_MASK;
FTM1_MODE |= ( FTM_MODE_WPDIS_MASK | TM_MODE_FTMEN_MASK );
FTM1_MODE &= ~FTM_MODE_PWMSYNC_MASK;
FTM1_MOD = 1000;
FTM1_C0SC = ( FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK ); // Edge-aligned PWM
FTM1_C1SC = ( FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK );
FTM1_COMBINE |= FTM_COMBINE_DTEN1_MASK;
FTM1_COMBINE |= FTM_COMBINE_SYNCEN1_MASK;
FTM1_C0V = 10;
FTM1_C1V = 10;
FTM1_SYNC |= FTM_SYNC_CNTMIN_MASK;
FTM1_SYNCONF |= FTM_SYNCONF_CNTINC_MASK | FTM_SYNCONF_SYNCMODE_MASK;
FTM1_CNTIN = 0x00;
FTM1_SC = FTM_SC_CLKS(1);
FTM1_SC |= FTM_SC_TOIE_MASK;
}
main task:
while(1)
{
if ( brightness > 900 )
{
increase = true;
}
else if (brightness < 10 )
{
increase = false;
}
if(increase)
{
brightness++;
}
else
{
brightness--;
}
// FTM1_MOD = brightness; // this works
FTM1_C0V = brightness; // this doesn't work
FTM1_PWMLOAD |= FTM_PWMLOAD_LDOK_MASK;
time_delay_ms(50);
}
Thanks.