Hello,
I'd like to calculate the speed of rotation from a conveyor band with a photoelectric sensor (switching frequency=500Hz, response time=1ms).
This sensor is connected to C167 pin 3.6 (T3IN). The wheel from the band has 8 black colour and 8 white colours and we will get HIGH/LOW through a change from the colours.
First, I'd like to count HIGH-Signal in a certain time and then calculate the rotation speed.
Here is my code, the number always increases, although the band is off. What did I do wrong?
How should I write the code for the calculating?
WORD T3IMAGE; void main(){ T3CON = 0x0401; T3 = 0; T3IE = 1; T3IC = 0x61; T2CON = 0x000D; T2 = 0; T2IC = 0x44; T2R = T3R =1; IEN = 1; while(1){ TIMAGE = T2; set_cursor(20,5); printf("Counter = %5u", T2); } T3IE = 0; IEN = 0; T3R = 0; T2R = 0; }
Thank you very much and sorry for the miserable language
Best regards, Ciek
I have changed the code.
void main(){ T3CON = 0x0401; // 0 010|0 0 0|001 T3OTL=1 Teiler 8*2=16 T2CON = 0x000D; // 0 0 0 1|101 Counter, rising edge in T30TL T2IC = 0x44; // T2IE=1 ILVL=1 GLVL=0 T3 = 0; T2 = 0; T3R=1; IEN=1; while(1) { set_cursor(13,5); printf("Counter = %5u", T3); set_cursor(14,5); printf("Counter = %5u", T2); } }
I see now in Terminal, that T3 decrement from 65536 to 0. If I start T2 (T2R=1), T2 is always going up.
How should I program, so that I get the value from counter in 65536 tact?
Thank you so much.