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

stuck in programming

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



Joined: 04 Mar 2009
Posts: 3

View user's profile Send private message

stuck in programming
PostPosted: Fri Jan 10, 2014 9:29 am     Reply with quote

hello everybody help please

i have to make a command in 15 valves

I'm using pic 18f452 at 20mhz

the fact is the way of opening this valves (i mean in programing not practice )

the problem is

each valve have a variable opening time from 0 to 9 like this

0= 0.00s
1=0.10s
2=0.14s
3=0.20s
4=0.28s
5=0.39s
6=0.54s
7=0.76s
8=1.10s
9=1.50s

s mean second this is the time that the valve must be keep open
other thing that all the valve have another parameter which is

how many opening time in one minute

this parameter can be between 00 and 64

Example for one valve that have the parameter :
3 = 0.20s and have 15 times opened in minute

so it will be have a square wave that have 15 on 1 logic and 15 off 0 logic

this square wave for the "1" logic 0.20s and the "0" logic is 3.8s

i have this equation (60/opening times ) - the opening time

so i m stuck how to program this by generate all 15 valves with each one have a particular opening time


excuse me for my bad english

please help
_________________
hi forr all
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Jan 10, 2014 12:37 pm     Reply with quote

Create a 10ms tick with one of the hardware timers.
Set up an ISR which executes on each tick and sets a flag.

In main:-

1) Wait for the flag to set
2) Process each valve in turn
3) Reset the flag.
4) Loop back to (1).

With your 20MHz clock you should have loads of time.

Each of your valves has an on_time and an on_time_counter, also an off_time and an associated off_time_counter.

Start by turning all the valves off and preset the off_time_counters.

So for each valve on every tick:-

a) If Valve is off, decrement off_time_counter.
b) If Valve is on, decrement on_time_counter.
c) If Valve is off and off_time_counter == zero; turn valve on & preset on_time_counter.
d) If Valve is on and on_time_counter == zero; turn valve off & preset off_time_counter.

Repeat this process for all valves in turn.
You will, of course have to be careful about how you deal with zero on_time & pulse_rate.

Mike
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Jan 10, 2014 2:23 pm     Reply with quote

If the valves are synced to some external event then you may want to use a faster timebase such as a 1ms time base instead of 10ms to minimize the error associated with synchronization.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
modchip



Joined: 04 Mar 2009
Posts: 3

View user's profile Send private message

thank you
PostPosted: Sat Jan 11, 2014 4:05 am     Reply with quote

thank you Mike

that seems logic
as i undrestand i must do tow counter for each valve one for the opening delay and the other for the off time

and teh valves have tow parametre for each valve have a value between 0 and 9

and this one can be different for each valve

and other parametre for all valve is the impulsion per minute between 00 and 64
_________________
hi forr all
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Jan 11, 2014 5:31 am     Reply with quote

I was trying to keep things simple for you.

If you are going to control by timing you have to convert your parameters to times.
You knew that in your first post, you showed us the formula.
You also need to keep track of the status of each valve.

Store all the parameters as arrays, that way you process all the valves with the same code as you index through the array.

Mike

PS
You could get away with using just the one timer for each valve.
It changes from being on_timer to off_timer depending on valve status.
It's slightly more complex.
I was trying to keep things simple for you.
As a beginnere your real problem will be dealing correctly with zero parameters and not getting stuck when the timers reach zero.
modchip



Joined: 04 Mar 2009
Posts: 3

View user's profile Send private message

PostPosted: Sat Jan 11, 2014 8:33 am     Reply with quote

thank s a lot i will try this at week end and tell you
_________________
hi forr all
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