void MCU_init_tpm1(void){ //Initialize timer TPM1 channel, assumes not touched since reset! TPM1SC_CLKSA = 1;//Select BUS clock TPM1SC_CLKSB = 0; TPM1SC_PS = T1PRESCALAR;//clock source divided by prescalar TPM1MOD = T1MODULUS;//set Counter modulus TPM1SC_CPWMS = 0; // not center aligned //TPM1, channel 1 TPM1C1SC_MS1B = 0; // MS0B:MS0A 00 == input capture TPM1C1SC_MS1A = 0; // TPM1C1SC_ELS1B = 0; // ELSnB:ELSnA 01 == rising edge capture only (10 falling, 11 either) TPM1C1SC_ELS1A = 1; // 0 = Select high as true, 1 = Select low as true TPM1C1SC_CH1IE = 1; TPM1C1SC = TPM1C1SC; TPM1SC_TOIE = 1; //enable timer overflow for counter //Verify!!! FIX ME!!! RPO}void update_encoder(unsigned char direction_verify_channel){ if(!direction_verify_channel) // { if(!++encoder[2]) if(!++encoder[1]) encoder[0]++; //"up" //encoder uses 3 bytes, shift the carry bit up/down } else { if(!encoder[2]--) if(!encoder[1]--) encoder[0]--; //"down" }}void interrupt 6 tpm1ch1_ChannelA_inputcapture(void){ unsigned char dummy = 0; dummy = TPM1SC; update_encoder(ChannelB); TPM1SC &= 0x7F; update_speed(); dummy = TPM1C1SC_CH1F; TPM1C1SC_CH1F = 0;}