Andrei917
Newbie level 5
Hi all, first I need to say I'm not good with microcontrollers, and I am building my second tesla coil, that is why I need a tachometer for the rotary spark gap RPM.
I started to look everywhere for a tachometer project, but I'm a bit limited on "money". I was trying to use PIC, because I can use pickit programmer at work. Then I found a code and schematics using PIC16F628A and 4 digit 7 segment display on the internet. Since I have this pic at work, my boss let me use it to test, if it works, then I will buy the parts.
I build the wiring as a lot of PIC projects:
RA0-3 ports control the digits
RB0-6 ports the segments
RA4 signal from IR transistor
RB7 turns on a IR led
MCRL goes to +5v
4MHz Crystal
Still the thing don't work. It shows 0000 when motor is off. If i turn on the motor, it show 8888, sometimes 8808, or some random segments that don't look like a number nor a letter.
I used this code from a blog. I found somewhere at this forum that a "break" comes after the case 0,1,2... lines, still it don't work.
I started to look everywhere for a tachometer project, but I'm a bit limited on "money". I was trying to use PIC, because I can use pickit programmer at work. Then I found a code and schematics using PIC16F628A and 4 digit 7 segment display on the internet. Since I have this pic at work, my boss let me use it to test, if it works, then I will buy the parts.
I build the wiring as a lot of PIC projects:
RA0-3 ports control the digits
RB0-6 ports the segments
RA4 signal from IR transistor
RB7 turns on a IR led
MCRL goes to +5v
4MHz Crystal
Still the thing don't work. It shows 0000 when motor is off. If i turn on the motor, it show 8888, sometimes 8808, or some random segments that don't look like a number nor a letter.
I used this code from a blog. I found somewhere at this forum that a "break" comes after the case 0,1,2... lines, still it don't work.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 unsigned short mask(unsigned short num) { switch (num) { case 0 : return 0x3F; case 1 : return 0x06; case 2 : return 0x5B; case 3 : return 0x4F; case 4 : return 0x66; case 5 : return 0x6D; case 6 : return 0x7D; case 7 : return 0x07; case 8 : return 0x7F; case 9 : return 0x6F; } //case end } sbit IR_Tx at RB7_bit; sbit DD0_Set at RA0_bit; sbit DD1_Set at RA1_bit; sbit DD2_Set at RA2_bit; sbit DD3_Set at RA3_bit; unsigned short i, DD0, DD1, DD2, DD3; unsigned int Sample1, Sample2, Sample3, RPM; void main() { TRISB = 0b00000000; // Set PORTB direction to be output TRISA = 0b00110000; // Set PORTA direction to be output PORTB = 0x00; // Turn OFF LEDs on PORTB CMCON = 7 ; // Disable comparators RPM = 0; // Initial Value of Counter OPTION_REG = 0b00111000; // TOCS=1 for Counter mode, PSA=1 for 1:1 IR_Tx = 0; // Turn OFF IR do { DD0 = RPM%10; DD0 = mask(DD0); DD1 = (RPM/10)%10; DD1 = mask(DD1); DD2 = (RPM/100)%10; DD2 = mask(DD2); DD3 = (RPM/1000); DD3 = mask(DD3); for (i = 0; i<=100; i++) { PORTB = DD0; DD0_Set = 1; DD1_Set = 0; DD2_Set = 0; DD3_Set = 0; delay_ms(5); PORTB = DD1; DD0_Set = 0; DD1_Set = 1; DD2_Set = 0; DD3_Set = 0; delay_ms(5); PORTB = DD2; DD0_Set = 0; DD1_Set = 0; DD2_Set = 1; DD3_Set = 0; delay_ms(5); PORTB = DD3; DD0_Set = 0; DD1_Set = 0; DD2_Set = 0; DD3_Set = 1; delay_ms(5); } DD3_Set = 0; // First Sample TMR0=0; IR_Tx = 1; Delay_ms(1000); // Delay 1 Sec IR_Tx = 0; Sample1 = TMR0*60; // Second Sample TMR0=0; IR_Tx = 1; Delay_ms(1000); // Delay 1 Sec IR_Tx = 0; Sample2 = TMR0*60; // Third Sample TMR0=0; IR_Tx = 1; Delay_ms(1000); // Delay 1 Sec IR_Tx = 0; Sample3 = TMR0*60; RPM = Sample1 + Sample2 + Sample3; RPM = RPM/3; } while(1); // endless loop }
Last edited by a moderator: