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

16F84A to 16F877 read values changing...

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Rollo
Guest







16F84A to 16F877 read values changing...
PostPosted: Wed Mar 19, 2003 11:14 pm     Reply with quote

I'm building a fine-grained sky darkness gauge using a TSL230 chip. I had a version working very well on a BS2. Another, off a laptop port. Friends were asking for a stand-alone version, so I got CCS and a Warp13A last week. People on this board have been great in giving very useful newbie advice.

Here's a new problem, in case anyone can help.

I did get a version of my "darkometer" working using a 16F84A and using an interrupt to generate time, and simple code to detect pulses ( loosely based on the CCS manual's EX_Pulse.c code.

These dark sensor pulses I want to measure are very slow, due to dark conditions - most useful range from 0.1hz to 100hz, though in a bright room it can reach 60KHz. Typically I measure pulses for 10 seconds and then divide the result by ten to get Hz. Works fine on the 16F84A to within 0.1Hz of my original BS2 design.

BUT during the last two days, when I tried to port this over to a 4Mhz 16F877 PIC, I started to have some problems with the pulse readings coming in off by 8000 each reading, in a bright room. As you can see, the readings are fluctuating quite a bit. My for all elements ( except of course the PIC ) is identical.

Anyway, here's the code. I hope it's not too long.


#include <16F877.h>
#FUSES XT,NOWDT,NOPROTECT,NOLVP,PUT,NOBROWNOUT
#use delay(clock=4000000)
#define INTS_PER_SECOND 4000000/(4*256*256)
#use fast_io(B)

// definition of each digit in terms of bits on and off on 7-seg-LED
byte CONST segs[12] = { 0b10000001, 0b10110111, 0b11000100, 0b10010100, 0b10110010, 0b10011000, 0b10001000, 0b10110101, 0b10000000, 0b10010000, 0b01111111, 0b11111111 };

byte seconds; // A running seconds counter
byte int_count; // Number of interrupts left before a second has elapsed
int16 pulses; // Counting number of pulses during a given time interval
byte count=0;
char numstring[5]="";


void poz(){

delay_ms(120);
}

void TSLoutput() {
disable_interrupts(INT_RTCC);
sprintf( numstring, "\%05lu", pulses );
for( count=0;count<=4; count++)
{
output_D(segs[(numstring[count]) - '0']);
poz();
poz();
output_D(segs[11]); // blank between digits
poz();

}

output_D(segs[11]); // blank to detect light
seconds =0;
enable_interrupts(INT_RTCC);

}


#int_rtcc // This function is called every time
clock_isr() { // the RTCC (timer0) overflows (255->0).
// For this program this is close apx 76 times
if(--int_count==0) { // per second.
++seconds;
if( seconds == 10 ) TSLoutput();
int_count=INTS_PER_SECOND;
}
}


void wait_for_low_to_high() {

while(input(PIN_B5)) ;
//delay_us(5);
while(!input(PIN_B5));
}


void wait_for_low() {
//delay_us(5);
while(input(PIN_B5));
pulses++;
}

set_tris_D(0);
//set_tris_B(1);

main() {
set_tris_B(0xFF);

// prepare the timer interrupts
int_count=INTS_PER_SECOND;
set_timer0(0);
setup_counters( RTCC_INTERNAL, RTCC_DIV_256);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);

seconds =0; // time and pulses to zero
pulses = 0; // once before loop

do {
wait_for_low_to_high();
wait_for_low();


} while (TRUE);
}


Any ideas appreciated! What could cause my # of pulses to fluctuate so much on the 877 but not on the 84A?


Thanks,
Rol
___________________________
This message was ported from CCS's old forum
Original Post ID: 12857
Rollo
Guest







Disregard Previous - found a typo - some noise left tho'...
PostPosted: Wed Mar 19, 2003 11:37 pm     Reply with quote

Wouldn't you know it, just after posting, my mind suddenly surfaces an idea. What if there's a typo and I'm not re-setting pulses to zero. That's all it was. Sheesh! After all this work and it's a typo! Well at least found it.

There's still much more "dark noise" left though, on the Astronomy darkometer.

In total (closed closet) darkness measured off TSL230 chip, by PICs =

1- BS2 circuit - 0.8hz
2- 16F84A - 0.9hz ( accpetable )
3- 16F877 - 1.7hz ( way too noisy )

So my question becomes... any ideas on how to reduce noise on a 16F877. The TSL must be ok, since I use the same chip and same config in all three versions of the dark sky sensor.

Already have...

1- One decoupling cap 0.1uF on PIC
2- A couple of caps on the 7805
3- A 1K pull-down resistor on the PIC pin that reads pulses

Is there anything else I should look into to reduce noise?

Thanks,
Rol
___________________________
This message was ported from CCS's old forum
Original Post ID: 12858
R.J.Hamlett
Guest







Re: Disregard Previous - found a typo - some noise left tho'
PostPosted: Thu Mar 20, 2003 4:24 am     Reply with quote

:=Wouldn't you know it, just after posting, my mind suddenly surfaces an idea. What if there's a typo and I'm not re-setting pulses to zero. That's all it was. Sheesh! After all this work and it's a typo! Well at least found it.
:=
:=There's still much more "dark noise" left though, on the Astronomy darkometer.
:=
:=In total (closed closet) darkness measured off TSL230 chip, by PICs =
:=
:=1- BS2 circuit - 0.8hz
:=2- 16F84A - 0.9hz ( accpetable )
:=3- 16F877 - 1.7hz ( way too noisy )
:=
:=So my question becomes... any ideas on how to reduce noise on a 16F877. The TSL must be ok, since I use the same chip and same config in all three versions of the dark sky sensor.
:=
:=Already have...
:=
:=1- One decoupling cap 0.1uF on PIC
:=2- A couple of caps on the 7805
:=3- A 1K pull-down resistor on the PIC pin that reads pulses
:=
:=Is there anything else I should look into to reduce noise?
:=
:=Thanks,
:=Rol
Several possible things.
Obvious difference. The 16F977, has two ground pins, and two supply pins. You will get odd behaviour, unless both are well connected, and decoupled.
You say 'a couple of caps on the 7805'. What sort of caps, and how are these connected?. Ideally, the regulator wants it's caps close to the pins, and you need to be looking at a choice of types that give both the low frequency behaviour, and good performance at high frequencies. Hence the common use of both an electrolytic paralleled with a ceramic cap.
What type is your 0.1uF cap?. Again there is a lot of difference in the performance between different types of capacitors.
How is the ground coupled between the PIC, and the incoming signal source?.
Is the pin you are using for the input, the same 'type' on both chips?. Remember a Schmidtt trigger input, will provide nice repeatable switching at the same voltage, but a TTL input will not. Port B5 (which you are using on the 16F chip), is a TTL input, not a Schmidtt trigger input type.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 12863
Rollo
Guest







Good advice re: caps and details...
PostPosted: Thu Mar 20, 2003 8:39 am     Reply with quote

Thanks so much for your suggestions. Here are circuit details regarding the items you mentionned...


>:=Obvious difference. The 16F977, has two ground pins, and two >supply pins. You will get odd behaviour, unless both are well >connected, and decoupled.

Both grounds and supplies are connected, and with each supply decoupled with a 5\% tant. 0.1uF cap.


>You say 'a couple of caps on the 7805'. What sort of caps, and >how are these connected?. Ideally, the regulator wants it's >caps close to the pins, and you need to be looking at a choice >of types that give both the low frequency behaviour, and good >performance at high frequencies. Hence the common use of both >an electrolytic paralleled with a ceramic cap.
>:=What type is your 0.1uF cap?.


Caps are right next to 7805 pins on the breadboard. A 0.47uF regular ceramic cap between the 9V input and center pin. A 1.0uF tant cap between center pin and 5V output.


>:=How is the ground coupled between the PIC, and the incoming >signal source?.

Ground is coupled between PIC and TSL light sensor each through breadboard ground only. Should this be different? I am curious whether the incoming signal pin on the PIC might require some kind of resistor or not.


>Is the pin you are using for the input, the same 'type' on >both chips?. Remember a Schmidtt trigger input, will provide >nice repeatable switching at the same voltage, but a TTL input >will not. Port B5 (which you are using on the 16F chip), is a >TTL input, not a Schmidtt trigger input type.

Didn't know I had to check, thanks for the idea...

On the 16F84A I was using pin RA2 - specs say TTL buffer.
On the 16F877 I am using pin RB5 - specs also say TTL buffer.

Does not look like that is the issue.


Note that I have just now pulled up all un-used pins on the PIC through a 4.7k resistor, but that does not affect the output. Any other ideas?

Thanks for your reply!

Rol
___________________________
This message was ported from CCS's old forum
Original Post ID: 12875
R.J.Hamlett
Guest







Re: Good advice re: caps and details...
PostPosted: Thu Mar 20, 2003 9:38 am     Reply with quote

:=Thanks so much for your suggestions. Here are circuit details regarding the items you mentionned...
:=
:=
:=>:=Obvious difference. The 16F977, has two ground pins, and two >supply pins. You will get odd behaviour, unless both are well >connected, and decoupled.
:=
:=Both grounds and supplies are connected, and with each supply decoupled with a 5\% tant. 0.1uF cap.
:=
:=
:=>You say 'a couple of caps on the 7805'. What sort of caps, and >how are these connected?. Ideally, the regulator wants it's >caps close to the pins, and you need to be looking at a choice >of types that give both the low frequency behaviour, and good >performance at high frequencies. Hence the common use of both >an electrolytic paralleled with a ceramic cap.
:=>:=What type is your 0.1uF cap?.
:=
:=
:=Caps are right next to 7805 pins on the breadboard. A 0.47uF regular ceramic cap between the 9V input and center pin. A 1.0uF tant cap between center pin and 5V output.
:=
:=
:=>:=How is the ground coupled between the PIC, and the incoming >signal source?.
:=
:=Ground is coupled between PIC and TSL light sensor each through breadboard ground only. Should this be different? I am curious whether the incoming signal pin on the PIC might require some kind of resistor or not.
:=
:=
:=>Is the pin you are using for the input, the same 'type' on >both chips?. Remember a Schmidtt trigger input, will provide >nice repeatable switching at the same voltage, but a TTL input >will not. Port B5 (which you are using on the 16F chip), is a >TTL input, not a Schmidtt trigger input type.
:=
:=Didn't know I had to check, thanks for the idea...
:=
:=On the 16F84A I was using pin RA2 - specs say TTL buffer.
:=On the 16F877 I am using pin RB5 - specs also say TTL buffer.
:=
:=Does not look like that is the issue.
:=
:=
:=Note that I have just now pulled up all un-used pins on the PIC through a 4.7k resistor, but that does not affect the output. Any other ideas?
:=
:=Thanks for your reply!
:=
Unfortunately, you are now into searching for harder to find differences!. The 16F877 chip, should actually draw slightly less power than the 16F84A. The input high, and low voltages are the same for both chips. So the most 'likely' difference, is something relating to the actual layout of the board, and how the signal routes. Both pins are well away from the clock, and the decoupling described sounds good. Try taking the grounds of each component (regulator, PIC, and sensor), back to one common point. If you could try switching to one of the Schmidtt inputs, you might well find it gives a better result. A decoupling difference round the sensor (given this is the part of the circuit with the lowest signal levels), or just a difference in the sensor (is this the same one, or another of the same type?), sound the most likely things now.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 12879
Rollo
Guest







Re: Good advice re: caps and details...
PostPosted: Thu Mar 20, 2003 1:44 pm     Reply with quote

>Unfortunately, you are now into searching for harder to find >differences!

OK, well, it's good to know it isn't something obvious.

Tried with two complete 16F877 circuits on different breadboards ( except for the light sensor that I switch across ).

>Try taking the grounds of each component (regulator, PIC, and >sensor), back to one common point.

Nope, that didn't do it either. Good idea tho.

>If you could try switching to one of the Schmidtt inputs, you >might well find it gives a better result.

Tried reading in with pin C4 instead, as it is Schmidtt, but the dark_noise level remains a steady 3.0hz on this 16F877, whereas it remains 0.9Hz on the 16F84A. I think I'll compare the two circuits one component at a time, to try to zero in on the difference.


>A decoupling difference round the sensor (given this is the >part of the circuit with the lowest signal levels), or just a >difference in the sensor (is this the same one, or another of >the same type?), sound the most likely things now.

Same sensor has been used all along, to factor out that variance. Your advice is much appreciated. I will look very slowly and carefully at everything again, from the ground up. I will post solution if I find it.

Thanks again for the assistance,
Rol
___________________________
This message was ported from CCS's old forum
Original Post ID: 12889
Rollo
Guest







Have narrowed it down to the power supply.
PostPosted: Thu Mar 20, 2003 2:09 pm     Reply with quote

I have managed to narrow down the problem to the power supply. I used Vdd and Vss off my Basic Stamp module, to power the 16F877 dark sky sensor, and the dark_noise level was down to 0.8Hz, instead of 1.5hz.

So, it sure looks like my power supply might be the spoiler, as opposed to anything in my wiring or circuit. This really narrows things down, at least.

later,
Rol
___________________________
This message was ported from CCS's old forum
Original Post ID: 12891
Rollo
Guest







Re: Good advice re: caps and details...
PostPosted: Thu Mar 20, 2003 2:11 pm     Reply with quote

I have managed to narrow down the problem to the power supply. I used Vdd and Vss off my Basic Stamp module, to power the 16F877 dark sky sensor, and the dark_noise level was down to 0.8Hz, instead of 1.5hz.

So, it sure looks like my power supply might be the spoiler, as opposed to anything in my PIC wiring or circuit. This really narrows things down quite a bit. I'll focus my attention here.

later,
Rol
___________________________
This message was ported from CCS's old forum
Original Post ID: 12893
R.J.Hamlett
Guest







Re: Good advice re: caps and details...
PostPosted: Thu Mar 20, 2003 4:02 pm     Reply with quote

:=I have managed to narrow down the problem to the power supply. I used Vdd and Vss off my Basic Stamp module, to power the 16F877 dark sky sensor, and the dark_noise level was down to 0.8Hz, instead of 1.5hz.
:=
:=So, it sure looks like my power supply might be the spoiler, as opposed to anything in my PIC wiring or circuit. This really narrows things down quite a bit. I'll focus my attention here.
:=
The 78xx, is usually pretty reliable. Is it possible that the 0.47uF cap you mention as decoupling on this, is not actually good at blocking high frequencies, and you are getting oscillation on the regulator?. Have you checked the input voltage to the regulator?. Remember the 78xx, is not a low dropout regulator, and will need an incoming rail quite a few volts above the required rail.
At least you know where the problem is now. :-)

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 12899
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Have narrowed it down to the power supply.
PostPosted: Thu Mar 20, 2003 4:58 pm     Reply with quote

:=I have managed to narrow down the problem to the power supply. I used Vdd and Vss off my Basic Stamp module, to power the 16F877 dark sky sensor, and the dark_noise level was down to 0.8Hz, instead of 1.5hz.
:=
:=So, it sure looks like my power supply might be the spoiler, as opposed to anything in my wiring or circuit. This really narrows things down, at least.
:=
----------------------------------------------------------

Basic Stamp II uses a Seiko Instruments S-81350HG regulator.
It probably regulates better than the 7805. You could try
using a later model regulator, such as LM340. Or, maybe the
first thing to try would be a 10 uf tantalum cap on the
output, instead of 1 uf. I always use 10 uf on that type
of regulator (on both input and output).
___________________________
This message was ported from CCS's old forum
Original Post ID: 12903
Rollo
Guest







Re: Good advice re: caps and details...
PostPosted: Thu Mar 20, 2003 5:53 pm     Reply with quote

Well, I just changed the voltage regulator, and the noise has now dropped to normal. Perhaps due to my inexperience I managed to send too strong a current thru it, and somehow damaged the unit in such a way that it is slightly noisier than before? I'm not sure.

In any case, all is now working well. Thanks very much for your advice -- I've picked up quite a few pointers from your assistance. Your assistance does make a big difference...

Thanks
Rol
___________________________
This message was ported from CCS's old forum
Original Post ID: 12905
Rollo
Guest







Re: Have narrowed it down to the power supply.
PostPosted: Thu Mar 20, 2003 10:13 pm     Reply with quote

Thanks for the suggestions! The first thing I'll try is to get my hands on some 10uF tant caps. Then I'll check out those regulators online as well. Very useful.

Got rid of most of my noise by simply replacing one make of 7805 with another, but your ideas might give me the extra little bit that I'd really like to get.

Thanks!
Rol


You wrote:
:=Basic Stamp II uses a Seiko Instruments S-81350HG regulator.
:=It probably regulates better than the 7805. You could try
:=using a later model regulator, such as LM340. Or, maybe the
:=first thing to try would be a 10 uf tantalum cap on the
:=output, instead of 1 uf. I always use 10 uf on that type
:=of regulator (on both input and output).
___________________________
This message was ported from CCS's old forum
Original Post ID: 12908
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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