fuzedmass
Junior Member level 2
Hello people, hope that every body is fine.
I m using PIC16f819 ADC module for a pretty simple task, that is if the analog voltage is greater that 0.6volts on RA1 it should start toggling the RB7 pin with a delay of 1second.
My hardware seems to be fine, on default all the outputs are HIGH. LED is connected to RB7 and it glows when RB7 equals to 0v. The analog voltage coming on pin RA1 ground is common with micro-controller's ground.
I m using internal oscillator of 8mhz, and I think I have done the right settings in CONFIGURATION BITS settings.
The problem is I think I have configured everything right in both the hardware and software, but it never works. If I simply do toggling of led using a delays it works. That means controller and oscillator etc settings are right.
Please HELP me
CODE:
HERE IS WHOLE CODE ... PLEASE HELP ME ...
THANKS
---------- Post added at 16:20 ---------- Previous post was at 16:19 ----------
I give 2.5Volts usually on RA1 but nothing happens, LED stays OFF (means getting 5volts all the time)
I m using PIC16f819 ADC module for a pretty simple task, that is if the analog voltage is greater that 0.6volts on RA1 it should start toggling the RB7 pin with a delay of 1second.
My hardware seems to be fine, on default all the outputs are HIGH. LED is connected to RB7 and it glows when RB7 equals to 0v. The analog voltage coming on pin RA1 ground is common with micro-controller's ground.
I m using internal oscillator of 8mhz, and I think I have done the right settings in CONFIGURATION BITS settings.
The problem is I think I have configured everything right in both the hardware and software, but it never works. If I simply do toggling of led using a delays it works. That means controller and oscillator etc settings are right.
Please HELP me
CODE:
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 #include <htc.h> /************Pin Assignment**********/ #define photo_probe_in RA2 #define photo_probe_neg_in RA3 #define mid_red_led RA4 //out #define relay_out3 RB0 //out #define relay_out1 RB1 //out #define relay_out2 RB2 //out #define low_green_led RB3 //out #define bottom_red_led RB4 //out #define mid_green_led RB5 //out #define top_green_led RB6 //out #define TOP_RED_LED RB7 //out #define push_button RA0 #define probe_pos_in RA1 /************Pin Assignment**********/ void my_configrations(void); void my_1sec(void); //1sec delay ftn unsigned int my_digi=0; void main(void) { my_configrations(); while(1) { my_highoutput(); } } void my_configrations(void) { //setting Internal OSC to run at 8mhz OSCCON = 0b01110100; //setting Internal OSC to run at 8mhz //configuring I/O TRISA0=1; //configure as INPUT TRISA1=1; //configure as INPUT TRISA2=1; //configure as INPUT TRISA3=1; //configure as INPUT TRISA4=0; //configure as OUTPUT TRISB0=0; //configure as OUTPUT TRISB1=0; //configure as OUTPUT TRISB2=0; //configure as OUTPUT TRISB3=0; //configure as OUTPUT TRISB4=0; //configure as OUTPUT TRISB5=0; //configure as OUTPUT TRISB6=0; //configure as OUTPUT TRISB7=0; //configure as OUTPUT RA4=1; //on default its HIGH RB0=1; //on default its HIGH RB1=1; //on default its HIGH RB2=1; //on default its HIGH RB3=1; //on default its HIGH RB4=1; //on default its HIGH RB5=1; //on default its HIGH RB6=1; //on default its HIGH RB7=1; //on default its HIGH //configuring I/O //ADC ADCS2=0; //AD clk div by 2 disabled ADFM=1; //right justified PCFG3=0;PCFG2=0;PCFG1=0;PCFG0=0; // AN0 to AN4 is analog and AVdd and AVss and refrence ADCS1=0;ADCS0=1; //FOSC/8 //ADIE=1; //enable ADC interrupt //GIE=1; //ADC } void my_highoutput(void) { unsigned int high_temp=0,x=0; //have to choose AN1 for this purpose CHS2=0;CHS1=0;CHS0=1; //select AN1 for(x=0;x<10;x++) { //average my_1msec(); GODONE=1;//start ADC module while(GODONE);//wait till it completes the conversion my_digi=0; //my_digi=ADRESL;//only using the lower register as the analog voltages are small my_digi=ADRESH; my_digi=my_digi<<8; //shift to left for 8 bit my_digi=my_digi|ADRESL; //10 bit result from ADC high_temp=high_temp+my_digi; } //average high_temp=high_temp/10; if(high_temp > 122) { TOP_RED_LED=!TOP_RED_LED; my_1sec(); } } void my_1msec(void) { unsigned int x=0,y=0; for(x=0;x<30;x++) { for(y=0;y<5;y++); } } void my_1sec(void) { unsigned int x=0,y=0; for(x=0;x<1773;x++) { for(y=0;y<102;y++); } }
HERE IS WHOLE CODE ... PLEASE HELP ME ...
THANKS
---------- Post added at 16:20 ---------- Previous post was at 16:19 ----------
I give 2.5Volts usually on RA1 but nothing happens, LED stays OFF (means getting 5volts all the time)
Last edited by a moderator: