Microprocessor programming

Thread Starter

yellowsub821

Joined Apr 26, 2010
5
Hello everyone, I'm doing a project right now in school that involves a microprocessor, and could use some help. The basic project is to control the humidity in a room via a humidity sensor circuit which is read in to the microprocessor, and then the humidifier is turned on/off based on a users input to the microprocessor (say 45% desired, must stay between 42-48%). The processor then automatically turns on/off when the correct percentages are reached.

Basically what I need help in is where to start on this code? I took a course in basic programming of the processor (I am using the MC9S08QG8) and kind of get the gist, but need a better place to start as this is pretty over my head. Are there any places online that you guys know of and use to get me started in assembly?
 

kingdano

Joined Apr 14, 2010
377
when i write code i always start like this:


1. create a flow chart/block diagram - this has no code on it, and is a visual aid for determining loops, and exit conditions within the program


2. for each block in the block diagram i write psuedo code (not real code, just describing line by line what the program should do)

once you have those things done (if they are done correctly) you should have a much easier time writing the code.

i am unfamiliar with your uC - so i cant help with the coding.

if you start with a flow chart i am sure people here will be willing to assist.

and a schematic of the board may help us as well.
 

Thread Starter

yellowsub821

Joined Apr 26, 2010
5
okay i wrote out a flow chart, and you're right i can see what i need to do much better now. i attached the flow chart i drew out, it seems to be right to me but maybe there's a loop or something i missed.

i'll write out the pseudo code in a bit, i have to run for now. also, what did you mean by a schematic of the board? the whole project? i have a high-level block diagram written out if that's what you were referring to. other than that i'm not sure, but let me know if anything else would help you guys out, and thanks
 

Attachments

davebee

Joined Oct 22, 2008
540
You'll probably want to add several time delays. After turning the humidifier on or off, how long does it take until the humidity sensor reads the changed humidity? Probably quite a few seconds or even minutes, I would guess.
 

Thread Starter

yellowsub821

Joined Apr 26, 2010
5
Yeah that's true, the sensor circuit takes ~a minute to relay the measured humidity. I'll probably implement delays in between readings to every three or four minutes to allow the circuit to reset and get a true reading.
 

kingdano

Joined Apr 14, 2010
377
Bear in mind, that sometimes writing a delay function in code is difficult - dont take it for granted.

Great job with the flow chart by the way, thats exactly what helps me.

:)
 

kingdano

Joined Apr 14, 2010
377
okay i wrote out a flow chart, and you're right i can see what i need to do much better now. i attached the flow chart i drew out, it seems to be right to me but maybe there's a loop or something i missed.

i'll write out the pseudo code in a bit, i have to run for now. also, what did you mean by a schematic of the board? the whole project? i have a high-level block diagram written out if that's what you were referring to. other than that i'm not sure, but let me know if anything else would help you guys out, and thanks
well since you will be talking to a sensor through a uC it may help someone familiar with the device to see what pins it is wired to etc. and also may help debug if you run into problems.

a high level block diagram is a start, but a detailed schematic would be best.
 

Thread Starter

yellowsub821

Joined Apr 26, 2010
5
okay the pseudo code is written, without any time delays though. i figure i'll get this working before i implement something on a higher level into the code. this looks pretty good to me, and i'll start to write out what i can in this code.

as far as a schematic goes, i attached the manual for the processor which has everything you could want to know about it. on page 20 is the mcu block diagram, and on page 24 is the pin assignments for the chip (we use the 16 pin chip, not the 8 pin).


edit: something i forgot to implement in the pseudo code, the sensor circuit has a switch that needs to be set to 'off' in order to read the current humidity, and back to 'on' for whenever it is not reading. ill post a block diagram of the sensor circuit so you can see what i mean.

edit 2: added the block for the sensor circuit, the control input off of R5 is the 'switch' i'm talking about, Vcc or floating for reading humidity and 0V for all other times. C1 is the humidity sensor, and obviously the freq out is the output of the humidity. it's an inverse relationship, the frequency decreases with increasing humidity.
 

Attachments

Last edited:

Thread Starter

yellowsub821

Joined Apr 26, 2010
5
pseudo code looks pretty well done to me - i am glad that my process was able to guide you somewhat.

good work!
Thanks, appreciate the help.

How do I write an if statement within an if statement? I wrote out something like this, but its not exactly an if in an if, if you follow me.


Rich (BB code):
IF:      LDA    P        
         CMP    Q        
         BGE    THEN        
ELSE:    BRA    SEQ1
THEN:    CMP    R        
         BLE    ENDIF        
         BRA    SEQ2
ENDIF:   BRA    START
where P,Q, and R are constants and SEQ1 and SEQ2 are lower routines in the code


edit: note that when i posted it all my spacing and lining for the code disappeared so it looks messy

edit 2: went to the code tag rather than quote, spacing should be good now
 
Last edited:

retched

Joined Dec 5, 2009
5,207
Use the CODE tags in stead of the QUOTE. When posting, click the 'Go Advanced' button.

In the 'Go Advanced' text editor, the '#' button will display CODE tags for you.

This should help with your formatting.
 
Top