4-20mA project

dan123456

Member
Im currently working on a project which uses a PT100 ( connected to a transmitter calibrated 0 degrees = 4mA, 100 degrees = 20mA) feeding in to a RCV420 chip which converts the 4-20 mA output in to a 1-5V output. I was wondering If there is a PICAXE chip that can have an output high when the input gets to or above an input voltage of my choosing (somewhere between 1-5V).

I hope I've explained this okay, if any more information is needed then please let me know :)

Cheers

Dan
 
So you want to set an output pin on the picaxe high only once an input pin exceeds a certain voltage? If so then yes an 08m2 will even do that.

Edit - Welcome to the forum BTW :) Why not download the picaxe editor and have a look at the examples, it is a great way to learn.
 

hippy

Technical Support
Staff member
Welcome to the PICAXE forum.

Any PICAXE should be able to do what you want. Read the 0V-5V signal using READADC, compare the result with a value which represents your switching point and set the ouput HIGH or LOW. Something like ...

Code:
Do
  ReadAdc C.1, b0
  If b0 > 127 Then
    High C.2
  Else
    Low C.2
  End If
Loop
 
You're welcome, I am a total beginner myself and I have found picaxe to be a fantastic platform for getting things done, not to mention a really great forum and support, good luck with your project and let us know how it turns out :)
 

SteveDee

Senior Member
...feeding in to a RCV420 chip which converts the 4-20 mA output in to a 1-5V output...
This looks like an interesting project. You probably have your own reasons for using the components you mention, but if you are only using the temperature sensor in an alarm cicuit (e.g. is the temperature greater than or less than a setpoint?) I would not have thought you needed a precision receiver like the RCV420.

If you can calibrate your system, then maybe you could connect the 4-20mA transmitter in series with a supply and (say) a good quality resistor(s) across the analogue input of 08m2 Picaxe. It is then a question of reading the ADC count for the required temperature, and using this value as the alarm point (add hysteresis as required).

If you find your readings are a bit noisy, and you don't need high sampling rates, you can use multisampling and add simple capacitor filtering as in my battery monitor: http://captainbodgit.blogspot.co.uk/2015/06/battery-monitor-for-pi-using-picaxe.html

Good luck.
 

Chad Dokens

New Member
Hi,

A 4-20ma signal applied across a 250 Ohm precision resistor will produce a voltage of 1 - 5 volts. Unless the RVC240 is absolutely necessary, a 1/4 Watt, .1% 250 Ohm resistor will work well and will simplify the circuitry. This is a reliable and very commonly used method used in industrial controls. The resistor should be placed a close as is practical to the microcontroller input.

With 8-bit ADC, the ADC value returned by the microcontroller will range from 51 to 255. With 10-bit ADC, the ADC value will range from 204 to 1023

Chad
 

dan123456

Member
This looks like an interesting project. You probably have your own reasons for using the components you mention, but if you are only using the temperature sensor in an alarm cicuit (e.g. is the temperature greater than or less than a setpoint?) I would not have thought you needed a precision receiver like the RCV420.

If you can calibrate your system, then maybe you could connect the 4-20mA transmitter in series with a supply and (say) a good quality resistor(s) across the analogue input of 08m2 Picaxe. It is then a question of reading the ADC count for the required temperature, and using this value as the alarm point (add hysteresis as required).

If you find your readings are a bit noisy, and you don't need high sampling rates, you can use multisampling and add simple capacitor filtering as in my battery monitor: http://captainbodgit.blogspot.co.uk/2015/06/battery-monitor-for-pi-using-picaxe.html

Good luck.
Hey Steve, thanks for the reply! My first thought was to use a 250 ohm resistor but I thought I would try something I haven't used before :)
 

dan123456

Member
hey guys,

I was wondering if I would be able to add on one of the serial modules to the project idea to display the temperature? (id still have the LEDs to indicate when the temperature gets too high)? Im guessing I would have to use a chip like the 18M2 instead of the 8M2..
 

hippy

Technical Support
Staff member
You should be able to add a serial module to display the temperature. You would not have to move from the 08M2 to anything else if you have a spare output line. You might be able to re-organise your outputs to free-up an output for a serial display, or you could perhaps share a LED line, or even have the serial display module control the LEDs.
 

dan123456

Member
So im guessing you would use something like this but instead of using a DS18B20 I'd somehow get the PIC to read the voltage and display the corresponding temperature:

low b.2 ; Initialise OLED output
pause 500 ; Waif for OLED to initialise
main: readtemp c.1, b0 ; Read DS18B20 on pin C.1
bintoascii b0, b1,b2,b3 ; Convert temperature to ascii digits
serout b.2, n2400, ( 254, $80 ) ; First line of display
serout b.2, n2400, ( "Temperature" ) ; Display "Temperature"
serout b.2, n2400, ( 254, $C0 ) ; Second line of display
serout b.2, n2400, ( b1, b2, b3, "C" ) ; Display the temperature
pause 1000 ; Waif a second
goto main ; Display latest temperature
 

dan123456

Member
Welcome to the PICAXE forum.

Any PICAXE should be able to do what you want. Read the 0V-5V signal using READADC, compare the result with a value which represents your switching point and set the ouput HIGH or LOW. Something like ...

Code:
Do
  ReadAdc C.1, b0
  If b0 > 127 Then
    High C.2
  Else
    Low C.2
  End If
Loop
If I wanted C2 to go high when the input to C1 was 2V what number would I put in the "if B0>..." part?
 

dan123456

Member
Im currently using a 1K potentiometer connected to a separate 5V power supply to simulate a 0-5V input to pin C1 using the following code

Code:
  low b.7 ; Initialise OLED output
pause 500 ; Waif for OLED to initialise
Serout B.7,N2400_4,(254,1)   '// Clear Display 
Pause 10
serout b.7, n2400, ( 254, $82 ) ; First line of display
serout b.7, n2400, ("Temperature:") ; Display "Temperature"

main: readadc10 C.1, W0
      w0 = w0 * 44 / 45
      bintoAscii w0,b5,b5,b6,b7,b8 ; Convert temperature to ascii digits
      serout b.7, n2400, ( 254, 197 ) ; Line 1, Position 6  
      serout b.7, n2400, (B5,B6,B7)
      serout b.7, n2400, (".")
      serout B.7, n2400, (b8)
      Serout B.7, n2400, ("    ")
      pause 1000 ; Wait a second
 
goto main
However when the potentiometer gets near to its maximum (the maximum on the screen should be 100) it will only be displaying around 38 on the screen and then random letters and numbers are scattered around the screen. Any ideas why? Ive attached some photos for you to see.

IMG_1678.JPGIMG_1679.JPG
 

Goeytex

Senior Member
My guess is that you do not have the grounds for the separate supplies tied together. Run a wire from the Pot's ground side directly to Picaxe 0V Pin.

( I would recommend a 10K Pot instead of a 1K)

Measure the voltage from the Picaxe 0V Pin to PinC.1. While turning the POT full range, the voltage should swing from 0V to 5V.

While the photos are nice, they are too small to see much. What we really need to see is not the display but rather the breadboard and connections.

ADC Example.png
 
Last edited:

hippy

Technical Support
Staff member
The OLED seems to have received codes to get it to display one of its EEPROM message so the data sent seems to have been corrupted somewhere. It might be worth increasing the PAUSE after turn on and after clearing the screen.

There can also be issues if the PICAXE is reset part way through sending to the OLED so perhaps turn power off and then on after a download to see if that fixes things.
 

dan123456

Member
My guess is that you do not have the grounds for the separate supplies tied together. Run a wire from the Pot's ground side directly to Picaxe 0V Pin.

Thanks again Goeytex!! It's working now. It was because I didn't have the same ground for the separate supples!

:)
 

dan123456

Member
Me again! I've taken a bit of a break from the project, now im back to it.

I want B2 to go high when the reading of C2 is less than 2V. B3 to go high if C2 is higher than 4.5V and B1 to go high when the voltage is inbetween 2 and 4.5V. ( I only want one output to be on at a time)

I wrote the following code:

Do
ReadAdc C.2, b0
If b0 > 102 Then
High B.2
low B.1
low B.3
Else
low B.2
End If

readadc C.2, b0
if b0 > 230 then
high B.3
low b.1
low b.2

else
Low B.3
endif

readadc C.2, b0
if b0 <102 then
high B.1
low B.2
low B.3
else
low B.1
endif
loop
end

Out puts B1 and B3 work fine but there is no output for B2 :(
 

hippy

Technical Support
Staff member
Run some short test code just to check that B.2 output is working -

Code:
Do
  Toggle B.2
  Pause 500
Loop
You may also find that SELECT-CASE makes things easier for you ...

Code:
Do
  ReadAdc C.2, b0
  Select Case b0
    Case > 230 ; > 4.5V
      High B.3
      Low  B.2
      Low  B.1
    Case > 102 ; > 2V
      Low  B.3
      High B.2
      Low  B.1
    Else       ; <= 2V
      Low  B.3
      Low  B.2
      High B.1
  End Select
Loop
 

rossko57

Senior Member
if - elseif - else - endif is also a useful construct

b0 is not altered by testing within an 'if', you need not redo the ADC read to make multiple comparisons
 

dan123456

Member
Run some short test code just to check that B.2 output is working -

Code:
Do
  Toggle B.2
  Pause 500
Loop
You may also find that SELECT-CASE makes things easier for you ...

Code:
Do
  ReadAdc C.2, b0
  Select Case b0
    Case > 230 ; > 4.5V
      High B.3
      Low  B.2
      Low  B.1
    Case > 102 ; > 2V
      Low  B.3
      High B.2
      Low  B.1
    Else       ; <= 2V
      Low  B.3
      Low  B.2
      High B.1
  End Select
Loop
Hi :) I finally tried your code and still it doesn't want to work, very stuck!
 

dan123456

Member
Hi Guys, Im trying to make it so a different LED comes on every 10 degrees so theres 10 LED's in total. I wrote the following Code but Only the LED connected To C6 would come on. It wouldn't turn off either:

Do
ReadAdc C.2, b0
Select Case b0
Case > 230 ; > 4.5V
High B.7
Low B.6
Low B.5
Low B.4
Low B.3
Low B.2
Low B.1
Low B.0
Low C.6
Low C.7
Case > 204 ; > 4.0V
Low B.7
High B.6
Low B.5
Low B.4
Low B.3
Low B.2
Low B.1
Low B.0
Low C.6
Low C.7
Case > 179 ; > 3.5V
Low B.7
Low B.6
High B.5
Low B.4
Low B.3
Low B.2
Low B.1
Low B.0
Low C.6
Low C.7
Case > 153 ; > 3.0V
Low B.7
Low B.6
Low B.5
High B.4
Low B.3
Low B.2
Low B.1
Low B.0
Low C.6
Low C.7
Case > 128 ; > 2.5V
Low B.7
Low B.6
Low B.5
Low B.4
High B.3
Low B.2
Low B.1
Low B.0
Low C.6
Low C.7
Case > 102 ; > 2.0V
Low B.7
Low B.6
Low B.5
Low B.4
Low B.3
High B.2
Low B.1
Low B.0
Low C.6
Low C.7
Case > 77 ; > 1.5V
Low B.7
Low B.6
Low B.5
Low B.4
Low B.3
Low B.2
High B.1
Low B.0
Low C.6
Low C.7
Case > 51 ; > 1.0V
Low B.7
Low B.6
Low B.5
Low B.4
Low B.3
Low B.2
Low B.1
High B.0
Low C.6
Low C.7
Case > 26 ; > 0.5V
Low B.7
Low B.6
Low B.5
Low B.4
Low B.3
Low B.2
Low B.1
Low B.0
High C.6
Low C.7
Else ; < 0.5V
Low B.7
Low B.6
Low B.5
Low B.4
Low B.3
Low B.2
Low B.1
Low B.0
Low C.6
High C.7

End Select
Loop
 

AllyCat

Senior Member
Hi Dan,

Your code appears to simulate correctly (but could be much more compact) so you may need to look for a hardware issue.

However, the first thing to do is introduce a SERTXD command into the program to report to the terminal what are the actual contents of b0.

Also, Please learn how to use [ code ] ... [ /code ] tags. ;)

Cheers, Alan.
 

dan123456

Member
Hi Dan,

Your code appears to simulate correctly (but could be much more compact) so you may need to look for a hardware issue.

However, the first thing to do is introduce a SERTXD command into the program to report to the terminal what are the actual contents of b0.

Also, Please learn how to use [ code ] ... [ /code ] tags. ;)

Cheers, Alan.
Cheers for the advice Alan, I looked in to the hardware issue by using the following code:

Code:
 do
      High B.6
      high B.5
	high B.4
	high B.3
	High B.2
	High B.1
	High B.0
	High C.7
	High C.6

	loop
	end
I measured between the ground on my project board and the output pins and I am only getting 4V on outputs C.7, C.6. The rest are at around 0.6??

I looked in to the SERTXD command but I don't really understand it.

Cheers, Dan
 

rossko57

Senior Member
Can you remind us what project board you are using, does it have an inverting buffer on port B outputs? You'd want to measure between + positive and output, if that were the case.
 

dan123456

Member
Can you remind us what project board you are using, does it have an inverting buffer on port B outputs? You'd want to measure between + positive and output, if that were the case.
18M2 project board. Aah if that's the case I have around 4 V on all the outputs except C.6 and C.7 where I have 0V
 

rossko57

Senior Member
Need to have another read of your project board datasheet. The port B outputs go via a darlington buffer/driver. Its output is driven low when the corresponding Picaxe output is switched high. You would normally put a load, like a LED with resistor, between the + and the B output, as advised on the datasheet. Then the LED will turn on when the Picaxe commands High.

The project board is set up to expect port C pins to be used as inputs. You can of course use them as outputs, but they will not be buffered (limited load capacity - but okay for a LED) and not inverted. You probably want to remove unwanted pulldown resistors, provided for use as inputs.
 

hippy

Technical Support
Staff member
You can use the inputs as outputs even with the pull-down in place, you can simply connect a LED+R to the input pins and use them as outputs.
 

hippy

Technical Support
Staff member
I wonder why i'm getting 0V on both C's
If you are measuring with respect to +V that would be correct if those pins are set as output high.

Measure with respect to 0V and with respect to +V, the B.x outputs via the Darlington array will be opposite to what is on the C.x pins.
 

dan123456

Member
If you are measuring with respect to +V that would be correct if those pins are set as output high.

Measure with respect to 0V and with respect to +V, the B.x outputs via the Darlington array will be opposite to what is on the C.x pins.
Yep just tried that and they are working fine. So I would connect resistor / LED to the the C output pins and then back to ground instead of the + pin?
 

dan123456

Member
I went back to the simpler code:

Code:
 Do
  ReadAdc C.1, b0
  If b0 > 102  Then
    High B.2
    low B.1
    low B.3
    Else
    low B.2
  End If

	readadc C.2, b0
	if b0 > 230 then
	high B.3
	low b.1
	low b.2
	
else
	Low B.3
endif

	readadc C.2, b0
	if b0 <102 then
	high B.1
	low B.2
	low B.3
else
	low B.1
endif
loop 
end
Even with this code, when the voltage is varied output B.1 remains on constantly. Somethings wrong but not sure what!
 

hippy

Technical Support
Staff member
Start even simpler ...

Code:
Do
  ReadAdc C.1, b0
  If b0 > 102 Then
    High B.1
  Else
    Low B.1
  End If
Loop
If that works you are reading the C.1 input correctly and the LED works as expected. Then you can replace C.1 with C.2 and test that analogue input.
 
Top