Model Boat Mayhem

Please login or register.

Login with username, password and session length.
Pages: 1 [2] 3 4 5 6 7   Go Down

Author Topic: Help writing pic code  (Read 32020 times)

Time Bandit

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 175
  • Model Boat Mayhem is Great!
  • Location: Deizisau, Germany
Re: Help writing pic code
« Reply #25 on: August 08, 2014, 08:44:08 pm »

Stew,
 try to read and understand the code.
I tried to make it understandable.
After your answers it just needs some minor changes.
A few sentences deleted and some things im the setup mode changed.

The switch off after the setup has a reason. The chip likes a controlled complete shutdown to store the eeram correctly. If you e.g. have a short brownout before the shutdown it may be corrupted.
Thats why nearly everybody switches of power after writing on the non volatile memory during program exeution.

At least 47microFarad. The bigger the better  %%
But with a battery it's not so necessary. Low power BEC make the problems.

You should generally overthink what you want to do in the Future.
If it will be sound related or more complex controls e.g. real closed loop controls like a 360 degree schottel control the Picaxe will be too slow.
It's probably fast enough for the ABC but believe me this program is not even using 5% of the capability of the AVR.
For most RC tasks like mixers etc it's enough, but I would make my decision on 2 things and that's if real (internal or external) clocked timers and Interrupts are available on the Picaxe.
If not I wouldnt go for it. Without them none of my more complex progeams would work.

Logged
regards

Tobias

afb

  • FORGE ELECTRONICS
  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 64
  • more wires than wood in my boats!
  • Location: New Forest
    • FORGE ELECTRONICS
Re: Help writing pic code
« Reply #26 on: August 09, 2014, 01:26:56 am »

Tobias

There's no denying that the AVR is a superior chip, but just for the record the PICAXE does have interrupt capability. For timers you need to choose your chip carefully - for example the 20X2 has a full function hardware timer whereas the 20M2 has a software "time" variable which gives elapsed seconds only but is subject to errors if blocking commands are used (ie commands where the chip has to wait an indeterminate time for a user interaction)

Alan
Logged
in the land of the blind the one-eyed man is king

megatron

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 70
  • Location: North Shields
Re: Help writing pic code
« Reply #27 on: August 09, 2014, 08:18:55 pm »

Hi everyone
I'm off for a weeks camping in the Lake district, I'll see you all when I get back.
I hope Alan and Tobias don't come to blows before then.
Cheers
Stew
Logged

TurboTyne

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 115
  • Location: Newcastle upon Tyne, England
Re: Help writing pic code
« Reply #28 on: September 05, 2014, 08:15:44 pm »

Thought I'd just throw in my comments in case  it might help to hear another persons path into PIC programming. I have built a working cotrol system for a flash-steam boiler. When I started this project I had never heard of a microcontroller before. I bought a Pickit 3 programmer (about £35 when I bought it) a decent bread board (essential), a few PIC chips and downloaded the free and excellent programming suite from Microchip along with data sheets for the PICs. I bought a book on programming but it was not very much use. I find it very useful to work up the programmes as flow charts in powerpoint before writing any code. I've stuck to using assembler and have no plans to move to a higher level language since I can do everything I need and I like the feeling of knowing exactly what is going on and none of the programmes are what you could call very complicated.

In order to show that it is quite possible for a novice (with no electronics skills) to develop PIC circuits directly with unadulterated PIC devices this summarises part of my current system. There are 5 PICS (16F1827) that interact via I2C serial bus. One measures steam temperature using maths routines to convert amplified thermocouple output to degrees C and sends commands to the PIC controlling the fuel pump stepper motor to set its speed etc. Another PIC measures  water pump speed by timing the pulses from a Hall effect sensor on the pump shaft and it also controls the speed of this pump by PWM. Most of the PICs run at 16 MHz. Most of my boards are strip boards and I only ventured into etching a board when it came to the needs for analysing the thermocouple outputs.  It did take a bit or perseverence but I feel it was well worthwhile because of all the possibilities that are now opened up. I have no experience of using PICaxe chips but started looking at them once briefly and decided to go with the straight PICs. I'd be happy to offer advice if you ever decide to use PIC chips - but I'll be no use outside the assembler environment.

Reagrds  Mike
Logged

megatron

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 70
  • Location: North Shields
Re: Help writing pic code
« Reply #29 on: September 06, 2014, 12:36:51 pm »

Hi everyone,
I'm back after a well deserved extended holiday.

I've thought long and hard and decided I want to go down the PIC route using assembler.
It may not be the easiest or best method for this particular project but possibly the best for me and any future projects.

I'd like to welcome TurboTyne to the discussion, I'm sure you could be a big help to me.
I have a copy of PIC IN PRACTICE which takes you through several projects but doesn't explain things very clearly.
Which book did you start with and have you found any good tutorials?
I think I could work out the program side of it but may need help choosing the right PIC and configuring it

Stew
Logged

TurboTyne

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 115
  • Location: Newcastle upon Tyne, England
Re: Help writing pic code
« Reply #30 on: September 06, 2014, 04:53:59 pm »

Hi Stew

Happy to help if I can. Of course, there are bound to be other (and better ways) to do most things (i.e. i don't claim to be an expert).   I bought "The PIC microcontroller" by Morton and then picked up a used copy of "PIC in practice" by Smith. This was an ex-library copy (2nd edition) so may be an older edition than your book.

The Microchip website carries a wealth of info in the form of data sheets for each device, application notes with code examples for all sorts of applications and a forum for each broad class of PIC device where you can get advice and search for solutions to problems. This is also the place to download the MPLAB integrated developer environment. Also, I'm pretty sure there is a collection of tutorials on the MP website. Of great importance there are pages that summarise the properties of the large range of PIC devices.

It is a long while since I took my first steps but I think that I started out following some examples in one of those books whereby you write simple code to turn LEDs on and off, flash them and write code to eliminate switch bouncing pulses when using switches to alter binary inputs.  I started using a simple PIC16C54 chip but later wished that I'd used something with a wider range of functions. The 16F54 now sit in a box and will probably never be touched again - but they only cost a few pence each. Trouble is, with a more sophisticated chip there is the risk of info overload when you start out.  I now use 16F1826 or 16F1827and these devices costing a mere couple of quid need a 400 page data sheet to cover (in minimal detail) all their functionalities - that thought always impresses me.

Another key document on the MP site is the PICmicro Mid-Range MCU Family Reference Manual (about 600 pages long) (i.e. for the 16-bit or 16F class of PIC). There are many PICS that are much more sophisticated (18F etc) but 16F devices can do everything (and more) than I will ever need.

I guess you will make a list of the functions you need and then look at the list of features. Trouble is the number just of 16F devices is huge. I you go for a more complex device, you can ignore the features you don't currently require. While many aspects of PIC programming are common to all dvices, much detail is not common and firmware may have to be edited to make it work on a different device.

If the 16F1826/7 chips have all the functions you need, you could do worse than use them. They use the extended instruction set which is an advantage and is one of the reasons why code written for PICs without this feature may need to be alterred before it will run on them.

Sorry for going on so much - I got a bit carried away. If you want to post a list of the features you can envisage needing to use I'll be happy to offer an opinion. i.e. how many analogue and binary inputs, how many plain binary outputs, outputs to servos, PWM etc and any analogue outputs.

Regards

Mike
Logged

megatron

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 70
  • Location: North Shields
Re: Help writing pic code
« Reply #31 on: September 06, 2014, 05:21:51 pm »

Hi Mike
I don't want to run before I can walk so I want to use the simplest pic possible.
If I keep it very basic i think an 8 pin pic should do.
Inputs
pressure sensor; this will output half supply voltage when pressure reaches preset value, possibly analogue depending on how sensitive a/d converter is,(10 bit would be good), otherwise I may need to use external voltage comparator, then digital.
level sensor; if using 5v supply this will output approx 2v or 3v depending on water level. probably digital input.
pilot flame pot; 0 to 5v, analogue input.
calibration switch; on or off, digital input.

Outputs
2 x servo outputs.

I hope that makes sense.
Once I've mastered an 8 pin chip I may move to 14 pin and add some extra features, but that's in the future.

Stew
Logged

TurboTyne

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 115
  • Location: Newcastle upon Tyne, England
Re: Help writing pic code
« Reply #32 on: September 06, 2014, 10:54:00 pm »

Hi Stew

I realised I made an error in my previous post - 16F PICs are 8-bit, not 16-bit. (i.e. data is moved around as single bytes).

In response to your outline, I suspect that pin count is not directly related to complexity/ease of use.  The low pin count devices can be very cost-effective in a mass-produced product but might need more skilfully written compact code to fit their often smaller memory and they have no flexibility in pin useage.  Also, if you need an external crystal oscillator to time slow processes, then you use 2 more pins leaving just 4 for i/o functions.  The books I read use the 18-pin PICS in their starting projects. However, I am sure you will gain useful experience from a 8-pin (i.e. 12F) series PIC.

Looks like you are thinking of 2 analogue and two digital inputs plus 2 PWM outputs = 6 pins plus 0V and +5V    = 8 pins.
But that means you would have to use the same pins for programming. Life can be a little simpler if some of the ICSP (i.e. in circuit programming) connections are not used for other purposes.

I am wondering if you already have a pressure sensor. If so, I'd be interested to hear what type it is. I have one I bought a year ago but I still have not set it up. Yes, the PICs I use do have 10-bit A to D converter modules and you can choose to use an additional pin to input a reference voltage instead of comparing to +5V . That would mean yet another pin is needed.

I started following the book using the 18 pin 16F54 and soon migrated upwards to 16F818 and 16F819 (the same but with more memory). Then I needed some extra capability so started using the enhanced type of PIC 16F1826/7 (all 18 pins). With hindsight I wish I'd gone from 16F54 straight to the 16F1826.

Regards

Mike
Logged

TurboTyne

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 115
  • Location: Newcastle upon Tyne, England
Re: Help writing pic code
« Reply #33 on: September 07, 2014, 06:41:30 am »

One additional important reason for having more than the minimum number of pins is that an extra output or 2 to switch on/off LEDs can be invaluable when debugging your code. You insert comands to effect these switching operations at various points in the code to track down where the execution has reached before hitting a problem etc. Similarly an extra digital input to enable you to control code execution can also be invaluable. Remember, you can always ignore extra pins when they are not needed. 

Mike
Logged

megatron

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 70
  • Location: North Shields
Re: Help writing pic code
« Reply #34 on: September 07, 2014, 08:46:03 am »

Hi Mike
I've also made an error, The level sensor will need to be analogue.
The pressure sensor I've made is actually a temperature sensor (thermistor), as temperature increases so does pressure.
The main reason for choosing 8 pin was to make the circuit board design simpler as the enclosure I want to use is quite small.
I suppose I could try to do a layout using a 14 pin chip and see if it would fit. If you've used stripboard before you will appreciate how quickly you run out of holes.
I don't intend to do any in circuit programming and would like a pic with an internal oscillator.
I would also need a small amount of eeprom memory for calibrating the level sensor.

Stew
Logged

flashtwo

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 521
  • Location: Sevenoaks, Kent, England
Re: Help writing pic code
« Reply #35 on: September 07, 2014, 09:41:28 am »

Hi Stew,

I had to make the same decision when looking for a control system for my monotube boiler (see Flash Steam Boiler control thread). I didn't know how to control the boiler and wanted an easily adaptable system that didn't need rebuilding as with a mechanical system, or resoldering with electronics; therefore a PIC based system allowed lots of changes to be made without resorting to the soldering iron.

The servo jittering problem that's been mentioned is typical of pre-written software that works in isolation, but has problems in incorporating with other code. Writing your own code gives you complete control over interfacing with the real world without having to make compromises using other peoples code. I also used Assembler throughtout  - I didn't buy any programing books, I just used Microchips data sheets for the particular PIC being used, plus a bit of internet research.

If you take Mike's approach and gradually work up by switching an LED on/off using a switch, then perhaps a potentiometer giving an analogue input that is limit tested to switch an LED on/off, then using Timers with interrupts doing the same job, you'll be well underway in understanding the system. Don't be put off by interrupts they do a wonderful job - just make sure that the interrupt handler is the first bit of code in your program (but we'll get to the detail when you need further advice).

A couple of DOs  - DO give your code a Version number. Your code will usually be a development of an existing one and, at the top of your code, keep a record of the version number and the reasons for the new version. DO put lots of comments with your code explaining what your are trying to achieve.

Regarding the use of thermistors - I haven't used them for years, but I now understand they are quiet accurate, do they cover the range of boiler temperatures up to 70psi?

Once you've produced some "standard" code you can then use it in other projects.

Ian

Logged

TurboTyne

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 115
  • Location: Newcastle upon Tyne, England
Re: Help writing pic code
« Reply #36 on: September 07, 2014, 10:08:27 am »

Hi Mike
I've also made an error, The level sensor will need to be analogue.
The pressure sensor I've made is actually a temperature sensor (thermistor), as temperature increases so does pressure.
The main reason for choosing 8 pin was to make the circuit board design simpler as the enclosure I want to use is quite small.
I suppose I could try to do a layout using a 14 pin chip and see if it would fit. If you've used stripboard before you will appreciate how quickly you run out of holes.
I don't intend to do any in circuit programming and would like a pic with an internal oscillator.
I would also need a small amount of eeprom memory for calibrating the level sensor.

Stew

Hi Stew

Do you know which programmer you will use? I don't know how much you've read already and I've only ever used ICSP (with a Pickit 3), but, as I understand things, a BIG advantage of ICSP is the ability to very quickly edit the code, re-programme the PIC and test it without repeatedly moving the PIC between programmer and circuit.  This avoids risk of physical and static damge to the PIC and frustration to the user, bearing in mind that you will need to repeat this cycle of edit-programme-test many dozens (hundreds) of times. Obviously I don't know your space restrictions etc but since the physical size of the PIC is an issue, one way forward you could consider is using a larger and more flexible device to learn with and to develop your firmware  - using ICSP. Presumably you'll start out on a breadboard. Then, once things look good, you could try changing to a smaller PIC of the same basic structure, since, by then you will hopefully only need to make minor tweaks to the code to make it compatibe with the new chip. But, once you get into this field I bet you'll realise that you will want to be able to make adjustments to various aspects of the programme. After all, a big advantage of microcontrollers is this very ability to alter the way a system responds without using a soldering iron.

It was Ian's posts that got me into PIC programming and his advice about version numbers is spot on. I do my best to keep things organised but, sadly, I've lost track of the time I've wasted working out which version of firmware I should be using for the next round of editing.

The rewards for mastering this technology are great so don't be put off by that steep learning curve.

Regards
Mike
Logged

megatron

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 70
  • Location: North Shields
Re: Help writing pic code
« Reply #37 on: September 07, 2014, 01:01:08 pm »

Ian, the thermistors I'm using are good for 300degC so can easily cope with the temp in our boilers. They are made by ATC Semitec.

Mike, the programmer I have is a PIC K150, a cheap chinese jobby but it seems to work ok. It has a ZIF socket and I will use a ZIF socket on my prototype board as well.
I have a couple of pic16f627a chips which I could use to get started then as you say port it over to a smaller chip.

Stew
Logged

TurboTyne

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 115
  • Location: Newcastle upon Tyne, England
Re: Help writing pic code
« Reply #38 on: September 08, 2014, 06:22:31 am »

Hi Stew

Sounds like a good plan. I hope you'll let us know how you get on. I'll be interested to hear more about your boiler control system.
As Ian said, let us know if you have further questions as and when ....

There is no shortage of web pages about PIC programming out there. I came across this one and mention it here because, in addition to introductory guidance about PIC programming, it also gives links to what seem to be simple home-made programmers / in-circuit programmers. I only looked at this stuff very briefly so have no idea how good it all is.

http://www.markhennessy.co.uk/pic/

Good luck with the PICs,   Mike
Logged

megatron

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 70
  • Location: North Shields
Re: Help writing pic code
« Reply #39 on: September 14, 2014, 07:53:52 pm »

Hi
A question for Mike or Ian.
I have a rough idea of how the program will work but I am short of a couple of pieces of code.

The pic will be running at 8Mhz and I need some code to produce a 1ms delay, that's the easy bit.

I will have a pot connected to 1 of the analogue inputs which will supply from 0 to 5v(supply voltage). I want to use this to produce a delay of 0 to 0.1ms. I don't need 10bit resolution so would I be able to use say the 4 or 5 most significant bits to create a loop? and if so how? The times don't have to be exact, within 2 or 3% would do.

I also need to know how to use a timer to count to 20ms.
The pic I think I'll be using is a pic16f684.

hope you can help
Stew
Logged

TurboTyne

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 115
  • Location: Newcastle upon Tyne, England
Re: Help writing pic code
« Reply #40 on: September 15, 2014, 08:44:11 am »

Hi Stew
I'm writing this from android tablet so find it easiest to attach a couple of pdf files.

No doubt others can suggest some cleverer trcks but these suggestions should work.
I hope they make sense.

Regards   Mike
Logged

TurboTyne

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 115
  • Location: Newcastle upon Tyne, England
Re: Help writing pic code
« Reply #41 on: September 15, 2014, 09:26:29 am »

Jusr realised that I was not thinking straight before. Should have said to set AD conversion to give left justified result and then just use the upper byte of the result. I.e. don, t need to use rotate etc.
Mike
Logged

megatron

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 70
  • Location: North Shields
Re: Help writing pic code
« Reply #42 on: September 15, 2014, 10:24:10 am »

Hi Mike
It will take me a little while to get my head around this but am I right in thinking that you are using tmr1 for both these delays? I would like the 2 timings to run independently of each other. e.g.

Start timer-->check pressure-->turn on servo1-->either (1ms delay + 0-0.1ms variable delay) or (1ms delay + 1ms delay)--> turn off servo1-->check boiler level-->turn on servo2-->either (1ms delay) or (1ms delay +1ms delay)-->turn off servo2-->wait until timer = 20ms-->clear timer-->goto start

hope that makes sense.

regards
Stew

P.S. As we live close to each other could we meet up and talk this over with a pint or two. I could show you the system I've already built.
Logged

flashtwo

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 521
  • Location: Sevenoaks, Kent, England
Re: Help writing pic code
« Reply #43 on: September 15, 2014, 10:56:13 am »

Hi Stew,

Based on the PIC 16F 684.

Please tell us if we are “teaching grandma to suck eggs” and there are many solutions to a problem – this is my version.

Have you considered a device frequency (Fosc) of 4MHz (4Mhz crystal).

If you look at the data sheet Figure 5-1, the Timer can use the internal clock which is Fosc/4 which then increments the Timer every microsecond ( 1us) if Fosc is 4Mhz.

Incrementing Timers by 1us becomes very useful when working with the servos, which use the 1 to 2ms PWM signal (i.e. 1000 to 2000us).
When programing, we will be using 3 bases decimal, binary and Hexadecimal – therefore d, b or h after a number stops any confusion.

This solution is to give the potentiometer complete mechanical movement a range of 0 to 0.127ms.

Now, if we want a 0 to 0.1ms delay, we need to load a number between 0 and 100d into the timer (assuming a 4MHz frequency – 1us clock). The Timers actually count up to zero (the overflow condition) and then issue an interrupt to say that they’ve arrived at zero.

Now Timer0 is an 8 bit register, and therefore can represent a number of the range 0 to 255d (it is very useful to have a calculator than can switch between decimal, binary and Hex). Since the Timer counts up to zero, we must initially set it to 155d for a 100us delay (see Paragraph 5.1.1 note about the two instruction delay if we want to be really accurate). You will notice that the Timer is set to the equation “255d minus delay”.

The Timer0 then increments every clock pulse to 255d and then overflows to zero and issues the interrupt.

To reiterate what Mike has said…

The analogue input value, as you can see from Fig. 9.3, arrives at two registers ADRESH and ADRESL containing the highest 8 bits of the analogue value in the first register and the lowest 2 bits in the second register – if ADFM is set to zero.

We just have to “right shift” the register once to get a value of 0 – 127d, which can go into the Timer equation above. Set bit 8 of ADH to zero in case the carry from bit 0 is 1.

First move the value of ADRESH into your own registers, say, ADH. This avoids the possibility of ADRESH changing during your conversion.
Little register sketches appear at this stage!

Now in ADH you have the value to be subtracted from 255d before it sets the Timer.

Referring to the instruction set Table 13.2 – then are plenty of logical operators like “RRF” right rotate and “BTFSS”, which can be used to reduce the 10bit analogue value into a 7 bit value that can be used in the Timer equation.  You can also get your teeth into “SUBWF” for the subtraction process.

I hope this points you in the right direction. It can be a bit (excuse pun!) of a challenge to start with, but each instruction mastered is like adding another spanner to the tool kit!

Ian
Logged

megatron

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 70
  • Location: North Shields
Re: Help writing pic code
« Reply #44 on: September 15, 2014, 11:53:29 am »

Hi Ian

Firstly I am happy to use whichever frequency is best.

A delay of 0-0.127ms would be quite alright.

Am I right in thinking that I would use tmr0 for the variable delay and tmr1 for the 20ms delay?

In summary I would read the value of ADRESH, place it into a user register ADH, rotate right and clear bit7. Subtract this from 255D and use this for the starting point of the timer.

Please note that my head is now spinning a lot faster than 50hz.

regards
Stew
Logged

flashtwo

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 521
  • Location: Sevenoaks, Kent, England
Re: Help writing pic code
« Reply #45 on: September 15, 2014, 01:19:10 pm »

Hi Stew,

I do wonder if we're trying to crack a nut with a sledgehammer.

If you are using this project to understand PICs or other types of modern controllers, then that is fine - it can open up a whole range of uses.

I'm not familiar with the Cheddar ABC unit nor what servo 1 and 2 are doing. Would it be possible for a brief description? - I've looked on the internet but couldn't find anything.

Why did your control box end up much bigger than the Cheddar original? Could different chips/relays be used?

Ian
Logged

megatron

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 70
  • Location: North Shields
Re: Help writing pic code
« Reply #46 on: September 15, 2014, 02:12:24 pm »

Hi Ian
A brief description of the Cheddar ABC.
There are 3 sensors
1; optical sensor to detect water in the sightglass
2; temperature sensor to sense boiler pressure
3; water level sensor to detect water in the feed tank

there are 2 servos
1; operates gas valve
2; operates water bypass valve

The unit is designed to operate with an engine driven water pump. This pump operates continually pumping water to a t-piece. 1 leg of the t-piece connects to the boiler via a non return valve, the other leg of the t-piece connects to a bypass valve. When the bypass valve is open the water is pumped back to the tank. When the bypass valve is closed the water is forced into the boiler.
When the optical sensor sees water in the sightglass the bypass valve is opened, when no water is seen the bypass valve is closed.

The gas is controlled using a double gas valve, this controls the main flow of gas to the burner and also supplies a small amount of gas to allow the flame to burn with a small pilot flame, the pilot flame is adjustable via a screw on the gas valve.
If the temperature of the boiler is below a preset level (adjustable with a pot) the gas valve is opened, if the boiler temperature is above the preset level the valve is closed and the flame is reduced to a pilot flame.

The water in the feed tank is also monitored so that if the water drops below a certain point the water bypass valve is held in the open position and a warning lamp is lit. This prevents the water pump running dry and destroying itself. The gas valve is not affected as you still need steam pressure to get the boat back.

My system uses a single gas valve with the pilot flame being controlled by a pot, hence the need for a variable delay.

The Cheddar system is much smaller than mine because they use a chip similar to a pic to control everything and it is built on a bespoke PCB. Mine was built using only passive components on stripboard. They both give pretty much the same result, but I want to make mine smaller.

Hope that's clear
Stew
Logged

TurboTyne

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 115
  • Location: Newcastle upon Tyne, England
Re: Help writing pic code
« Reply #47 on: September 15, 2014, 06:43:27 pm »

Hi Stew
Re: meeting up, yes, I'd like to see your set up - maybe we can arrange something via PM etc.

As Ian has already said, you would need to use 2 timers for this, not just TMR1 and his method of exploiting the interrupt upon roll over of each timer is certainly the way to go. I have never used a servo but your scheme seems ok. to me although as Ian said , using PWM outputs would be an alternative although l think you would need a different PIC with 2 PWM modules.

I assume that the output from your water level gauge is just full on or full off. If so, does the by pass valve get opened and closed very frequently?  I was wondering if there might be a need or possibility of some sort of control that moves the by-pass valve to an intermediate position rather than keep oscillating between full open and full shut.

Final question, how does temperature error adjust gas valve position ? i.e. what computation ?
Regards Mike

Logged

flashtwo

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 521
  • Location: Sevenoaks, Kent, England
Re: Help writing pic code
« Reply #48 on: September 15, 2014, 06:54:23 pm »

Hi Stew,

Thanks for the Cheddar description.

Are the valves operated by servos (requiring PWM) or solenoids (requiring a relay contact), i.e. just open/closed with nothing in between?

Ian.
Logged

megatron

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 70
  • Location: North Shields
Re: Help writing pic code
« Reply #49 on: September 15, 2014, 07:21:33 pm »

Hi Mike
When you ask about the water level sensor I assume you mean the sightglass sensor for the boiler. This sensor gives an output of approx 2v when water present and 3v when no water present, this would need to go to an analogue input and will need calibrating occasionally ( but that's another story). On the system I have built the servo is only operated if there is no water detected for 10 seconds. This is to prevent the servo operating when the water is sloshing about. Again this will have to be implemented somehow, but I was trying to keep the program as simple as possible to begin with. I think it would be very difficult to alter the bypass valve to give exactly the right flow.
The pressure is regulated just like a thermostat, if the voltage from the sensor is below 1/2 supply voltage the gas is turned off and if above the gas is turned on. This needs to be very tight as just a few mV difference will alter the pressure by a couple of psi.
cheers
Stew
Logged
Pages: 1 [2] 3 4 5 6 7   Go Up
 

Page created in 0.11 seconds with 22 queries.