Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

pic16f630

Status
Not open for further replies.
I wonder if someone can help me. I am using a 16f630 to generate a pwm signal for a small electric motor. I have 4 inputs for forward, reverse, halt and emergency stop. I originally used RA0, RA1, RA2 and RA3 as inputs and it worked fine. However I decided that it would be useful to keep RA3 (MCLR) free for future reprogramming, and also for a better distribution of pcb tracks it would be better to use RA0(pin13), RA1(pin12), RA4(pin3) and RA5(pin2). I made the changes to my program for the new inputs and the new interrupts in IOCA, and ---------it didn't work.

The problem appears to be with the use of RA5. When this appears in the MPLAB Stimulus worksheet for PIN/Register Actions, while RA0, RA1 and RA4 appear as Binary inputs, nothing is registered for RA5. The fault in the program appears in the pwm routine where I am using TMR0 to measure mark and space values, BUT TMR0 doesn't change:confused:

I can always go back to my original program, but I would like to know why I can't use RA5 as an input, and why does it affect TMR0.

Eddie Price
 
You need to make sure you have set _INTRC_OSC_NOCLKOUT in the Configuration Bits.
 
Hmm. Just had a look and I have set that. The complete config settings are _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
 
That's the only thing i can think of would make ra5 not work. Post your code.
 
Okay. I have turned the comparators OFF

movlw b'00000111' ;turn off comparators
movwf CMCON

The timer now works, but it still does not recognize RA5 as a digital input. The inputs to RA0, RA1 and RA4 are recognized, but not RA5.
 
Your shooting in the dark If you posted your code it would be easy to help.

1.You need the Ansel cleared
2. Cmcon set to off
3. The Trisa set right
4. make sure timer1 is not using it.
3.2.3.6 RA5/T1CKI/OSC1/CLKIN
Figure 3-5 shows the diagram for this pin. The RA5 pin
is configurable to function as one of the following:
• a general purpose I/O
• a TMR1 clock input
• a crystal/resonator connection
• a clock input
 
I will try to attach my code. I have been playing around with the configuration bits, but have still not found a way of making the simulator recognize RA5. It seems to remain as a zero irrespective of whether I include a '1'. The inputs are active low to satisfy the outputs from an RF600D decoder.

The only place where PORTA inputs appear are in 'getinput'. The condition of the input is transferred to 'button', and I think everything after this works. I suspect that the critical parts are the configuration and initialization.

I have renewed the attachment with changes as indicated in a later reply. There were a couple of errors, apart from the problem of RA5.
 

Attachments

  • decoder_quasar_Rx-2.asm
    10.4 KB · Views: 172
Last edited:
Tried your CONFIG suggestion and RA5 now acts as a digital input, but TMR0 has stopped working again. I think I am just going to use RA0, RA1, RA2 and RA4. I will keep RA3 as MCLR for possible in-circuit re-programming. These inputs seem to work so I will leave it at that.

Thanks everyone. I will keep an eye on this thread to see if anyone has any ideas as to why using RA5 causes so many problems.

Eddie Price
 
It's not Ra5 thats the problem your code stops when it hits main. I really have not had a lot of time to look at it.

Your configure __CONFIG H'0184'

Is not this __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT

This is __CONFIG H'3F84'
 
I tried H'3F84', but when I came to programming the chip with PICkit2 is showed config as H'184'.

Anyway I think it now works. I have replaced the code attachment in the previous entry. There was one typo error where I had movfw instead of movlw. It meant my prescaler wasn't included. I couldn't think why there was such a high frequency whine from the motor. The pwm was about 10kHz. It works much better at 100Hz.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top