Analog Schmartboards

3 views
Skip to first unread message

Ian Knight

unread,
Feb 8, 2016, 12:01:12 PM2/8/16
to Potteries Hackspace
Thought some of you guys maybe interest in these:
Ian

Lionschasing .

unread,
Feb 8, 2016, 12:10:15 PM2/8/16
to potteries...@googlegroups.com
Dear Ian

So I've decided to head back into electronics for yet another battle :P

I've ordered two thermocouple adapters, some ultrasonic sensors, an o2 sensor, and other sensors to make sense of it all. I've also bought a trusty arduino to use as my base controller...

my aim is to measure the temperature of our (transformer) coiled hub motors inside the new hub motors we are getting. :)

The code can be found and restructured online, but the issue is the electronics bit....
My aim is to oil-cool one of the hub motors to see what the difference is, it's thanks to Matt that I now know about thermocouple devices, and having spent the whole of yesterday reading about them I'm interested.

--
You received this message because you are subscribed to the Google Groups "Potteries Hackspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to potteries-hacks...@googlegroups.com.
To post to this group, send email to potteries...@googlegroups.com.
Visit this group at https://groups.google.com/group/potteries-hackspace.
For more options, visit https://groups.google.com/d/optout.

Ian Knight

unread,
Feb 8, 2016, 1:33:03 PM2/8/16
to potteries...@googlegroups.com

Ok Archie how can I help?

First question is are these sensors Analogue or Digital?

If Digital it is simply a matter of programming/coding the Arduino IC2 or SPI ports to talk to the device. OScope is very useful for debugging the conversation.

If Analogue it is an Arduino Analogue to Digital converter job, reading samples and turning it into values that represent what measurement you want. (This may require calibration)

 

One issues is sensitivity e.g thermocouple might work over range of -100c to +200c and as you may only be interested in say 20c to 50c so you may not get the resolution you require with an 8bit A/D conversion. So you may simply want to add an Op amp in with a couple of bias resistors to amplify the mid range to give you required resolution and what falls below or above the boundaries is out of rang data and of no consequence.  

 

I have not programmed Ardunio but have done quite a bit of A/D and IC2/SPI in PIc24 and DsPIC so lot of code if you want to take and HACK.

 

Also remember back to old PHS when we where sorting out what to keep and junk. Well we had some Rabbit 8bit microcontrollers I had donated, that got passed on to Stephen. There is lot of code there i wrote to drive the A/D and a serial display that maybe of some use if Stephen still has them.

Ian

 

 

 


Lionschasing .

unread,
Feb 8, 2016, 2:50:52 PM2/8/16
to potteries...@googlegroups.com
thank you for the words of wisdom I am reading a basic arduino hacks book right now to figure out how to get a reading, my code is currently working but what you mention about the operational amplifier rings lots of bells

Ian Knight

unread,
Feb 8, 2016, 4:31:27 PM2/8/16
to potteries...@googlegroups.com

Archie,

If you are familiar with writing micro controller code then ignore the rest of this post.

If not that familiar then the following may be of interest and reap many rewards as the programme grows.

 

A big no no is using delay of wait to wait for i/o send/receive/status etc functions as they change the latency of the programme:

One: if you change the environment (different chip or i/o speed)  you may have to go back and change the duration of the delay/wait function.

Two generally if you use more than ONE delay or wait function they can interact with each other so you have to tune two or more areas of your code.

 

What I find works best for me is to have a TIMER based interrupt handler that uses a state counter to controller the i/o and to use Main() to do the overall control of what your trying to do.

 

AND DON’T FORGET Volatile! Doing so will really mess up your head.

 

You can if you want to get real cleaver is to replace the while loop with a SLEEP to put the cpu in hibernation and when the i/o completes the timer function wakes up to cpu to do main()…. Save this for version two or three.

 

Something like this:

 

Volatile int DataReady;

Volatile int NewData;

Volatile OneSecond;

Main()

{

Volatile Int MyData;

 

DoInitialization(); // Setup io port etc

 

StartOmsMSTimer(); // This starts a 1ms timer that generates an interrupt

 

While(1)

{ // loop forever

 

 

 If( IO_StateCounter == FALSE )

  IO_StateCounter = TRUE; Start the receive.. but let the interrupt handler do all the work.

 

If(DataReady)

 {

 DataReady--;

 MyData = NewData; // Capture new data

 Process MyData….Blah…Blah

 }

 

If(OneSecond) // use this to keep track of things that main() needs to do… there maybe some timing jitter but generally good enough for most applications.

 {

OneSecond = FALSE;

 }

 

 

 

 } // end loop forever

} // end main…………………….

 

Int MS_COUNTER;

Int IO_StateCounter;

 

Interrupt  StartOmsMSTimer() // This function is called by an interrupt ever millisecond

{

MS_COUNTER++;

 

If( MS_COUNTER >= 1000 )

 {

 MS_COUNTER = 0;

 OneSecond =  TRUE; // Use 1 second counter.. use something like this to control flow of main()

 }

 

 

Switch( IO_StateCounter )

 {

 Case START_IO;

 ///….Do whatever

 Break;

 Case IO_READY;

 ////…. Start Receiving….

 Break;

 Case IO_COMPLETE

////….Receive complete so tell main have some data;

  NewData = GetReceiveData();

  DataReady++;

  StopIO();

  Break;

  }

 

 

// RESET Interrupt flag…

 

} // end 1ms interrupt

Ian Knight

unread,
Feb 8, 2016, 5:37:24 PM2/8/16
to potteries...@googlegroups.com

Archie,

Another good tip when micro controller programming is to define some io ports as digital out and put an LED on them.

Call em test led 1 thru 8 say.

Then in the code toggle the bit to signal that this area of code has been called..

Thus TEST_LED_1 ^= 1; \\ toggle test led 1

Ian Knight

unread,
Feb 11, 2016, 4:37:36 AM2/11/16
to potteries...@googlegroups.com

Archie,

Sorry the below could cause problem if timer goes off again before you have read NewData in Main():

 

If(DataReady)

 {

 DataReady--;

 MyData = NewData; // Capture new data

 Process MyData….Blah…Blah

 }

 

Better like this:

 

If(DataReady)

 {

 MyData = NewData; // Capture new data

 

 DataReady--; // reset flag

 

 Process MyData….Blah…Blah

Lionschasing .

unread,
Feb 11, 2016, 8:54:11 AM2/11/16
to potteries...@googlegroups.com
thanks Ian
Reply all
Reply to author
Forward
0 new messages