| Author |
Message |
   
stubble
Just joined Username: stubble
Post Number: 1 Registered: 02-2010
Rating: N/A Votes: 0 (Vote!) | | Posted on Wednesday, 03 February, 2010 - 05:24 pm: |
|
Help I’m new to programming PIC’s and have been working on a washing machine project for some months, I cant seem to switch off the analogue to digital converter so I can use all of porta as digital inputs from some switches with external pull ups. I am using MPLAB IDE assembly. Can anyone see what I’m doing wrong?? Program always runs SW1 GOTO D90 and is not scanning any of the rest of porta!! Any help appreciated. ;MICROCONTROLLER CLOCK USING 32kHZ CRYSTAL AND 2 CAPACITORS AT 68P PIN9-10 INCLUDE "P16F872.INC" __CONFIG _CP_OFF & _LP_OSC & _WDT_OFF CBLOCK 0X20 ENDC ORG 0X0000 BCF STATUS, RP0 BCF STATUS, RP1 CLRF PORTA ;CLEAR ALL PORTS CLRF PORTB CLRF PORTC BSF STATUS, RP0 MOVLW B'00000110' ;PORTA DIGITAL MOVWF ADCON1 MOVLW B'11111111' ;PORTA INPUT MOVWF TRISA MOVLW B'00000000' ;PORTB OUTPUT MOVWF TRISB MOVLW B'00000000' ;PORTC OUTPUT MOVWF TRISC BCF STATUS,RP0 ;PROGRAM STARTS NOW SW1 BTFSS PORTA,0 ;SELECTS WHITES 90c GOTO D90 SW2 BTFSS PORTA,1 ;SELECTS COLOUR FAST 60c GOTO D60 SW3 BTFSS PORTA,2 ;SELECTS NON COLOUR 40c GOTO D40 SW4 BTFSS PORTA,3 ;SELECTS DELICATE 40c GOTO D30 SW5 BTFSS PORTA,4 ;SELECTS RINSE AND SPIN GOTO RN SW6 BTFSS PORTA,5 ;SELECTS SPIN GOTO SP GOTO SW1 ;RECHECK SWITCHES |
   
magnum4
Frequent Contributor Username: magnum4
Post Number: 818 Registered: 04-2005

Rating: N/A Votes: 0 (Vote!) | | Posted on Wednesday, 03 February, 2010 - 06:42 pm: |
|
Hi Stubble. Might be a stupid question, but have you got pull down resistors on all the inputs? HTH Regards, Jim
|
   
stubble
Just joined Username: stubble
Post Number: 2 Registered: 02-2010
Rating: N/A Votes: 0 (Vote!) | | Posted on Wednesday, 03 February, 2010 - 07:29 pm: |
|
Hi, this how I have connected the PIC to the switches. I have had some success with omitting porta,0 but would like that extra switch.
 |
   
magnum4
Frequent Contributor Username: magnum4
Post Number: 820 Registered: 04-2005

Rating: N/A Votes: 0 (Vote!) | | Posted on Wednesday, 03 February, 2010 - 07:42 pm: |
|
Can you check that RA0 is actually +5V? Without a switch press it should skip the D90 instruction? I noticed My mistake above, I did mean pull up I might be missing something silly but I would have thought it would work as it is? Regards, Jim
|
   
stubble
Just joined Username: stubble
Post Number: 3 Registered: 02-2010
Rating: N/A Votes: 0 (Vote!) | | Posted on Wednesday, 03 February, 2010 - 08:11 pm: |
|
The circuit seems fine, tested with meter 5v and when the button is pressed 0v so the pull up works , I have gone into Debugger, selected MAPLAB SIM and animated the program with Asynchronous Stimulus and the program dose the same thing, GOTO D90, also in the output window a message says:- SIM-N0001 Note: Asynchronous Stimulus Toggle RA0 fired. IOPORT-W0001: Pin(s) (0x01) on PORTA can not be stimulated due to being controlled by the A/D converter I can get it to work by:- MOVLW B'00001110' MOVWF ADCON1 ;PORTA,0 as analogue rest as digital And loosing the switch connected to porta0!! |
   
magnum4
Frequent Contributor Username: magnum4
Post Number: 822 Registered: 04-2005

Rating: N/A Votes: 0 (Vote!) | | Posted on Wednesday, 03 February, 2010 - 08:17 pm: |
|
I wonder If there is an errata for that part? I remember the Justification on the 874/877 part was wrong in the datasheet. looking at this parts data sheet it is the same as the 87x part. If your using the Icd you can simulate the actual circuit. What programmer are you using? Regards, Jim
|
   
magnum4
Frequent Contributor Username: magnum4
Post Number: 824 Registered: 04-2005

Rating: N/A Votes: 0 (Vote!) | | Posted on Wednesday, 03 February, 2010 - 09:28 pm: |
|
Ok I cant find any reference to a problem setting all analogue to digital. I wonder if the problem is in another part of your prog,?. If it were Me, I would stick a led and resistor on portb,0 to 5. Then change my GOTO statements with something like this. MOVLW B'00000001' MOVWF PORTB. FOR RA0 and MOVLW B'00000010' MOVWF PORTB for RA1 ETC. So SW1 would turn on Led 1 (RB0) SW2 would turn on led 2 (RB1) Etc. This would confirm if there is a problem with the setup or something else! HTH Regards, Jim
|
   
alec_t
Frequent Contributor Username: alec_t
Post Number: 172 Registered: 03-2009
Rating: N/A Votes: 0 (Vote!) | | Posted on Wednesday, 03 February, 2010 - 11:14 pm: |
|
Hi Stubble, Your ORG 0X0000 directive is starting your code at address 0. I'm not familiar with the 16F872, but many PICs have address 4 reserved for the interrupt vector. Try starting the code at address 5, by using ORG 0x0005. Regards, Alec |
   
zeitghost
Frequent Contributor Username: zeitghost
Post Number: 1432 Registered: 01-2006
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, 04 February, 2010 - 08:16 am: |
|
org 0x0000 goto start org 0x0005 start would do the trick. Are you using interrupts at all? |
   
alexr
Frequent Contributor Username: alexr
Post Number: 108 Registered: 02-2008
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, 04 February, 2010 - 10:15 am: |
|
Not that what goes into address 004 really matters unless you are using interrupts. The real question is why the program appears not to work. Your code to disable analogue functions looks fine to me which raises the question, are you sure that it a problem with disabling analogue functions on port A or could it be something more basic such as the clock not running. I ask because you seemed to say that you are using a 32KHz crystal and a couple of 68pF capacitors. Did you mean a 32KHz watch crystal? If you did then 68pF load capacitors are way too large. Somewhere between 6.8pF and 22pF would be nearer the mark. Also be aware that watch crystals come in two flavours 6pF load capacitance and 12pF load capacitance. Alex
|
   
alec_t
Frequent Contributor Username: alec_t
Post Number: 173 Registered: 03-2009
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, 04 February, 2010 - 11:49 am: |
|
Quote: "Program always runs SW1 GOTO D90" But where does your D90 routine return to? It would have to come back to label SW2 (and similarly the D60 routine would have to come back to label SW3, and so on) for the program to scan further switches. Perhaps make each routine a subroutine and use CALL rather than GOTO instructions? Regards, Alec |
   
magnum4
Frequent Contributor Username: magnum4
Post Number: 825 Registered: 04-2005

Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, 04 February, 2010 - 01:40 pm: |
|
I had noticed that Alex, thats why i suggested he try the simple switch check to see if he has a problem with setup. Org 0x00 should be fine unless as noticed above interupts are used. I agree Alec, we dont know whats happening, again the simple change I suggested above would tell us a lot  Regards, Jim
|
   
magnum4
Frequent Contributor Username: magnum4
Post Number: 826 Registered: 04-2005

Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, 04 February, 2010 - 02:31 pm: |
|
Have you got a second 872 to try? I have had some chips go faulty where one pin can not be changed? There was a discussion on this board about this a while ago? Regards, Jim
|
   
stubble
Just joined Username: stubble
Post Number: 4 Registered: 02-2010
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, 04 February, 2010 - 04:56 pm: |
|
Hello folks, thanks for the responses. I am using 2 x 6.8 PF ceramic capacitors with a 32.768KHZ watch crystal. And the clock works O.K. I have tried the code on a different 16F872 and had the same results. But where does your D90 routine return to? I never copied the rest of the code in, but it runs this:- ;Portb and portc connected to 2 seven segment displays D90 MOVLW B'11111000' ;LEFT DISPLAY P MOVWF PORTC MOVLW B'10000010' ;RIGHT DISPLAY 1 MOVWF PORTB GOTO D90 D60 MOVLW B'11111000' ;LEFT DISPLAY P MOVWF PORTC MOVLW B'11001101' ;RIGHT DISPLAR 2 MOVWF PORTB GOTO D60 D40 MOVLW B'11111000' ;LEFT DISPLAY P MOVWF PORTC MOVLW B'01100111' ;RIGHT DISPLAY 5 MOVWF PORTB GOTO D40 D30 MOVLW B'11111000' ;LEFT DISPLAY P MOVWF PORTC MOVLW B'00101100' ;RIGHT DISPLAY 7 MOVWF PORTB GOTO D30 RN MOVLW B'00011000' ;LIFT DISPLAY r MOVWF PORTC MOVLW B'10100001' ;RIGHT DISPLAY n MOVWF PORTB GOTO RN SP MOVLW B'01110110' ;LEFT DISPLAY S MOVWF PORTC MOVLW B'10001111' ;RIGHT DISPLAY P MOVWF PORTB GOTO SP END ;END OF PROGRAM I just don’t understand why I can not get it to work when I can if I set the A/D so only porta,0 is analogue and the rest digital and remove the D90 part of the code. Problem is I don’t no what I am doing, never done this before. Above is the first stage of a larger program I’m working on but still have the same problem. You can see the first stage of what I am trying to doing on the link to a video, again the only problem is porta,0!! http://www.youtube.com/watch?v=8TtQVSIbMkU Thanks. |
   
alec_t
Frequent Contributor Username: alec_t
Post Number: 174 Registered: 03-2009
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, 04 February, 2010 - 05:43 pm: |
|
I think I've spotted the problem:- D90 MOVLW B'11111000' ;LEFT DISPLAY P MOVWF PORTC MOVLW B'10000010' ;RIGHT DISPLAY 1 MOVWF PORTB GOTO D90 This bit of code keeps looping the program in the D90 routine, so the program never gets to test other inputs. 'GOTO D90' should be replaced by 'GOTO SW2'. The other 'GOTO D.....' instructions will also need changing to 'GOTO SW...' Regards, Alec |
   
alec_t
Frequent Contributor Username: alec_t
Post Number: 175 Registered: 03-2009
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, 04 February, 2010 - 05:51 pm: |
|
....and the 'GOTO RN' and 'GOTO SP' instructions in your latest post need changing to return the program to labels SW6 and SW1 respectively. Cheers, Alec |
   
kolbep
Regular Contributor Username: kolbep
Post Number: 46 Registered: 05-2009

Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, 04 February, 2010 - 06:39 pm: |
|
BTW, Here is the code I had to use to get all of PORTA working as digital IO (PIC18f2420) , else some of the pins would not work in mplab sim : ; ------------------------------------------- START MOVLW b'00001111' ; Set PORTA as Digital IO MOVWF ADCON1 ; MOVLW B'00000111' ; Set PORTA as Digital IO MOVWF CMCON ; CLRF TRISA ; PORTA IS OUTPUT CLRF LATA ; ------------------------------------------------------------------------------ ; END OF INIT. SECTION ; ------------------------------------------------------------------------------ (Message edited by kolbep on 04 February, 2010) |
   
stubble
Just joined Username: stubble
Post Number: 5 Registered: 02-2010
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, 04 February, 2010 - 07:51 pm: |
|
I’m so confused, OK can any one start me off again, this is what I want from this PIC PORTA all digital inputs PORTB all digital outputs PORTC 0, 1, 2, 3, digital inputs - 4, 5, 6, 7, digital outputs WORKING FILES THAT INCLUDE, COUNT and TMR0 2 x 6.8 PF ceramic capacitors with a 32.768KHZ watch crystal PRESCALER at 256 = GIVING TIMING PULSES OF 32 A SECOND FOR THE DELAYS. THERE ARE NO INTERRUPTS OR ANLOGUE TO DIGITAL CONVERSIONS. |
   
magnum4
Frequent Contributor Username: magnum4
Post Number: 827 Registered: 04-2005

Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, 04 February, 2010 - 10:25 pm: |
|
Hi Stubble. Can you try my suggestion above? Your ADCON1 setup looks correct for the 872 as far as I can see. If the program always goes to D90 then the pin is being read as CLEAR. If you leave the setup as it is and change your program as I suggest above then the results will help to point us in the direction.  Regards, Jim
|
   
violin
Regular Contributor Username: violin
Post Number: 31 Registered: 11-2008
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, 04 February, 2010 - 10:38 pm: |
|
;This is a basic code for your requirements ;no debounce rountine included. didn't have time ;***** ;MICROCONTROLLER CLOCK USING 32kHZ CRYSTAL AND 2 CAPACITORS AT 68P PIN9-10 ;***** List P = PIC16F872, R=DEC; #include <p16f872.inc> errorlevel -302 ;***** ;config bits needs to be confirmed ;to its datasheet __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _LP_OSC & _LVP_OFF & _CPD_OFF ;; __CONFIG _CP_OFF & _LP_OSC & _WDT_OFF ;***** cblock 0x20 ;GPR's if required endc ;***** org 0x00 goto START ;***** START bcf STATUS,RP0 bcf STATUS,RP1 clrf PORTA ;CLEAR ALL PORTS clrf PORTB clrf PORTC ;***** bsf STATUS,RP0 movlw B'11111111' ;PORTA INPUT movwf TRISA movlw B'00000000' ;PORTB OUTPUT movwf TRISB movlw B'00000000' ;PORTC OUTPUT movwf TRISC movlw 0x06 ;PORTA DIGITAL movwf ADCON1 bcf STATUS,RP0 ;PROGRAM STARTS NOW SW1 btfss PORTA,0 ;SELECTS WHITES 90c call D90 SW2 btfss PORTA,1 ;SELECTS COLOUR FAST 60c call D60 SW3 btfss PORTA,2 ;SELECTS NON COLOUR 40c call D40 SW4 btfss PORTA,3 ;SELECTS DELICATE 40c call D30 SW5 btfss PORTA,4 ;SELECTS RINSE AND SPIN call RN SW6 btfss PORTA,5 ;SELECTS SPIN call SP goto SW1 ;RECHECK SWITCHES ;****************SUBROUTINES*************** D90 call DELAY movlw B'11111000' ;LEFT DISPLAY P movwf PORTC movlw B'10000010' ;RIGHT DISPLAY 1 movwf PORTB btfsc PORTA,0 goto D90 return ;***** D60 call DELAY movlw B'11111000' ;LEFT DISPLAY P movwf PORTC movlw B'11001101' ;RIGHT DISPLAR 2 movwf PORTB btfsc PORTA,1 goto D60 return ;***** D40 call DELAY movlw B'11111000' ;LEFT DISPLAY P movwf PORTC movlw B'01100111' ;RIGHT DISPLAY 5 movwf PORTB btfsc PORTA,2 goto D40 return ;***** D30 call DELAY movlw B'11111000' ;LEFT DISPLAY P movwf PORTC movlw B'00101100' ;RIGHT DISPLAY 7 movwf PORTB btfsc PORTA,3 goto D30 return ;***** RN call DELAY movlw B'00011000' ;LIFT DISPLAY r movwf PORTC movlw B'10100001' ;RIGHT DISPLAY n movwf PORTB btfsc PORTA,4 goto RN return ;***** SP call DELAY movlw B'01110110' ;LEFT DISPLAY S movwf PORTC movlw B'10001111' ;RIGHT DISPLAY P movwf PORTB btfsc PORTA,5 goto SP return ;***** ; is to give time for the buttons ;in question to settle, debounce is better ;your clk speed is quite low anyway so not a big ;delay needed DELAY ;to write accordingly nop nop return ;***** end I see there is no code formatting within the Forums software. Sorry about this. Regards |
   
stubble
Member Username: stubble
Post Number: 6 Registered: 02-2010
Rating: N/A Votes: 0 (Vote!) | | Posted on Saturday, 06 February, 2010 - 11:48 am: |
|
Thanks to all, will try all the above and see if I can get it to work. |
   
magnum4
Frequent Contributor Username: magnum4
Post Number: 829 Registered: 04-2005

Rating: N/A Votes: 0 (Vote!) | | Posted on Saturday, 06 February, 2010 - 06:00 pm: |
|
Keep us Informed  Regards, Jim
|
   
stubble
Member Username: stubble
Post Number: 7 Registered: 02-2010
Rating: N/A Votes: 0 (Vote!) | | Posted on Sunday, 07 February, 2010 - 04:11 pm: |
|
I’m rechecking all the hardware, might take a week or two, will get back to you soon. Lee |
   
stubble
Member Username: stubble
Post Number: 8 Registered: 02-2010
Rating: N/A Votes: 0 (Vote!) | | Posted on Sunday, 14 February, 2010 - 03:08 pm: |
|
YES, Thanks to you all, it now works as I want. A combination of your code suggestions and hard ware pointers has sorted out this problem. I spent Saturday manufacturing a new PCB with the improved power supply including new caps and the new resistor values on the in-puts and out-puts. Thank you, thank you. Very much appreciated. Lee. |
   
magnum4
Frequent Contributor Username: magnum4
Post Number: 834 Registered: 04-2005

Rating: N/A Votes: 0 (Vote!) | | Posted on Tuesday, 16 February, 2010 - 10:10 pm: |
|
Thanks for letting us know Lee  Regards, Jim
|