CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Newbie / Frustration (very both)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

Newbie / Frustration (very both)
PostPosted: Tue Dec 02, 2003 1:19 am     Reply with quote

I just setup a low voltage programmer and got some 16F872 (acutally they're 16LF872)... got the programmer (tlvp) working, made a simple led example, programmed it, setup a test board/led deal (5v)and................. nothing happends.

Here is the code:


Code:

#include <16F872.h>
#fuses HS,LVP,NOWDT,NOPROTECT
#use delay(clock=20000000)

main()
 {
  while(1)
   {
    output_high (PIN_B2);
     delay_ms(250);
    output_low (PIN_B2);
     delay_ms(100);
   }
 } //end


I read about the tris and standard_io, fixed_io etc in other posts and dont THINK that is my problem, if I dont specify an IO it should just be std no ?

I've tried just about every port, other similar methods, different chips, fuses, lower clocks, etc...

My programmer is a Trivial LVP and I read that RB3 had to be used when programming and grounded when the chip was executed, so I tried grounding that... no avail...

What is wrong here ???

ps> What is a bootloader ? I dont need one of these right ? The firmware that comes on the chip is fine for me no ?
davt



Joined: 07 Oct 2003
Posts: 66
Location: England

View user's profile Send private message

Newbie / Frustration
PostPosted: Tue Dec 02, 2003 3:34 am     Reply with quote

Hi
You must set up the ports properly - PORT and PORT DIRECTION (Tris)
registers. Then your program should then work.
Good luck!
Dave
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Tue Dec 02, 2003 3:59 am     Reply with quote

But I'm using output_high(port); so shouldn't standard_io take care of that for me ?

That was my understanding, the standard_io (default) did the tris automatically.
Ttelmah
Guest







Re: Newbie / Frustration (very both)
PostPosted: Tue Dec 02, 2003 6:59 am     Reply with quote

iso9001 wrote:
I just setup a low voltage programmer and got some 16F872 (acutally they're 16LF872)... got the programmer (tlvp) working, made a simple led example, programmed it, setup a test board/led deal (5v)and................. nothing happends.

Here is the code:


Code:

#include <16F872.h>
#fuses HS,LVP,NOWDT,NOPROTECT
#use delay(clock=20000000)

main()
 {
  while(1)
   {
    output_high (PIN_B2);
     delay_ms(250);
    output_low (PIN_B2);
     delay_ms(100);
   }
 } //end


I read about the tris and standard_io, fixed_io etc in other posts and dont THINK that is my problem, if I dont specify an IO it should just be std no ?

I've tried just about every port, other similar methods, different chips, fuses, lower clocks, etc...

My programmer is a Trivial LVP and I read that RB3 had to be used when programming and grounded when the chip was executed, so I tried grounding that... no avail...

What is wrong here ???

ps> What is a bootloader ? I dont need one of these right ? The firmware that comes on the chip is fine for me no ?


What you have written, should work, and represents a good 'test' program. The possible problems are:
1) The programmer is not working.
2) The programmer is not writing the 'config' fuses.
3) You have a faulty chip.
4) There is a problem with the wiring of the circuit.
5) The chip has been programmed to, or arrived set to NOLVP mode.
There is no 'firmware on the chip'. This is not needed by an external programmer.
There are a number of possible reasons at each point. On the first, this is a 'parallel port' programmer, if I remember correctly. If so, then it may well be that the code won't work under WNT, W2K, or WXP. Check this, if you are running one of these OS's.
Quite a few programs, require the config fuses to be 'manually' configured inside the program (don't read the values from the source file). This would result in patterns being used, that might not work.
Once 'NOLVP' is set, a PIC, can only be reprogrammed using a 'high voltage' programmer. Some chips have at times come from the factory set like this.
Double check also, that the chips are 16LF872, not 16LF872A variants. The latter are not 'cross compatible' with the former.

Best Wishes
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

STILL NOTHING :(
PostPosted: Tue Dec 02, 2003 4:24 pm     Reply with quote

I dont understand whats going on here....

Code:

#include <16F872.h>
#fuses HS,LVP,NOWDT,NOPROTECT
#use delay(clock=8000000)

main()
{
  while(1)
   {
    output_high (PIN_B4);
     delay_ms(250);
    output_low (PIN_B4);
     delay_ms(100);
   }
} //end


in hex its (oops, this hex is EXACT same code, but ouputs to B2):
Code:

:1000000000308A00172800002630840000080319F9
:1000100016280230A100A001A00B0C28A10B0B2870
:100020009730A000A00B1228800B0928003484010F
:100030001F3083059F30840007308000831606112F
:1000400083120615FA30A6000420831606118312C7
:0C00500006116430A60004201E28630086
:02400E00FA3F77
:00000001FF
;PIC16F872


with this (I know that the pic says its an A part, but thats a mistake, I'm using 16LF872, NON-A):


I get nonthing... I tested the circuit and i verified the chip, it reads the same as my hex file... I'm stuck. I'm sure the programmer works... but not sure about the config bit...

If the hex reads off the chip just like my file shouldn't that also mean the config is set and that would also mean that it is being programmed (ie: the lvp bit is correctly good)

Btw: I read that when programmed in LVP that RB3 must always be grounded (well except programming o/c)... i tried un-gnding it, no difference.

I'm using the trivial lvp and tait's FPP... one thing i noticed in FPP is that under "code" i see my hex file, but under "data" i see "blank" is that where my config bit is supposed to be ???

Kinda need this to work very soon....
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Tue Dec 02, 2003 4:34 pm     Reply with quote

What kind of signal is going to MCLR?
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Tue Dec 02, 2003 4:41 pm     Reply with quote

um..... none ?

nothing is.... is it supposed to be ?


My programmer runs to mclr... but the led setup i have nothing goes to mclr/vpp... I thought that was for programming only...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 02, 2003 4:48 pm     Reply with quote

I saw your post last night, but I didn't answer it because I have
no experience with the TLVP programmer.

But I had a hunch.... I said to myself, "does he even have
a crystal hooked up to his PIC ?"

In addition to Neutone's remark about MCLR, you should
look at this schematic to see how a crystal is connected to
the PIC. It has to go on the OSC1 and OSC2 pins.
You need the capacitors also. The #use delay statement
value must match the value of the crystal frequency.
See this schematic. Note that the pin numbers are
different, because the schematic shows a 40 pin PIC.
But you can go by the pin labels, and compare that
to your 16LF872.

http://www.melabs.com/downloads/labx2sch.pdf

In addition to that, you very likely need a resistor in
series with your LED. Use a value from 220 to 470 ohms.
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Tue Dec 02, 2003 4:59 pm     Reply with quote

Ok.... what if i want to do this w/o a clock.... Cant I use an internal timer or somthing or do i NEED an external clock ???

What is SUPPOSED to be sent to mclr? (i dont want or need a reset)

I just got back from radioshack... No Clock/Crystals :( .... Is there a store that is probally local that would have these ??

Also, i'm using a 5V led that i know works.


edit: Um... in FPP it says "Config: ####" should somthing meaningful be in there or does it retrieve it from my hex file? ...And if I am supposed to put somthing in there, i'm guessing its a hex value, but how do i figure what to put ?
Ttelmah
Guest







PostPosted: Wed Dec 03, 2003 3:28 am     Reply with quote

iso9001 wrote:
Ok.... what if i want to do this w/o a clock.... Cant I use an internal timer or somthing or do i NEED an external clock ???

What is SUPPOSED to be sent to mclr? (i dont want or need a reset)

I just got back from radioshack... No Clock/Crystals :( .... Is there a store that is probally local that would have these ??

Also, i'm using a 5V led that i know works.


edit: Um... in FPP it says "Config: ####" should somthing meaningful be in there or does it retrieve it from my hex file? ...And if I am supposed to put somthing in there, i'm guessing its a hex value, but how do i figure what to put ?


You need a pull-up resistor on MCLR. Something like 47K to 5v. Otherwise the chip will never start. Then either an external clock signal feeding in to the OSC1 pin, or a crystal between OSC1, and OSC2 (with two small capacitors, one from each end of the crystal to ground - the exact values will depend on the crystal, but typically perhaps 27pF each). Also, you should really have a resistor in series with the LED, unless this is a type with a built in 'current limit', or you risk overloading the pin driving it (this depends on the forward voltage of the LED).

Best Wishes
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Wed Dec 03, 2003 4:21 am     Reply with quote

I see,

So.... I need to go back to radioshack and get a 47k pull up resistor. Then 5V goes to the resistor and then that goes to mclr... this is NEEDED ?? I've never seen anyone's simple led diagrams w/ this... then again, those have all been for 16f84s

So for the clock I need to go find a crystal (or i guess use RC fuse... is there a forumla to figure out what X resistor and Y cap with make for Mhz ?)

Anyhow, this is what I cam up with now... will this one work ???


Oh, and your right, there should be a resistor on that led... what resistor can i put on there that wont cut the brightness down too much but will stop it from burning the pin ?

Thanks Again,


edit: also, I'm trying to find 22pF caps... its pico right, not mirco (uF)... It looks like radioshack MIGHT have a set of 80 mixed caps that have 22pF in there, but its like $8.00! They do have 100pF caps, will those work? (prolly not, but hey, might as well ask)
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Wed Dec 03, 2003 9:14 am     Reply with quote

Radio Shack is nearly worthless for getting parts.

Since you have obivously have some kind of Internet access, go to www.digikey.com and www.mouser.com (there are others but these will get you a long way). Prowl around and find an email or phone number to call and order a catalog. The catalogs are available on-line but I find it is sometimes easier to sift through the printed version first.

You will have minimum order issues and shipping costs but weigh those against the cost of your time and frustration when you don't have the parts you want to try an idea. Also, if the part is cheap order 2 or 10 or 100, never just one.

Also, go to http://www.microchip.com/1010/suppdoc/refernce/midrange/index.htm and download a copy of the midrange reference manual. Good stuff in there.

Back to your circuit,

1) You need MCLR- pulled up to Vdd (+5V) Use a resistor between 10K and 47K. Radio Shack does have these (1/4W carbon film, 5% is OK)

2) You need some kind of clock source. You can tell the PIC to use its internal clock generator . This is done with the FUSES statement if you are using the CCS compiler. EXTRC is the keyword for external RC. The resistor should be kept between 3K and 100K. It is between Vdd and the OSC1 pin. Then from the OSC1 pin to ground you add a small capacitor. The minimum value of capacitor is 20pF and Microchip recommends you pick something a bit higher. Now to pick the values you can refer to the charts in the DC and AC Characteristics Graphs and Tables portion of the datasheet. Only problem is that the PIC16F87xA data sheet (at least the copy I had handy) doesn't have that appendix filled out yet. As a fall-back position I'd refer to the previous revision's data sheet, the PIC16F87x. There I find that if my Vdd is 5V and I'm at 25C I can expect to have Fosc run at 3.5MHz if I pick 20pF and 3.3k. You can put an oscilloscope on OSC2 to see Fosc / 4 (don't have an oscilloscope, then save your money or try to borrow one). You will NEVER get the kind of frequency stability that a crystal, crystal oscillator or even ceramic resinator provides using an external RC. But to blink a LED, the EXTRC choice is just fine.

3) You need a current limiting device for your LED. The simplest is a resistor. In general, the average RED led has a voltage drop of about 2.1V. And the average RED led has a maximum current limit of 20mA. But you don't need 20mA through the LED to make it nice and bright, most look fine on the bench with 8mA to 10mA. To pick your resistor the formula is R = (Vdd - Vled) / Iled. Since you are probably going to use a 5% resistor and just admire the LED with your eyeballs we don't need to get fancy and have 3 decimal points of precision here. Assume Vled = 2V (I know I said 2.1V earlier but its easier to do in your head if you use 2V) and Vdd=5V. If you want 8mA then you need (5-2)/.008 = 375 Ohm. The closest 5% value is 360 Ohm. However if your only source of parts is Radio Shack you are probably stuck with 330 or 390 Ohm or maybe 470 Ohm. Good enough.

If you get some better LEDs than the crappy surplus junk Radio Shack sells then you can get a nice bright light with less current. Try playing with values of 470 or 1K. Also, if you are going to drive a lot of LEDs from a single chip without multiplexing then you need to make sure you aren't asking the chip to sink or source more total current than the maximum allowed for the IC. You just have one LED so no worries.

4) If you can borrow a known working programmer then you can eliminate several unknowns. That will let you test your circuit and code instead of the programmer, circuit and code.

The last thing I can say is to save your pennies and keep your eyes open for good deals on development tools like programmers, comilers and test equipment. Even working as a hobby, your time and sanity are worth much more than saving $49.95 to buy the tool that does what you need.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Wed Dec 03, 2003 9:25 am     Reply with quote

I just looked at the Microchip web site and they have an updated copy of the PIC16F877A datasheet. It does have the frequency vs R vs C vs temp graphds included. Somewhat different from those in the non-A datasheet so look at the new ones.

Don't try 3.3K and 20pF. Start with 10K and 100pF to run around 1MHz Fosc. You can try 5.1K and 20pF to get close to 4MHz but don't expect it to be reliable if your Vdd goes below 4.5V or the temperature shifts more than a few degrees away from 25C.

Time to print a new datasheet and transfer all my notes to the new pages!
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 03, 2003 11:31 am     Reply with quote

He's not using the "A" part. See this quote from his previous post:
Quote:
(I know that the pic says its an A part, but thats a mistake, I'm using 16LF872, NON-A):

By "pic", he means "picture" (schematic).
Guest








PostPosted: Wed Dec 03, 2003 12:47 pm     Reply with quote

oh... Smile

Yea, confusing sorry.


So that pic(ture) I have there will work now ? Cause I found out that NO ONE in 100mi of me has clocks... So i'm gonna make a RC deal today and have some ordered in.

(btw: whats the diff between a crystal clock and an ocillator clock?)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group