You are on page 1of 2

#include <main_slave.h> #byte CAP1BUFH = 0xF69 #byte CAP1BUFL = 0xF68 #byte CAP1CON = 0xF63 #bit #bit CAP1REN = CAP1CON.

6 IC1IF = PIR3.1 #byte PIR3 = 0xFA4 float cte_velocity_rps = 0, cte_velocity_rpm=0; int16 ad=0, count=0; int32 INSTRUCTION_CYCLE = 5000000; int16 ENCODER_PPR = 1200; float RPM_CONSTANT_QEI = 0; #int_IC1 /* Velocity capture interrupt */ void IC1_isr() { count=qei_get_count(QEI_GET_VELOCITY_COUNT); ad=get_timer5(); //! //! RPM_CONSTANT_QEI =cte_velocity_rps/ad ; RPM_CONSTANT_QEI =cte_velocity_rpm/ad ; RPM_CONSTANT_QEI = 1953.125/count; in AN899 and I can't read correctly the velocity // RPM=((Operating Frequency/4) / (PPR x Velocity Update Rate x Pulse Reduction Ratio x Timer5 Prescale x VELR<H:L>)) x 60 set_timer5(0); qei_set_count(0); } void main() { /*setup QEI*/ setup_qei(QEI_MODE_X4_RESET_ON_MATCH | QEI_VELOCITY_MODE_ENABLED | QEI_VELOCITY_PULSE_DIV_4 ,QEI_FILTER_ENABLE_QEB | QEI_FILTER_ENABLE_QEA, 2400); //! 2249); SETUP_TIMER_5(T5_INTERNAL | T5_DIV_BY_8); //! enable_interrupts(INT_TIMER5); enable_interrupts(INT_IC1); enable_interrupts(GLOBAL); cte_velocity_rps = 625000/ENCODER_PPR; Prescale x PPR) cte_velocity_rpm = cte_velocity_rps*60; while(true) { //cte_rps = (Operating Frequency/4) / (Timer5 setup_qei(QEI_MODE_X4_RESET_ON_MATCH, QEI_FILTER_ENABLE_QEB | QEI_FILTER_ENABLE_QEA, //In RPS revolutions per second, This //In RPM revolutions per minute, This //this value obtain of the equation 5 works fine except when the rotor is stopped. works fine except when the rotor is stopped.

output_toggle(LED); } } /*End to while(true)*/

/*End to main(void)*/

#include <18F4431.h> #device adc=10 #FUSES NOWDT #FUSES WDT128 #FUSES HS #FUSES NOBROWNOUT #FUSES NOLVP I/O #use delay(clock=20M) #define LED PIN_C0 #define DELAY 10 //No Watch Dog Timer //Watch Dog Timer uses 1:128 Postscale //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD) //No brownout reset //No low voltage prgming, B3(PIC16) or B5(PIC18) used for

You might also like