PDA

View Full Version : Could I have some advice on Which Pic Please?



karenhornby
- 15th May 2008, 13:35
Sorry to be a right pain in people's butts,
I had many problems when i first started working with PIC's and you kind people helped me tremendously thanks :)
However now I've done all the code and got everything working, I've realised I'm using way too big of a PIC 16F877A with too much wastage on it

What I need to know is :
Whats the best pic that will do the following:
compatible with a DS18B20 for temperature measurement
4 input pins (simple high or low inputs)
4 output pins (simple high or low outputs through transistor switch to operate relay)
6 Pins for an LCD (4 bit mode)
gonna be working with an 8Mhz resonator because no crucial timings involved.
NO critical measurments being made, just switching outputs depending on input selections
Will be be programmed with an ICD2

If anyone has any ideas on what PIC would be best to use so hardly any pins are wasted (as small a pic as possible) could they let me know please
Also and this is a very big hope in my part :)
Does anyone know the defines to use with PBP and ICD2 for whatever PIC chip they are suggesting?

It's not important I can always just use the 16F877A I've got working, but this way not only do I make the chip smaller and less wastage, but I learn the differences between programming the two

OH and also what would be exreeeeemely hand would be the config needed to set the ports to straight inputs and or outputs, I can never work that one out

Always hopeful :)
Karen

skimask
- 15th May 2008, 13:47
Whats the best pic that will do the following:
compatible with a DS18B20 for temperature measurement
It's not the PIC that fullfills the requirements for being compatible with the DS18B20...it's the keyboard operator.


4 input pins (simple high or low inputs)
4 output pins (simple high or low outputs through transistor switch to operate relay)
6 Pins for an LCD (4 bit mode)
gonna be working with an 8Mhz resonator because no crucial timings involved.
http://www.microchip.com/ParamChartSearch/chart.aspx?branchID=1002&mid=10&lang=en&pageId=74

A 16F628A handles everything but the 8Mhz (has 4Mhz internal)
Once you need an 8Mhz internal and small, as in 18 pin package,
http://www.microchip.com/ParamChartSearch/chart.aspx?branchID=1004&mid=10&lang=en&pageId=74
2 pins power/ground, internal 8Mhz, 14 I/O + a pin for the DS18B20...
18F1220/1230/1320/1330...
No pins wasted...small package...

It's all in the parametric search pages at www.microchip.com

Ron Marcus
- 15th May 2008, 14:18
How much program/RAM space do you need?

Acetronics2
- 15th May 2008, 17:07
Hi, Karen

with the external Xtal or reso ... 16F628/648 will be unbeatable !!!
with internal 8Mhz clock ... 16F88 or 16F819 ...

18F1320 ... I had small problems with mine ( no more than 20 reprogrammings available , EEPROM single location programming ... FALSE !!! Works well ONLY with more than two writings ... )

searchtool here also:

http://melabs.picbasic.com/Scripts/perl/picsearch.pl

Alain

skimask
- 15th May 2008, 17:16
18F1320 ... I had small problems with mine ( no more than 20 reprogrammings available , EEPROM single location programming ... FALSE !!! Works well ONLY with more than two writings ... )
Had problems with my 18F1320's also using a Warp13a awhile back. Had to add an extra .1uf cap across Vdd/Vss, worked like a champ. Have been using PICKIT2 to do them the same way. Haven't tried it without the extra .1uf cap's though. Will do over this weekend and let you know.

Acetronics2
- 15th May 2008, 18:06
Hi, Ski

I've tried Picstart, ICD2, PicFlash and a programmer from one of our Magazines ( a serious one ! Lol ! ) ...

Always the same answer ... only erasing seems to work.

a second chip had refused Picstart programming for a moment ... and with the 8.0 MPLAB release, It miraculously came back to life ...
I didn't insist further and "locked" it firmly on a PCB !!!

Capacitor and/or 1K have been tried with no appearing result ...

Now, I just program them from blank and send the PCB assembled ...

µChip has been unable to tell me something about that ... and the error sheet didn't show anything suspect ...
The memory issue needed to use the Brownout ... very,very bad idea aboard something flying !!!

Alain

Dave
- 15th May 2008, 18:55
karenhornby, I would suggest using an 18F2620 as there are enough pins to do what you want as well as 2 CCP modules a voltage reference, comparator and you can run it at 40Mhz. if necessary. I have used these parts for many products over the last year and 1/2 and have had great success. If you are planning on laying out a pc board it will give you some extra pins to use in the future... It also has 4 timers and enhanced capture/compare for use with an H bridge later on if needed...

Dave Purola,
N8NTA

karenhornby
- 15th May 2008, 21:30
Thanks guys :)
All pretty helpful, and I never knew abt the reference page to look them up.
The program I've written is 8k (the hex file is) and the reason I havent even considered the 18 series is i was as few pins as possible and dont need any complicated maths functions or add ons. It's going to be a simple switching circuit depending on what inputs are high will then determine what outputs go high and whats displayed oin the LCD display, it's that simple
I actually never considered an internal reference it would cut component count down using internal too thanks :)
The only problem stopping me using the 16F628A as suggested is the program size, i could add eeprom i guess but it's simpler to use a different pic than use more components.
My idea is to make the project as small and compact as possible but still using discreet components and NOT smd's.

Looks like it may have to be the 16F877A
Thanks Everyone :)
and Hi Dave, de Karen M3ZZZ

skimask
- 16th May 2008, 01:05
The only problem stopping me using the 16F628A as suggested is the program size, i could add eeprom i guess but it's simpler to use a different pic than use more components.
You know what else might be even easier would be to post the code and see if any of us could possibly help you optimize it a bit more and make it take up less code space :)

karenhornby
- 16th May 2008, 09:28
You know what else might be even easier would be to post the code and see if any of us could possibly help you optimize it a bit more and make it take up less code space :)
Sorry didn't do it b4 as I didn't want to ask for too much help.
JUST changed the code to get rid up unneeded pins, i.e led o/p's that wont be on the final version it will only use the lcd
What I'd like to do more neatly is have it so if PORTD.1 is pressed twice within the space of 2 seconds the program jumps to STOP1
If PORTD.1 is ONLY pressed once then it jumps to PURGING:
I'm sure there is a simpler way to do it than I've used.

Oh Acetronics thanks :) I've actually deleted quite a few lines of code and actually have no idea what size it assembles to at the moment as the computer I'm using at the moment doesn't have a complier on it
BUT when I compiled the code that you saw, the hex file was 8K (7.28K to be exact)
Maybe I did things wrong, I dont know i'm still extremely new to this, I was using the Mikroe easypic5 when i designed the circuit, now I've got rid of that and am going to make up a circuit board with just the parts needed and program it direct using the ICD2 (hopefully :) )


'************************************************* ***************
'* Name : Oil Control.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2008 [KarenH] *
'* : All Rights Reserved *
'* Date : 06/05/2008 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
Define LOADER_USED 1

@ DEVICE pic16F877a,HS_OSC,WDT_OFF,LVP_OFF
' Define various stuff
DEFINE OSC 8
DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus .7
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 4 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 5 ' Set LCD Enable bit i.e, PORTE.4
DEFINE LCD_BITS 4 ' Set LCD bus size ot 4 bit Upper Nibble (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD to 4 Lines
DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50 ' Set data delay time in us



' Allocate variables
command var byte ' Storage for command
i var byte ' Storage for loop counter
temp var word ' Storage for temperature
DQ var PORTA.5 ' Alias DS1820 data pin
DQ_DIR var TRISA.5 ' Alias DS1820 data direction pin


ADCON1 = 7 ' Set PORTA and PORTE to digital

Pause 500 ' Wait for LCD to start
Lcdout $FE,1," All Circuits", $FE,$C0, " Funtioning OK " ' Display sign-on message
Pause 3000 'Wait 3 seconds going any further



' Mainloop to read the temperature and display on LCD

mainloop:

Gosub init1820 ' Init the DS1820

command = $cc ' Issue Skip ROM command
Gosub write1820

command = $44 ' Start temperature conversion
Gosub write1820

Pause 500 ' Wait 0.5 seconds for conversion to complete

Gosub init1820 ' Do another init

command = $cc ' Issue Skip ROM command
Gosub write1820

command = $be ' Read the temperature
Gosub write1820
Gosub read1820

' Display the decimal temperature

IF PORTC.0 = 0 AND PORTC.3 = 0 then lcdout $FE,1," Diesel", $FE,$C0,"Outside ", $fe, $C9, dec (temp >> 1), ".", dec (temp.0 * 5), $DF, "C": LOW PORTE.0: LOW PORTE.1
IF PORTC.0 = 1 AND PORTC.3 = 0 then gosub Tempcheck
IF PORTC.0 = 0 AND PORTC.3 = 1 then gosub Tempcheck
If PORTC.0 = 1 AND PORTC.3 = 1 then gosub Oil
IF PORTD.1 = 1 Then GOSUB purging


Goto mainloop ' Do it forever

Stop1:

LOW PORTE.0
LOW PORTE.1
LCDOUT $FE,1," MANUAL",$FE,$C0," Diesel OVERRIDE"
while PORTD.1=0 'OVERRIDE COMMAND to MANUALLY switch back to DIESEL i.e. if veg oil runs out
wend
pause 1000 'so a very quick button press is NOT recognised and the program stays paused
Goto Tempcheck

OIL:
LCDOUT $FE,1," Veg-Oil", $FE,$C0,"Outside", $fe, $C9, dec (temp >> 1), ".", dec (temp.0 * 5), $DF, "C"
HIGH PORTE.0 'Diesel Solenoid
HIGH PORTE.1 'OIL Solenoid
return



Tempcheck:
lcdout $FE,1," TEMP LOW", $FE,$C0,"Still on DIESEL"
LOW PORTE.0: LOW PORTE.1
return

Purging:

LCDOUT $FE,1," PURGING Please",$FE,$C0," WAIT"
HIGH PORTE.0 'Diesel Solenoid
LOW PORTE.1 'Oil Solenoid
Pause 60000 'set delay of purge here 60 seconds
gosub Stop1

Goto mainloop


' Initialize DS1820 and check for presence
init1820:
Low DQ ' Set the data pin low to init
Pauseus 500 ' Wait > 500us
DQ_DIR = 1 ' Release data pin (set to input for high)

Pauseus 100 ' Wait > 100us
If DQ = 1 Then
Lcdout $fe, 1, "DS1820 not present"
Pause 500
Goto mainloop ' Try again
Endif
Pauseus 400 ' Wait for end of presence pulse
Return


' Write "command" byte to the DS1820
write1820:
For i = 1 to 8 ' 8 bits to a byte
If command.0 = 0 Then
Gosub write0 ' Write a 0 bit
Else
Gosub write1 ' Write a 1 bit
Endif
command = command >> 1 ' Shift to next bit
Next i
Return

' Write a 0 bit to the DS1820
write0:
Low DQ
Pauseus 60 ' Low for > 60us for 0
DQ_DIR = 1 ' Release data pin (set to input for high)
Return

' Write a 1 bit to the DS1820
write1:
Low DQ ' Low for < 15us for 1
@ nop ' Delay 1us at 4MHz
DQ_DIR = 1 ' Release data pin (set to input for high)
Pauseus 60 ' Use up rest of time slot
Return


' Read temperature from the DS1820
read1820:
For i = 1 to 16 ' 16 bits to a word
temp = temp >> 1 ' Shift down bits
Gosub readbit ' Get the bit to the top of temp
Next i
Return

' Read a bit from the DS1820
readbit:
temp.15 = 1 ' Preset read bit to 1
Low DQ ' Start the time slot
@ nop ' Delay 1us at 4MHz
DQ_DIR = 1 ' Release data pin (set to input for high)
If DQ = 0 Then
temp.15 = 0 ' Set bit to 0
Endif
Pauseus 60 ' Wait out rest of time slot
Return

End

Acetronics2
- 16th May 2008, 09:40
Hi, Karen ...




The program I've written is 8k (the hex file is)



The sample you gave compiles ... 1315 Words

did I miss something ???

Alain

karenhornby
- 16th May 2008, 11:41
Changed the code previously posted to get rid of unused functions

Acetronics2
- 16th May 2008, 12:23
That fits into a 16F628a whithout any problem ... then.

may we consider the subject solved ???

you can easily save some more room, simply replacing "high x " and "Low y " by " x = 1 " and " y = 0 "

Alain

skimask
- 16th May 2008, 13:53
Define LOADER_USED 1
If you don't need it in the end product, would save some space here...


IF PORTC.0 = 0 AND PORTC.3 = 0 then lcdout $FE,1," Diesel", $FE,$C0,"Outside ", $fe, $C9, dec (temp >> 1), ".", dec (temp.0 * 5), $DF, "C": LOW PORTE.0: LOW PORTE.1
IF PORTC.0 = 1 AND PORTC.3 = 0 then gosub Tempcheck
IF PORTC.0 = 0 AND PORTC.3 = 1 then gosub Tempcheck
If PORTC.0 = 1 AND PORTC.3 = 1 then gosub Oil
The If/AND/Then takes up more space than consecutive If/Then's...


IF PORTC.0 = 0 then
If PORTC.3 = 0 then
lcdout $FE,1," Diesel", $FE,$C0,"Outside ", $fe, $C9, dec (temp >> 1), ".", dec (temp.0 * 5), $DF, "C": LOW PORTE.0: LOW PORTE.1
endif
endif



For i = 1 to 8 ' 8 bits to a byte
For i = 0 to 7 would save a few more bytes


For i = 1 to 16 ' 16 bits to a word[/B]
Same thing here.... For i = 0 to 15

Just some tips for future use... :)

karenhornby
- 16th May 2008, 15:02
Many thanks Gents :)
You're all stars (in my eyes)
and yes subject closed.
Thanks again