readadc10 troubles!

Andie

Member
hello,

I have been using the readacd command in my programme and it works fine for the 4V-12V inputs i was using it for.

However, a new input that i need to be measured by my chip is only 0.35V and readacd cant detect this voltage.

I have been advised to use readacd10 to get the resolution i need, however im pretty clueless how to do this.

Here is the current code
Code:
	input b.6	;Fan input
main: readadc10 b.6,b1
	if b1 < 2 then goto redb ; move to redb to turn red light on when the extraction tube stops
redb: low b.1 ; green light off
	high b.2 ; red light on
	serout b.0,N2400, (254,1)
	pause 30
	serout b.0,N2400, (254,134,"Fan") ; display "extraction fan not working" on OLED screen
	pause 500 ; pause for 1 second
	readadc b.6,b1
	if b1 > 2 then goto main ; start program again if the extraction fan starts working again
	goto redb ; start again
i would like to make my OLED screen display "Fan" when the input is less than 0.35V, but alas i require some assistance!

I'm using an 18M2 chip.

Thanks in advance and sorry if this isnt very clear.

A
 
Last edited by a moderator:

Andie

Member
thank you for the quick reply!

ah okay shall do.

also, sorry for quoting the code, and not wrap code-ing it, misclick.
 

premelec

Senior Member
Note that .35 volts with 5 volt reference would read about 72 - also take a look at FVRSETUP to use lower reference voltage...
 
Last edited:

Andie

Member
i have improved the design of my air intake system and my fan can now give out 0.8volts.. Will this help at all?

and with the FVRSETUP command, how will this benefit ?
 

nick12ab

Senior Member
However, a new input that i need to be measured by my chip is only 0.35V and readacd cant detect this voltage.

I have been advised to use readacd10 to get the resolution i need, however im pretty clueless how to do this.
It works like the readadc command except you use a word variable as the value returned by readadc goes up to 1023 instead of 255. This quadruples the resolution.

and with the FVRSETUP command, how will this benefit ?
It sets the voltage that represents 1023 and proportionally adjusts all the others as well. For example if the maximum voltage going into the ADC pin is 2V then the 2.048V voltage reference can be used for 1023 hence improving resolution because most of the scale is now used for the entire input range rather than only a small part of the scale.
 

Andie

Member
Thank you very much for explaining, I shall get to work experimenting with this.

On a different note, my fan is 5V. If i use a 12V fan with the same air flow, would i get a larger voltage output? Because if so, then everything will be much easier!

A
 

nick12ab

Senior Member
On a different note, my fan is 5V. If i use a 12V fan with the same air flow, would i get a larger voltage output? Because if so, then everything will be much easier!
Can you say more about your fan? What model is it? Are you sure it has an analogue output and not a PWM one?
 

Andie

Member
Sorry if i didnt make it clear originally - Im using an air extractor as part of the system. This fan sits in the suction air flow created by the external air extractor. The fan gives out a DC voltage of 0.8V.
 

SAborn

Senior Member
To be honest i dont see how that fan will work as a generator at all without it being modified.

I think you will find its a 3 phase motor wired in star, for this to be driven off a DC supply (as a fan) a drive circuit is required, the drive circuit will prevent power generated from flowing back out the leads when the motor is used as a generator.

It can be done if the fan is disassembled and the wiring changed, with the 3 stator wires being extended and brought out of the motor, the motor then will be a 3 phase alternator making AC power, that will need to be fed through a 3 phase rectifier (6 diodes) to produce a DC voltage output.
Now you have a DC voltage to work with, but be warned it is not limitted to only 5 volts max and the faster it spins the higher the voltage and the greater the current produced.

Perhaps if you search the net for "computer fan wind generators" or other similar topics you will find details on the mods needed to make this work.
I did do some tests on this a few years back for a Indian student to help with his project of charging a mobile phone from a computer fan while travelling on a train.
I dont recall all the details now, but it did need a wind speed over 100kmh to reach cutin voltage to the battery before any charge would flow.
 

JimPerry

Senior Member
Sorry if i didnt make it clear originally - Im using an air extractor as part of the system. This fan sits in the suction air flow created by the external air extractor. The fan gives out a DC voltage of 0.8V.
Are you by any chance using a computer fan with 3 leads? The 3rd lead on these outputs a speed signal - which you may be reading as a DC voltage - it's not! :confused:

Whoops - just read Nic12ab's posts
 
Last edited:

SAborn

Senior Member
On further inspection it was not a 3 phase motor in those fans, its a 4 coil iron core motor so you will need 8 diodes to rectifie the AC.

Internal shot of the motor here.

Fan motor.JPG
 

nick12ab

Senior Member
me neither, but it does.. It does everything you've said after modifications, without doing anything to it.
The fan will have a driver circuit that's only meant to convert DC into whatever the fan uses, not the other way round. If you use that fan as a generator, it will be a very rubbish one.
 

SAborn

Senior Member
It does everything you've said after modifications, without doing anything to it
That is simply not possible, unless you think 0.8v is a exceptable output, and from your question of using a 12v or 5v motor for greater output, i would take it you have little idea of what you are doing with your current methods.

This looks like another thread where the person asking the questions think they know more then we do, so why are we bothering to try to help you with advice.

Perhaps you should research how a brushless motor works, then you could have some idea of how you can use it, and what is needed to achieve it.
 

AllyCat

Senior Member
It does everything you've said after modifications, without doing anything to it.
Hi,

But your statement back at #1 suggests that it doesn't:

a new input that i need to be measured by my chip is only 0.35V and readacd cant detect this voltage.
A PICaxe should be able to easily detect 0.35 volts even with 8-bits readadc, which suggests that your measuremement is at fault. What is measuring the "0.35 volts" and is that across the +/- pins of the fan or the "tacho" signal?

Cheers, Alan.
 

hippy

Ex-Staff (retired)
To be honest i dont see how that fan will work as a generator at all without it being modified.
me neither, but it does.. It does everything you've said after modifications, without doing anything to it.
Well, perhaps, but not generating the level of voltage that a modified fan would produce.

Of course, it may be that what the fan puts out is good enough for what you want it to do. It might be worth explaining exactly what you want, just a simple indication that the fan is turning, or something that indicates how fast it is turning ?

As AllyCat notes the PICAXE should be able to recognise a 0.35V signal, and it appears you have a 0.8V signal now. So perhaps the question is; are we simply trying to get the PICAXE to recognise a 0.35V or 0.8V signal or something else or more ?

Assuming the fan doesn't give out a voltage when stationary, gives 0.2V or more when activated, the following code should work ...

Code:
Do
  ReadAdc FAN_INPUT, b0
  If b0 > 10 Then
    SerTxd( "Fan Turning", CR, LF )
  Else
    SerTxd( "Fan Stopped", CR, LF )
  End If
  Pause 1000
Loop
 

Andie

Member
im sorry for offending you SAborn, i was just saying that i am getting an ouput, and yes 0.8V is acceptable.

Without you guys helping as you do it would take so much more time to get what i need from the internet.

Sorry again
 

Andie

Member
okay hibby your code didnt work..

it may be because i didnt originally post all of my code and therefore you didnt get enough information, i dont know..

here is my full code:

Code:
input b.7	;Current input
input b.6	;Fan input
input b.5	;Stirrer input

main: readadc b.7,b0
	readadc b.6,b1
	readadc b.5,b2
	if b0 > 2 then goto reda ; move to reda to turn red light on when the current stops
	if b1 < 2 then goto redb ; move to redb to turn red light on when the extraction tube stops
	if b2 > 2 then goto redc ; move to redc to turn red light on when the magnetic stirrer stops
	low b.3 ; blue light off
	low b.2 ; red light off
	high b.1 ; green light on
	serout b.0,N2400, (254,1)
	pause 30
	serout b.0,N2400, (254,129,"All systems OK") ; display "all systems OK" on OLED screen
	pause 500 ; pause for 1 second
	goto main ; start again
	
reda: low b.1 ; green light off
	high b.2 ; red light on
	serout b.0,N2400, (254,1)
	pause 30
	serout b.0,N2400, (254,133,"Current") ; display "current off" on OLED screen
	pause 500; pause for 1 second
	readadc b.7,b0
	readadc b.6,b1
	readadc b.5,b2
	if b1 < 2 then goto reda1 ; move to reda1 to keep red light on if extraction tube also stops
	if b2 > 2 then goto reda2 ; move to reda2 to keep red light on if magnetic stirrer also stops
	if b0 < 2 then goto main ; start program again if the current returns
	goto reda ; start again
	
reda1:serout b.0,N2400, (254,1)
	pause 30
	serout b.0,N2400, (254,129,"Current and fan") ; display "current off and extraction fan not working" on OLED screen
      pause 500 ; pause for 1 second
      readadc b.7,b0
      readadc b.6,b1
	readadc b.5,b2
	if b2 < 2 then goto blue ; move to blue to turn blue light on if the magnetic stirrer also stops
	if b0 < 2 then goto main ; start program again if the current returns
	if b1 > 2 then goto main ; start program again if the extraction fan starts working again
	goto reda1 ; start again
	
reda2:serout b.0,N2400, (254,1)
	pause 30
	serout b.0,N2400, (254,130,"Current and") ; display "current off and magnetic stirrer not working" on OLED screen
	serout b.0,N2400, (254,196,"stirrer")
      pause 500 ; pause for 1 second
      readadc b.7,b0
      readadc b.6,b1
	readadc b.5,b2
	if b1 < 2 then goto blue ; move to blue to turn blue light on if the extraction fan also stops
	if b0 < 2 then goto main ; start program again if the current returns
	if b2 < 2 then goto main ; start program again if the magnetic stirrer starts working again
	goto reda2 ; start again
	
redb: low b.1 ; green light off
	high b.2 ; red light on
	serout b.0,N2400, (254,1)
	pause 30
	serout b.0,N2400, (254,134,"Fan") ; display "extraction fan not working" on OLED screen
	pause 500 ; pause for 1 second
	readadc b.7,b0
	readadc b.6,b1
	readadc b.5,b2
	if b0 > 2 then goto redb1 ; move to redb1 to keep red light on if current also stops
	if b2 > 2 then goto redb2 ; move to redb2 to keep red light on if magnetic stirrer also stops
	if b1 > 2 then goto main ; start program again if the extraction fan starts working again
	goto redb ; start again
	
redb1:serout b.0,N2400, (254,1)
	pause 30
	serout b.0,N2400, (254,129,"Current and fan") ; display "current off and extraction fan not working" on OLED screen
      pause 500 ; pause for 1 second
      readadc b.7,b0
      readadc b.6,b1
	readadc b.5,b2
	if b2 > 2 then goto blue ; move to blue to turn blue light on if the magnetic stirrer also stops
	if b0 < 2 then goto main ; start program again if the current returns
	if b1 > 2 then goto main ; start program again if the extraction fan starts working again
	goto redb1 ; start again
	
redb2:serout b.0,N2400, (254,1)
	pause 30
	serout b.0,N2400, (254,129,"Fan and stirrer") ; display "extraction fan and magnetic stirrer not working" on OLED screen
      pause 500 ; pause for 1 second
      readadc b.7,b0
      readadc b.6,b1
	readadc b.5,b2
	if b0 > 2 then goto blue ; move to blue to turn blue light on if the current also stops
	if b1 > 2 then goto main ; start program again if the extraction fan starts working again
	if b2 < 2 then goto main ; start program again if the magnetic stirrer starts working again
	goto redb2 ; start again
	
redc:	low b.1 ; green light off
	high b.2 ; red light on
	serout b.0,N2400, (254,1)
	pause 30
	serout b.0,N2400, (254,132,"Stirrer") ; display "magnetic stirrer not working" on OLED screen
	pause 500 ; pause for 1 second
	readadc b.7,b0
	readadc b.6,b1
	readadc b.5,b2
	if b0 > 2 then goto redc1 ; move to redc1 to keep red light on if current also stops
	if b1 < 2 then goto redc2 ; move to redc2 to keep red light on if extraction fan also stops
	if b2 < 2 then goto main ; start program again if the magnetic stirrer starts working again
	goto redc ; start again
	
redc1:serout b.0,N2400, (254,1)
	pause 30
	serout b.0,N2400, (254,130,"Current and") ; display "current off and magnetic stirrer not working" on OLED screen
	serout b.0,N2400, (254,196,"stirrer")
	pause 500 ; pause for 1 second
      readadc b.7,b0
      readadc b.6,b1
	readadc b.5,b2
	if b2 > 2 then goto blue ; move to blue to turn blue light on if the extraction fan also stops
	if b0 < 2 then goto main ; start program again if the current returns
	if b1 > 2 then goto main ; start program again if the magnetic stirrer starts working again
	goto redc1 ; start again
	
redc2:serout b.0,N2400, (254,1)
	pause 30
	serout b.0,N2400, (254,129,"Fan and stirrer") ; display "extraction fan and magnetic stirrer not working" on OLED screen
      pause 500 ; pause for 1 second
      readadc b.7,b0
      readadc b.6,b1
	readadc b.5,b2
	if b0 > 2 then goto blue ; move to blue to turn blue light on if the current also stops
	if b1 > 2 then goto main ; start program again if the extraction fan starts working again
	if b2 < 2 then goto main ; start program again if the magnetic stirrer starts working again
	goto redc2 ; start again
	
blue: low b.2 ; red light off
	high b.3 ; blue light on
	serout b.0,N2400, (254,1)
	pause 30
	serout b.0,N2400, (254,132,"Finished") ; display "finished" on OLED screen
	pause 800 ; pause for 3ms
	readadc b.7,b0
	readadc b.6,b1
	readadc b.5,b2
	if b0 < 2 and b1 > 2 and b2 < 2 then goto main ; if all three components start working again start program from beginning
	goto blue ; start again
the current and stirrer voltages will always be more than 5V, but its the fan current that is only 0.8V.

all of you have said that readadc can easily read 0.8V but i cant figure out how to tell it to!

so please help :(

thank you
 

SAborn

Senior Member
Try this and see what ADC values show in b0, b1, b2

Code:
main:
             readadc b.7,b0
	readadc b.6,b1
	readadc b.5,b2
             debug
             pause 500
             goto main
 

Andie

Member
At 2v:
b0 0
b1 0
b2 0

At 1V
b0 5
b1 3
b2 75

At 0.9V
b0 54/55
b1 48/49
b2 223

At 0.8V
b0 255
b1 225/226
b2 247

At 0.7V its the same as 0.8V.

Is this what you were asking for?

cheers
 
Last edited:

SAborn

Senior Member
b0 is your fan input and for some reason it looks to be counting backwards, all very wierd.

The adc value should count up as the adc pin voltage increases, 0v = 0 adc, 5v = 255 adc.
So why is b0 = 0 at 2 volts and b0 = 255 at 0.8 volts.
All i can think of is your circuit is not correct or you have the pins messed up, as the data given dont make sense to the input voltages.
 

Andie

Member
im pretty sure that b1 is my fan input?

Code:
input b.7	;Current input
input b.6	;Fan input
input b.5	;Stirrer input

main:     readadc b.7,b0
	readadc b.6,b1
	readadc b.5,b2
hmm well i could check all my wiring but that would take way more time than i have available.

is there a way for me to programme my chip with the adc's acting like they are?
 

Andie

Member
also, between 0.91V and 0.89V the adc values of b0 and b1 go from 20something to 220something..

very confused.
 

rossko57

Senior Member
Have you been able to check your fan "output" with a scope? It's very likely to consist of pulses varying in width, level and frequency which the ADC won't be very good at reading. Maybe you can add a series resistor and a capacitor across your "sense" wires to produce an average.
 

Andie

Member
i havent been using my actual fan/current/stirrer voltage inputs for these adc readings. i just connected the three input cables to the same power pack. Meaning all three values should be the same.

at the moment i am making another circuit with nothing but the 3 input cables, V+ and V0 to the chip. and hopefully this will work fine meaning all my previous circuitry is somewhere bodged.

i shall check my fan output with a scope. the air flow is incredibly stable though and constant, but i will be sure to look for these pulses

thanks
 

Andie

Member
i hooked up my 3 inputs to chip along with V+ and V0.

SAborn -> the ADC values were all the same, and all increased as voltage increased. So my circuitry is somewhere wrong/ a component has fried.

Thank you very much for helping and i will post back results.

A
 

Andie

Member
Finished!

You guys probably don't care anymore, but i have got it all to work :D

Had to change some components and wiring, and also the code.. a lot..

but here it is if youre interested :)

Code:
input c.2	;Current input
input c.1	;Fan input
input c.0	;Stirrer input



main:  readadc c.2,b2
       readadc c.1,b1
       readadc c.0,b0
       if b2 < 40 and b1 < 40 and b0 < 40 then goto blue ; if all three inputs are off then go to blue
       if b2 < 40 and b1 < 40 and b0 > 40 then goto candf ; if c and f are off then go to candf
       if b2 < 40 and b1 > 40 and b0 < 40 then goto cands ; if c and s are off then go to cands
       if b2 > 40 and b1 < 40 and b0 < 40 then goto fands ; if f and s are off then go to fands
       if b2 > 40 and b1 > 40 and b0 < 40 then goto reds  ; if s is off then go to reds
       if b2 > 40 and b1 < 40 and b0 > 40 then goto redf  ; if f is off then go to redf
       if b2 < 40 and b1 > 40 and b0 > 40 then goto redc  ; if c is off then go to redc
       if b2 > 40 and b1 > 40 and b0 > 40 then goto green ; if all on then go to green
       
green: low b.3 ; blue light off
	 low b.2 ; red light off
	 high b.1 ; green light on
	 serout b.0,N2400, (254,1)
	 pause 30
	 serout b.0,N2400, (254,129,"All systems OK") ; display "all systems OK" on OLED screen
	 pause 500 ; pause for 1 second
       goto main ; start again
       
redc:  low b.1 ; green light off
	 high b.2 ; red light on
	 serout b.0,N2400, (254,1)
	 pause 30
	 serout b.0,N2400, (254,133,"Current") ; display "current off" on OLED screen
	 pause 500; pause for 1 second
       goto main ; start again
	
redf:  low b.1 ; green light off
	 high b.2 ; red light on
	 serout b.0,N2400, (254,1)
	 pause 30
	 serout b.0,N2400, (254,134,"Fan") ; display "extraction fan not working" on OLED screen
	 pause 500 ; pause for 1 second
       goto main ; start again
	
reds:  low b.1 ; green light off
	 high b.2 ; red light on
	 serout b.0,N2400, (254,1)
	 pause 30
	 serout b.0,N2400, (254,132,"Stirrer") ; display "magnetic stirrer not working" on OLED screen
	 pause 500 ; pause for 1 second
       goto main ; start again
	
fands: serout b.0,N2400, (254,1)
	 pause 30
	 serout b.0,N2400, (254,129,"Fan and stirrer") ; display "extraction fan and magnetic stirrer not working" on OLED screen
       pause 500 ; pause for 1 second
       goto main ; start again
	
cands: serout b.0,N2400, (254,1)
	 pause 30
	 serout b.0,N2400, (254,130,"Current and") ; display "current off and magnetic stirrer not working" on OLED screen
	 serout b.0,N2400, (254,196,"stirrer")
	 pause 500 ; pause for 1 second
       goto main ; start again
	
candf: serout b.0,N2400, (254,1)
	 pause 30
 	 serout b.0,N2400, (254,129,"Current and fan") ; display "current off and extraction fan not working" on OLED screen
       pause 500 ; pause for 1 second
       goto main ; start again
	

blue:  low b.2 ; red light off
	 high b.3 ; blue light on
	 serout b.0,N2400, (254,1)
	 pause 30
	 serout b.0,N2400, (254,132,"Finished") ; display "finished" on OLED screen
	 pause 800 ; pause for 3ms
       goto main ; start again
thanks again for being so helpful and knowledgeable etcetc,

i will be recommending picaxe to everyone i meet!

A
 

SAborn

Senior Member
Its nice to have a report of a successfull result, many dont report their success and we never know if our assistance has been of help, often after lots of free time devoted by several members.

Good luck with your next picaxe project, and guessing we will hear from you when the good luck runs out.
 

AllyCat

Senior Member
You guys probably don't care anymore, ...... Had to change some components and wiring, and also the code.. a lot..
Hi Andie,

Yes, thanks for the feedback, and we DO care!

However, 4 or 5 of us suspected that a normal computer fan wouldn't generate a satisfactory voltage as a "generator", were we wrong? If so we'd like to give the "correct" information next time. Which components did you need to change and do you have a circuit diagram?

Despite the topic header, I don't see any readadc10s in the code! But I think we suspected that that wasn't the primary issue. :D

Cheers, Alan.
 
Top