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 CCS Technical Support

auto_off function

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



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

auto_off function
PostPosted: Fri Mar 06, 2020 5:00 am     Reply with quote

Hi,

PIC 18F2620, 1MHz internal oscillator, CCS version: V4.114

I want to auto-off the circuit when there is no change in PV for about 10 minutes. Due to some factors, PV will change slightly. So that we shall provide a limit like PV+x and PV-X. If the PV is within this range, a digital pin will switch off the circuit. Could you please help on the logic to work it out. I have been trying it. But couldn't find the solution.

Let's say, on 5th minute, if the PV changes largely or outside the limits as mentioned above. Time should start from 0.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Mar 06, 2020 8:17 am     Reply with quote

What on earth do you mean by 'PV'. We don't know....
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Mar 06, 2020 9:05 am     Reply with quote

PV = Potential Voltage or Photovoltaic Voltage ??
The algorithm to control power is easy enough though...
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Mar 06, 2020 11:51 am     Reply with quote

Photovoltaic voltage brings different problems to potential voltage.
Problem you are going to have is any photo voltaic source is going to
be very high impedance. You will need a buffer amplifier.
Simplest way would be to program two comparator outputs one from a
voltage just below the source, the second just above (use the comparator
reference module to set the limits), then take the two outputs and feed
them into a logic gate, or have hove code to set a pin when the voltage
is between the two limits.
However resolution will be quite low. For accuracy, you would have to
actually have the PIC running, and read the ADC and test the value
being between the limits. You could use the watchdog and sleep for
(say) 28mSec then make one reading, update the output and go back to
sleep. If a pin is to control this then wake for just a handful of machine
cycles test the pin and if it is still set, go straight back to sleep.
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Fri Mar 06, 2020 4:16 pm     Reply with quote

What circuit are you talking about? Do you mean you want to switch off your PIC, or you want to disable the power of the amplifier that you are using to measure the voltage?

If you are talking about the amplifier then there are opamps with a disable pin that you can pull to turn off the amplifier.
Jerson



Joined: 31 Jul 2009
Posts: 125
Location: Bombay, India

View user's profile Send private message Visit poster's website

PostPosted: Fri Mar 06, 2020 6:52 pm     Reply with quote

I guess the original poster meant process value
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Mar 06, 2020 7:08 pm     Reply with quote

We need more information.
What is 'PV' ?
Is PV an analog signal or a digital signal ?
This is CRITICAL information.
Another very important piece is HOW the 'time keeping' is being done.
Do you use an RTC device like the DS1307 or a SW based RTC ? Both require good battery backup and really a HW RTC is preferable the DS3231 is a very accurate RTC.
hemnath



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

PostPosted: Sun Mar 08, 2020 10:09 pm     Reply with quote

PV - Process Value

In my case, it varies from 0.000 to 10.000.

Assume it is a variable as Y. Don't confuse with PV.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Mon Mar 09, 2020 1:03 am     Reply with quote

Some comment:

Having a number like 0 to 10.0 floating point, is a sure sign of 'bad design'.
Floating point numbers are never accurate, involve a huge amount of
processor work, are bulky & slow.
Much better to have an integer value like 0 to 10000.
Now no matter how this is generated there will be 'errors'. You are never
going to get 'no change'. Simple noise implies that values will fluctuate.
You need to be using a 'margin', and allowing small changes to be treated
as insignificant.
Now, how to suspend a system, will be down to what hardware you actually
have. Simplest something like a RTC chip, and program an alarm for a time
interval. However don't be afraid of simply having the system wake for a
few machine cycles at a much shorter interval. A one per second 'tick',
and a system that wakes, does some tests, updates a counter and goes
back to sleep, costs almost nothing in power.
hemnath



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

PostPosted: Mon Mar 09, 2020 2:53 am     Reply with quote

Ok. I'll come in your way.

If the value is integer (lets say the value is 50) is constant for 10 minutes, I'll send a logic high signal using microcontroller pin. I don't have RTC chip in my hardware. Using internal timer, I have to use it.

I have used the internal timer section for 1 second delay.
Code:
#INT_rtcc  // This function is called every time
void clock_isr()
{
   // the RTCC (timer0) overflows (255 - > 0) .
   // FOR this program this is apx 76 times
   if (--INT_count == 0)
   {
      // per second.
      ++seconds; 
      INT_count = INTS_PER_SECOND;
   }
}

How to build the algorithm/logic to check that the value is not changing using this timer ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Mon Mar 09, 2020 4:11 am     Reply with quote

Even with an integer, you will see change. The key is to set limits for it:

Code:

int1 change_seen=FALSE;
#define LEVEL 4 //set this to determine the movement accepted

#INT_rtcc  // This function is called every time
void clock_isr()
{
   static unsigned int16 old_pv;
   int16 diff;

   if (old_pv>pv)
      diff=old_pv-pv;
   else
      diff=pv-old_pv;
   if (diff>LEVEL)
      change_seen=TRUE;
   else
      change_seen=FALSE;
   old_pv=PV;     

   // the RTCC (timer0) overflows (255 - > 0) .
   // FOR this program this is apx 76 times
   if (--INT_count == 0)
   {
      // per second.
      ++seconds;
      INT_count = INTS_PER_SECOND;
   }
}
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 09, 2020 5:18 am     Reply with quote

re: timer based RTC
the following link ...
http://www.ccsinfo.com/forum/viewtopic.php?t=26177

...shows how to implement an accurate RTC using an internal timer.

Your version has a comment ...'apx 76 times'....
While it might be OK for a few seconds, 5-6-10 minutes could become inaccurate.
Also if NOT using an external xtal/caps for the PIC clock, the internal oscillator will not be accurate. Just something to be aware of.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Mon Mar 09, 2020 8:30 am     Reply with quote

and as a comment for looking for change over a time:
Code:

int1 change_seen=FALSE;
#define LEVEL 4 //set this to determine the movement accepted
#define LIMIT_TIME 4560 //counts - here using 60*76

#INT_rtcc  // This function is called every time
void clock_isr()
{
   static unsigned int16 old_pv;
   static unsigned int16 max_pv, min_pv;
   static int16 count;
   int16 diff;

   if (old_pv>pv)
      diff=old_pv-pv;
   else
      diff=pv-old_pv;
   if (diff>LEVEL)
   {
      change_seen=TRUE;
      count=0;
   }
   else
   {
      count++
      if (count>LIMIT_TIME)
         change_seen=FALSE;
   }
   old_pv=PV;     

   // the RTCC (timer0) overflows (255 - > 0) .
   // FOR this program this is apx 76 times
   if (--INT_count == 0)
   {
      // per second.
      ++seconds;
      INT_count = INTS_PER_SECOND;
   }
}

Here 'change_seen' will go FALSE, when the PV signal stays the same
within 'LEVEL' for 'LIMIT_TIME' counts.
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