Okada
Banned
This is my PIC18F based Led VU Meter (16 channel bargraph). How can I improve the code ?
This is my code. Proteus simulation, mikroC PRO PIC project and Proteus Simulation video are attached. In simulation change the .wav to any 8 KHz wave file.
I have used multiplication and division operators in the equation. Can I replace them with shift operators in someway to get the same result ?
I have also done another version which uses LUT and it is simple but I wanted to do it differently.
- - - Updated - - -
What is the speed of 74HC595 SH_CP at 5V working voltage ? 25 MHz ?
If I use 32 MHz Oscillator for PIC then instrction clock will be fosc / 4 = 32 MHz / 4 = 8 MHz.
Instruction time will be 1 / 8 MHz = 0.125 us.
If 74HC595 can work at 25 MHz then SH_CP speed will be 0.04 us
So, can I clock 74HC595 with 0.125 us speed ?
I am making a shift register based VU Meter which needs 6 pins of a microcontroller.
This is my code. Proteus simulation, mikroC PRO PIC project and Proteus Simulation video are attached. In simulation change the .wav to any 8 KHz wave file.
I have used multiplication and division operators in the equation. Can I replace them with shift operators in someway to get the same result ?
I have also done another version which uses LUT and it is simple but I wanted to do it differently.
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 97 98 99 100 101 102 103 104 105 #define MAX_ADC_VALUE 1023 unsigned char number_of_bars = 16; unsigned long int raw_adc_value = 0, vu_meter_data = 0; char select_channel = 0; void Interrupt() { if((ADIE_bit) && (ADIF_bit)) { //read raw adc value raw_adc_value = (unsigned int)ADRESH << 8 | ADRESL; //convert raw adc value to bargraph data //slow method vu_meter_data = ((2 << ((raw_adc_value * number_of_bars) / MAX_ADC_VALUE)) - 1); if(select_channel == 0) { CHS0_bit = 0; CHS1_bit = 1; CHS2_bit = 1; CHS3_bit = 0; CHS4_bit = 0; LATA = vu_meter_data; LATB = vu_meter_data >> 8; } else if(select_channel == 1) { CHS0_bit = 1; CHS1_bit = 0; CHS2_bit = 1; CHS3_bit = 0; CHS4_bit = 0; LATC = vu_meter_data; LATD = vu_meter_data >> 8; } if(++select_channel > 1)select_channel = 0; ADIF_bit = 0; GO_DONE_bit = 1; } } void main() { asm clrwdt OSCCON = 0x67; OSCCON2 = 0x83; OSCTUNE = 0x00; CM1CON0 = 0x00; CM2CON0 = 0x00; SLRCON = 0x00; ANSELA = 0x00; ANSELB = 0x00; ANSELC = 0x00; ANSELD = 0x00; ANSELE = 0x03; ADCON1 = 0x80; ADCON2 = 0b10110110; TRISA = 0x00; TRISB = 0x00; TRISC = 0x00; TRISD = 0x00; TRISE = 0x03; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; PORTE = 0x00; LATA = 0x00; LATB = 0x00; LATC = 0x00; LATD = 0x00; LATE = 0x00; Delay_ms(100); ADIE_bit = 1; PEIE_bit = 1; GIE_bit = 1; CHS0_bit = 1; CHS1_bit = 0; CHS2_bit = 1; CHS3_bit = 0; CHS4_bit = 0; ADON_bit = 1; GO_DONE_bit = 1; while(1) { asm clrwdt LATE2_bit = ~LATE2_bit; Delay_ms(500); } }
- - - Updated - - -
What is the speed of 74HC595 SH_CP at 5V working voltage ? 25 MHz ?
If I use 32 MHz Oscillator for PIC then instrction clock will be fosc / 4 = 32 MHz / 4 = 8 MHz.
Instruction time will be 1 / 8 MHz = 0.125 us.
If 74HC595 can work at 25 MHz then SH_CP speed will be 0.04 us
So, can I clock 74HC595 with 0.125 us speed ?
I am making a shift register based VU Meter which needs 6 pins of a microcontroller.
Attachments
Last edited: