PDA

View Full Version : Problem with 16F648A



ngeronikolos
- 2nd March 2008, 13:59
Hello to everybody,

I use the 16F648A with internal OSC 4Mhz and I power it with 3VDC.The microcontroller does not work well.
I do not manage to find the fault of my code!!!!!
Have a look to the BEGIN MAIN LOOP (of my code).THE IF condition never get TRUE!!!!(That is the reason I add the blink led)
Please have a look and advice
----------------------------------------------------------------------
include "modedefs.bas"
@ DEVICE pic16F648A, INTRC_OSC_NOCLKOUT ' system clock options
@ DEVICE pic16F648A, WDT_ON ' watchdog timer
@ DEVICE pic16F648A, PWRT_ON ' power-on timer
@ DEVICE pic16F648A, MCLR_OFF ' master clear options (internal)
@ DEVICE pic16F648A, BOD_OFF ' brown-out detect
@ DEVICE pic16F648A, LVP_OFF ' low-voltage programming
@ DEVICE pic16F648A, CPD_OFF ' data memory code Protect
@ DEVICE pic16F648A, PROTECT_OFF ' program code protection


PAUSE 500
DEFINE OSC 4 'OSC MUST BE SET TO HS

'general purpose variables
i VAR BYTE
counter var byte

'pin definitions for comm w/ Laipec TRW-24G
RF_CE var PORTB.7
RF_CS var PORTB.6
RF_DR var PORTB.5
'channel 1
RF_CLK1 var PORTB.4
RF_DATA_Out var PORTB.3

' THIS IS THE ADDRESS FOR THE w/ Laipec TRW-24G
WhichAddress1 var byte 'Channel 1
WhichAddress2 var byte 'Channel 2

'constants for RF configuration modes
CONRFRX var byte
CONRFTX var byte

'indicates state of current RF configuration - TX is 0, RX is 1
RFCurrentState var bit

'hold data for RF message
RFDataArrayIN var byte[4]
RFDataArrayOUT var BYTE[4]

'hold data for RF configuration
RFConfigArray var Byte[16]

'variables for each received or sent message
msgFromID var word
msgToID var word
msgData1 var word
msgData2 var word
SerialData VAR BYTE
sendLED var PORTA.0
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''

bootup:
WhichAddress1 =$BA
WhichAddress2 =$BA
PORTA = %00000000;
TRISA = %00011110; ' 0 = Output, 1 = Input (A.1 is RxPC)

PORTB = %00000000;
;TRISB = %01101010; ' 0 = Output, 1 = Input (C.1 is RF_DATA_In, C.3 is RF_DR)


'intialize RF module configuration
'constants to define receive/transmit modes at 2402 Mhz frequency
CONRFTX = $04
RFCurrentState = CONRFTX

GOSUB initRFConfig

'************************BEGIN MAIN LOOP***********************'

start:

IF PORTA.1 = 1 THEN A
goto start

A: low RF_CS ' bring CS low before turning CE high - only one high at a time!
HIGH RF_CE ' bring CE high to bring RF into active mode
high sendLED
pause 1000
low sendLED
msgToID = 000 ' CHANGE THIS TP WHO SHOULD RECIEVE MESSAGE
msgFromID = 001
msgData1 = 001 ' DATA SENT
msgData2 = 000
gosub sendData ' goto the sendData function
pause 200
goto start


sendData : mpla
mpla
mpla

RETURN
END

duncan303
- 2nd March 2008, 16:02
Hi

I cannot see that you have set the PORTA register to digital, have a look at the sheet for the device you are using, there is also a paragrapgh in the manual that discusses this specific issue, worth taking a look for the future.



HtH

Duncan

ngeronikolos
- 2nd March 2008, 18:03
My friend duncan303,

Last I looked the 16F628 didn't have A/D Converters and as such doesn't have ADCON Registers - but you might want to correct me on that...


Nikos

duncan303
- 2nd March 2008, 18:19
hi Nikos,

Are you on 16F628 or on the 16F648A, they are not identical the datasheets are similar but differrent, one is the A series.

No matter, I have got the 16F62X sheet open at the moment, the register associated with the PortA is listed on page 34 table 5.2, therefore you will be looking at the CMCON register, if you look in the PBP manual on page 10 it will help explain better than I can right now, just off for my Sunday roast :)


Mmm hungry

Duncan

Archangel
- 2nd March 2008, 18:54
Hi ngeronikolos,
Please read this thread:
http://www.picbasic.co.uk/forum/showthread.php?t=543
You will see to use internal Osc does not require you to set osc to HS, are you doing that manualy in the programmers fuse?, I ask because of your comment in define statement?
Early in your code put CMCON = 7 to disable comparators.
your statement:


'constants for RF configuration modes
CONRFRX var byte
CONRFTX var byte

these are set as variables not constants.
Call to nonexistant sub directory: GOSUB initRFConfig
What is " mpla " ?
your
'constants to define receive/transmit modes at 2402 Mhz frequency
CONRFTX = $04
RFCurrentState = CONRFTX
If you had properly set those as constants, I do not think you could redefine them later in code, since you set them as VAR it works. to make them constants just rewrite as:
CONRFTX CON $04 'at the beginning, then you give the variable RFCurrentState it's value as above RFCurrentState = CONRFTX .
This is your statament:
@ DEVICE pic16F648A, INTRC_OSC_NOCLKOUT ' system clock options
Change to :
@ DEVICE pic16F648A, INTOSC_OSC_NOCLKOUT ' use internal OSC instead of R/C osc
If you installed everything in the default places when you setup PBP then you should find a file called P16F648A in this directory:C:\Program Files\Microchip\MPASM Suite , open it and look at the last several lines to see all available config fuses for this chip.

ngeronikolos
- 3rd March 2008, 23:09
I do not manage to fix my problem.I add the CMCON = 7 to disable comparators...BUT NOTHING.

But I found something strange and I would like your advice.
I use Microcode Studio Plus 3.0.0.5, compiler PBP 2.47, programmer Pickit2.
I compile my code and I program my pic with the .hex generated file.After that I read the pic and the .hex file is not the same(same changes).

LOOK the attaches file

falingtrea
- 4th March 2008, 15:45
Since you are running at 3V you may have an input level problem. If the IF PORTA.1 = 1 never goes true, the hardware just may not be seeing the proper level. If the input pin is "TTL" level then it needs a voltage level of (.25 VDD + 0.8V) for a '1'. If it is a schmitt trigger then it needs at least 0.8VDD for a '1'. Sometimes it is the simple stuff you need to check. :)

ngeronikolos
- 4th March 2008, 15:58
falingtrea,

The condition IF PORTA.1 = 1 never goes true either using 5vdc.I do not think that is level "1" the problem.

I will try to de-install the Microcode Studio Plus + pICKIT2 because it seems to me that the problem is from the pc.

If someboby have any other idea please advice

Regards
Nikos

falingtrea
- 4th March 2008, 17:08
I do not manage to fix my problem.I add the CMCON = 7 to disable comparators...BUT NOTHING.

But I found something strange and I would like your advice.
I use Microcode Studio Plus 3.0.0.5, compiler PBP 2.47, programmer Pickit2.
I compile my code and I program my pic with the .hex generated file.After that I read the pic and the .hex file is not the same(same changes).

LOOK the attaches file

If you look closely you will see that from address 0 to 2FF the data is the same. After that the difference between the files is that the read is showing all the blank locations of the total memory for the PIC device. This is normal.

falingtrea
- 4th March 2008, 17:15
falingtrea,

The condition IF PORTA.1 = 1 never goes true either using 5vdc.I do not think that is level "1" the problem.

I will try to de-install the Microcode Studio Plus + pICKIT2 because it seems to me that the problem is from the pc.

If someboby have any other idea please advice

Regards
Nikos

This may be a stupid question but have you verified that the signal on PortA.1 is working the way you expect it? What is driving this pin? If it is some kind of open-collector output, for instance, it needs a pullup in order to generate a '1'. I always check the hardware before I assume there is a problem with the software. I can't remember how many times I have put the wrong kind of signal on a pin and wondered why the software did not work.

ngeronikolos
- 6th March 2008, 23:08
Finally falingtrea show me the way to solve my <<stupid>> problem.
I add pull down resistor to PORTA.1...and that's it.ok

HARDWARE
Thanks boys
Nikos