View previous topic :: View next topic |
Author |
Message |
devilfrmheaven
Joined: 09 Feb 2016 Posts: 53
|
Interrupt Capabilities of PIC16F73 or PIC16F727 |
Posted: Sun Aug 20, 2017 1:23 am |
|
|
Hi All,
I am confused with the types and number of interrupts that I am going to use for my friend's farm water pump project. This part was not intended but was an input from my friend as one of his water pumps got damaged running dry.
So I am looking for some options like overflow protection and run dry protection.
I am planning to use the following:
1) A second poller => Hopefully Timer 0
2) Ultrasonic Sensor = > Timer 1
3) Modbus for Communication => Timer 2
4) Interrupt-on-Change (RB7:RB4) => Hopefully B5 to read pulses from the water flow sensor.
I have been writing codes for this, have managed to make #1, #2 and #3 work simultaneously.
Now the issues the I face.
A) The Second poller seems to slow down and Speed up during modbus communication even with the approach below.
B) When I add in Interrupt on Change to the cocktail everything stops working. (#INT_RB)
Code: | void sec_count(void)
{
CurrentTick = get_ticks();
if(GetTickDifference(CurrentTick, PreviousTick) >= (TICK_TYPE)TICKS_PER_SECOND)
{
PreviousTick = CurrentTick;
polling();
input_regs[0]++;
}
}
|
Am I asking too much from a microcontroller? Do I need to split the second pulses to a different Microcontroller?
Please let me know your valuable suggestions.
Thanks in Advance. _________________ Regards,
Devil |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Aug 20, 2017 1:55 am |
|
|
If the system slows down with #int_rb it implies:
1. You're not clearing the interrupt-on-change condition inside the isr.
This is required. If you don't do it, you'll get continuous interrupts and
the PIC will appear to be locked up.
2. You may have repetitive interrupt-on-change interrupts because you
don't have pull-up resistors (or internal pull-ups) on the input pins.
If those PIC pins are floating, you will get noise interpreted as interrupts.
My suspicion is that you are not doing multi-tasking correctly.
See this thread for a simple example:
http://www.ccsinfo.com/forum/viewtopic.php?t=54043 |
|
|
devilfrmheaven
Joined: 09 Feb 2016 Posts: 53
|
Thanks for the quick response |
Posted: Sun Aug 20, 2017 2:24 am |
|
|
Thanks for the quick response PCM.
I think the waterflow sensor continuously gives a 115 Hz pulse.
With your response I think a pic can handle all these at the same time. So let me go back to my drawing board and see whats wrong.
I was under the impression that I am clogging up the interrupts of PIC Microcontroller.
The Seconds counter falls off balance when Modbus starts communication. Otherwise its pretty stable. _________________ Regards,
Devil |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sun Aug 20, 2017 5:14 am |
|
|
just some comments about PIC choice and project scope...
From your other thread you're doing a 'watering' project so...
1) watch out for EMI ( noise from pump turning on/off). Use shielded cables from sensors, MOVs, caps, etc whatever it takes to reduce , preferably eliminate EMI or glitches from getting to the PIC.
2) if you're not computing GPM of water, just 'poll' the flow sensor say at a 1Hz rate, for 4 seconds( 4 inputs). If 2 or more readings are high...water is flowing.This makes it a 'yes/no' function instead of 'math' for flow rate, so code is simpler.
3) use a 40 pin PIC. well at least one that is 'bigger', as you'll need more pins or RAM or peripherals.....
4) pump control. Use an SSR if possible,one that's 'self indicating' with feedback is best. this will send a 'confirmation' it's running
5) mount in a steel box, use a membrane keypad. $3 gets you a 3x4(telephone style) one these days, perfect for 'messy' areas !
6) add an LCD module. I like the 4x20 blue ones. You need 6 pins for it ..but you need some 'display' capabilites.LEDs are great but compare... 1 for power, 1 for pump on, 1 for flow,1 for heartbeat....that's 4 already ! With an LCD you have MUCH greater ability to show info.
7) add 'dead PIC' code on the host. Since you're using modbus, I assume there's a 'host' in control. Be sure it polls the PIC to confirm it, the PIC , is running .My remote control systems poll 4 times a minute and can sense if and where the wire has been cut.
8) might as well add an RTC..like the DS1307. That gives you a hardware 1Hz interrupt, great 'heartbeat' to update display,check sensors,report to host....
heck my projects always 'grow', so should yours !!
Jay |
|
|
devilfrmheaven
Joined: 09 Feb 2016 Posts: 53
|
Thanks Jay! |
Posted: Sun Aug 20, 2017 7:31 am |
|
|
Thanks Jay!
That was pretty awesome suggestions.
#1 is covered, I am using a lot of caps 0.1, 0.01, 0.001 - EMI is covered works perfectly with my protoboard. It has a lot of protection against static and it held decent during last couple of thunderstorms.
#2 GPM -> Not right now, may be my friend might spawn this brilliant Idea in his head half way through the project.
#3 PIC16F727 is 44PIN QUAD package. Plenty of pins
#4 I love SSR, all the PUMPS kicked off using beefy SSRs
#5 Yes Steel boxes with PCB as cover, and a glass molding over the top. Cap sense works through glass and no mess / scratches, Cow dung / wear and tear.
#6 Isnt LCD too much and most of the workers wouldnt be able to read English as its not our native language. Instead relay the reading to the master controller an Arduino that can do all these gimmick inside where my friend can monitor the activity.
Was planning 8 dual color LED for 8 water pumps. Red is OFF, Flashing green on.
#7 That would be included
#8 DS1307 Is another option I am looking for if I cannot get steady 1Hz pulse from the PIC :(
Chose modbus as the distances are long and there are always chances of lightning strikes.
I am also going green on this on by using solar cells to charge up a 7AH battery. _________________ Regards,
Devil |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Sun Aug 20, 2017 9:11 am |
|
|
Water flow sensors (cheap & reliable): https://www.seeedstudio.com/G1%262%22-Water-Flow-Sensor-p-635.html
I've used these before and they're very accurate. It creates a pulse for every rotation of its internal vane. Different sizes are available.
Use these and they will also solve your "run dry" problem. |
|
|
devilfrmheaven
Joined: 09 Feb 2016 Posts: 53
|
thanks New Guy |
Posted: Sun Aug 20, 2017 9:24 am |
|
|
We are using beefier one than this we are using 100 to 200 liters per minute ones.
Thanks _________________ Regards,
Devil |
|
|
devilfrmheaven
Joined: 09 Feb 2016 Posts: 53
|
Thanks for all your help! |
Posted: Tue Aug 22, 2017 1:46 pm |
|
|
Hi All,
I managed to put together all the interrupts and got it working, The PIC I chose was PIC16F73. There were some glitches that I faced.
I was using PORT B for everything
Quote: |
B0 - OUTPUT -> Waterpump SSR
B1 - TRIGGER -> Ultrasonic Sensor
B2 - ECHO -> Ultrasonic Sensor
B5 - WATERFLOW -> Flowsensor |
The output tend to pulse for 100ms in every second. could not set it steady no matter what I did.
After some thinking and head scratching I decided to move
B0 - OUTPUT -> Waterpump SSR -> PIN_A0
B1 - TRIGGER -> Ultrasonic Sensor -> PIN_A1
B2 - ECHO -> Ultrasonic Sensor - PIN_A2
Leaving the B5 only for the flow sensor, then all the things started working as expected.
Once again thank you all for your help. I have completed my project.
Hopefully the next post you see from me would be from the other side of the earth.
By the way anybody from Canada here? _________________ Regards,
Devil |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
Re: Thanks for all your help! |
Posted: Tue Aug 22, 2017 6:26 pm |
|
|
devilfrmheaven wrote: | By the way anybody from Canada here? |
Nice work, congratulations, and yes, I'm Canadian. Where are you moving? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Tue Aug 22, 2017 7:56 pm |
|
|
me too, Canadian, eh !!
west of Toronto,Ontario
Jay |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Tue Aug 22, 2017 8:43 pm |
|
|
Cost of living is very high there, but there honestly aren't many places in Canada that are inexpensive anymore. Best of luck to you! Welcome! |
|
|
devilfrmheaven
Joined: 09 Feb 2016 Posts: 53
|
newguy and Temtronic |
Posted: Thu Aug 24, 2017 8:35 am |
|
|
newguy and Temtronic I'm in Express entry pool now, waiting for the invitation.
Hopefully I would land by the end of winter... I would be at Toronto. _________________ Regards,
Devil |
|
|
|