![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hi, I am a newbie in this wonderful world of PIC programming and having some problems, so I'm hoping some one out there can help me out. I have written a program for the pic 16f876a microcontroller, this uses RA0 as an analogue input. I have tested it with MPLAB simulator and seems to work ok. Unfortunately MPLAB does not seem to support analogue input simulation, I could be wrong here. I have programmed the PIC with no problems encountered, but when I breadboard, it will not function. All the external components are in the correct locations, using 100k pull-up resistor on the MCLR pin and using a 10k pot for analogue input on pin 2 of the PIC. Also I would appreciate any good links, especially a simulator that allows analogue input. Hope someone can help me out there, before I pull out all my hair. Many thanks, Jeff The programme listing:- ;CHARGE CONTROLER PROCESSOR 16F876a INCLUDE <p16f876a.inc> __config _HS_OSC & _WDT_OFF & _PWRTE_ON ;CONSTANTS STATUS EQU 03H TRISA EQU 85H ;BANK 1 TRISB EQU 86H ;BANK 1 PORTA EQU 05H PORTB EQU 06H ADCON0 EQU 1Fh ADCON1 EQU 9FH ;BANK 1 ADRES EQU 1EH GODONE EQU 02H CARRY EQU 00H ;SET UP PORTS BSF STATUS,5 ;TO BANK 1 MOVLW H'ff' errorlevel -302 MOVWF TRISA ;PORT A INPUT MOVLW 00H MOVWF TRISB ;PORT B OUTPUT MOVLW B'00000100' MOVWF ADCON1 ;SET RA0,1,3 ANALOGUE INPUTS BCF STATUS,5 ;TO BANK 0 errorlevel +302 MOVLW B'01000001' MOVWF ADCON0 ;CLOCK 4Mz CLRF PORTA CLRF PORTB GOTO START ;24V ROUTINE ROUTINE24V BSF PORTB,1 ;24V LED ON BEGIN2 BSF ADCON0,2 WAIT2 BTFSC ADCON0,2 GOTO WAIT2 MOVF ADRES,W ;READ ANALOGUE VALUE SUBLW .179 ;3.5V Used for test purpose BTFSC STATUS,CARRY GOTO CHARGE24V BCF PORTB,0 ;BIT 0 CLEAR BCF PORTB,4 ;BIT 4 CLEAR BSF PORTB,1 ;BIT 1 SET BSF PORTB,5 ;BIT 5 SET GOTO BEGIN2 ;CHARGING ROUTINES CHARGE12V BSF PORTB,0 ;BAT TR ON BSF PORTB,4 ;BAT LED ON BCF PORTB,1 ;DUMP TR OFF BCF PORTB,5 ;DUMP LED OFF GOTO BEGIN CHARGE24V BSF PORTB,0 ;BAT TR ON BSF PORTB,4 ;BAT LED ON BCF PORTB,1 ;DUMP TR OFF BCF PORTB,5 ;DUMP LED OFF GOTO BEGIN2 START BTFSS PORTA,2 ;CHECK SW FOR 12V OR 24V GOTO ROUTINE24V BSF PORTB,0 ;TURN ON 12V LED BEGIN BSF ADCON0,2 ;TURN ON ANALOGUE INPUT WAIT BTFSC ADCON0,2 GOTO WAIT ;WAIT UNTILL ANALOGUE CONVERTION COMPLET MOVF ADRES,W SUBLW .128 ;2.5V. TEST, CHECK IF REQUIRES CHARGING BTFSC STATUS,CARRY GOTO CHARGE12V BCF PORTB,0 ;TURN OFF BAT TRANS BCF PORTB,4 ;BAT LED OFF BSF PORTB,1 ;DUMP TR ON BSF PORTB,5 ;DUMP LED ON GOTO BEGIN end | |
| |
| | (permalink) |
| Hi there, If your PIC won't function at all then that would suggest that there is something wrong with either you config of your circuit. Try checking you connections like you clock, Power ect, ect. Also have a look at your config for you PIC device. It may be something as simple as having LVP (Low Voltage Programming) Enabled. Good look. P.S As far as the A/D simulator I can't really help you there. I don't think Mplab does support A/D simulation but I may be wrong. | |
| |
| | (permalink) |
| What didn't work? Does the LEDs work when you change the 12/24V switch?
__________________ L.Chung | |
| |
| | (permalink) | ||
| Quote:
Quote:
The maximum recommended impedance for analog sources is 2.5 kΩ. This is required to meet the pin leakage specification. I wonder if the statement work for you. Good luck! | |||
| |
| | (permalink) | |
| Quote:
My PIC analogue tutorial explains about using the analogue inputs, in a somewhat simpler way than the datasheets do. | ||
| |
| | (permalink) |
| Hello, I am trying to paste a circuit diagram that is in abode reader format, any ideas how to do this. Someone has given me a link for a simulator that allows analogue input simulation, it seems to work well http://www.oshonsoft.com/pic.html Tried this sim with my prog. and seemed to work ok, so possibly it could be a hardware problem. Iwill get back to you when I have discovered how to get circuit diagram in here. "No rest for the wicked" as the expression goes. Many thanks for all your help. Regards, Jeff Last edited by JEFFxxx; 17th September 2006 at 01:45 AM. | |
| |
| | (permalink) | |
| Quote:
Thanks for your reply When I use the switch there is no change in any way. I have found a simulator that has analogue input simulation, and tested my prog. and it seems to work ok. So there is possibly a problem with my hardware or the breadboard i am using. I would paste my circuit here but it is in abode reader format and I do not know how to change the format. http://www.electro-tech-online.com/ This link is for the simulator I was given, hope you find it useful. Regards, Jeff | ||
| |
| | (permalink) | |
| Quote:
I would suggest to you not to troubleshoot a large trunk of the code but instead try initially to flash a LED and build gradually from that. This way, you can at least prove that all the hardware (PIC, PIC code downloading and clock oscillator) is working good, before moving on to the AD experiment.
__________________ L.Chung | ||
| |
| | (permalink) |
| starting at the beginning when running have you connected MCLR to Vdd ,+5V ? | |
| |
| | (permalink) |
| Hi, Sorry for delay in responding. I found two problems:- First the two caps. for the crystal were faulty, replaced and ran OK. Second I had set the wrong bit for turning on the 12V led and the 24V led, they should have been bit 2 and 3. It now works perfectly. Many thanks for all your input. Regards, Jeff | |
| |