Tim Bruening - Fab Academy 2016

Week #13 - Output Devices

In the thirteenth week we created and test output circuits.  I decide to try the "hello-world" servo board.  The board can 

control either one or two servo motors depending on the file that is downloaded to the board.  I did notice that it is getting 

a little easier to work with the electronic circuit board.  My soldering technique is improving and I am able to program the boards a little easier.

Here is a list of tasks as I see them for the thirteenth week.

Choose an output circuit to build and program.

I chose to make the hello.servo.44 circuit board. I wanted to see what it took to make something move. 

The circuit uses an ATtiny44 microcontroller. It also includes one or two small servo motors to operate.

This circuit uses Pulse Width Modulation (PWM) to control the movement of the servos.  The PWM in this circuit is hardware based.

That means we are using the attiny44 to cause the PWM.  The "c" file hello.servo.44.c

controls one servo.  The drive rotates about 45 degrees from start, then rotates to about 90 degrees from start, then resets to zero degrees.

According to an Arduino tutorial (arduino.cc/en/tutorial/pwm) "Pulse Width Modulation (PWM) is a technique for getting analog results with digital means.

A square wave is used to create the signal. The pulse width is determined by how long the signal is on.

Looking at the chart below,if we had an LED control with a 100% duty cycle it would be as bright as it can be.

If the duty cycle were reduced to 25% the LED would be quite dim.


smiley face

Download the board and component files from FAB Academy.

I downloaded the files I needed from the FAB Academy website.

smiley face

Create the PCB board in Eagle software.

Using the examples I printed from the FAB Academy page I drew the schematic for the hello.servo.44 board.

smiley face

I then labeled all the conections and associated them with a board.

To populate the board in Eagle you need to create the traces that go with the yellow lines from the associations.

smiley face

Each time more of your traces appear until you have all the associated connections needed for the board.

smiley face


Machine the board.

I used an LPKF Protomat S63 electroics CNC to cut the new hello-servo-44 circuit board.

The tool used had a diameter of 0.0625" (1/64")

Here is an image from Week #6 of the LPKF machine.

smiley face

Populate the board with electronic components.

Here are two images of the components needed and the finished board with battery connector.

smiley face smiley face

Program the PCB.

I chose to use two servos for this lab. There are two programs that I can run with the servos.

The file "hello.servo.44.c" will only control one servo. The servos use hardware based Pulse Width Modulation.

By hardware  PWM I mean that the ATTiny44 will control the pulsing.  In software based PWM there are delays in the program that mimic hardware PWM.

In order to understand what is going on in the program I had to use the ATtiny44 datasheet to find some of the pins and other info for the program.

The beginning part of the hello.servo.44.c program is message statements that list Neil Gershenfeld as the author and contain his copyright info. 

There is also a message to "set lfuse to 0x5E for 20 MHz xtal" This will be programmed later. 

The next two lines set up which libraries or headers to use to find commands used in the program.   include avr/io.h  &  include util/delay.h

The next nine lines are definitions needed for setup.

     ex- define output(directions,pin) (directions |= pin)   sets port direction for output.  |= is an "or" command.

          00011000

          00001001                OR Example

          00001000

--------------------------------------------------------------------------

     ex -  define PWM_port PORTA      the name "PWM_port"  is set to PORTA

     ex - define PWM_pin  (1 << PA6) set PA6 as an output.


smiley face

----------------------------------------------------------------

Look at data sheet pg. 108 for table 12-4    

TCCR1A = (1 << COM1A1) | (0 << COM1A0)          This is the third condition in the table   1 0  and means "Clear OC1A/OC1B on Compare Match when up-counting.

smiley face

ex - clear (PWM_port, PWM_pin);          clears PORTA & PA6

ex - output (PWM_direction, PWM_pin);  sets as outputts

------------------------------------------------------------------

The next parts of the program are the main loop. 

OCR1A = 1250                       This means that the Output Compare Register will reset when 1250 is achieved.

position_delay();                      This rests the delay.                     This function was located in one of the libraries defined earlier.

Here is a visual to understand what OCR1A is controlling.  It would be shorter is the PWM is lower.


smiley face

 -----------------------------------------------------------------

The file "hello.servo.44.2.c" will control two servos. The program sets up a routine where the servos go back and forth with movement.

The files to compile the codes and run the servos are found on the FAB Academy website.


To compile the code to control one servo -            make -f hello.servo.44.make

To complie the code to control two servos -           make -f hello.servo 44.2.make

To flash the code to the atttiny44 -                           make -f hello.servo.44.c

One servo will be cycling.

To flash the code to the attiny44 -                            make -f hello.servo.44.2.make

Two servos will be cycling.


Test the PCB.

I alternated between the two programs. hello.servo.44.c hello.servo.44.2.c The first one only controls one servo and the second one has a routine to control both. The image on the right shows one servo working. The image on the left shows both servos working.

smiley face smiley face

Document the process and list any problems encountered.

I must be getting a litle better with my electric circuits.  I took some time to create the schematic, board image, populate the board and program the PCB.

Other than my on going deficiencies in programming I am really starting to understand what is going on with circuit boards.

Create the Output Circuit for the Final Project



Build PCB Boards

I needed to build two boards for this project.  After discussions with my mentor and other electronics people I decided to make a smaller, separate board for the hall effect sensor.

It will be easier to place and keep the main board away from the heat.

The main board will house the ATTiny44 micro controller and all the 2 x 2 connectors needed to integrate all components.

Here is a screenshot of the schematic for the ATTiny44 board.


smiley face

Here is a screenshot of the traces for the final ATTiny44 board.


smiley face

This is a picture of the completed ATTiny44 board and the traces used to make it.


smiley face

Here is the schematic for the hall effect sensor.


smiley face

Here are the board traces for the hall effect sensor.


smiley face

Here is the hall effect sensor before populating.


smiley face

Here is the finished hall effect sensor board.


smiley face

Program the Boards

For my final project I decided to use Arduino programming.  To me it seems simpler than the "C" programming we used in earlier programs.

The Arduino code is easier for me to understand.  I am able to walk through each line of code and explain what is happening.

Here is my final project program.  The explanations in RED are not part of the program  They are added for explanation only.  

void setup() {                                                                                 setup only runs once on startup

  // put your setup code here, to run once:

  pinMode(10,OUTPUT);                                                              define pin #10 as an output

 

}

 

int sensorValue =0; // variable for hall read on A0                    set hall effect input to zero

int TimeValue=0;  // potentiometer input                                    set pot. input to zero                                                                  

int timescale=0; // pot variable                                                    set pot. variable to zero

 

void loop() {                                                                                   loop forever constantly scan code

  // put main code here, to run repeatedly:

 

sensorValue = analogRead(0);  // read voltage on A0            hall effect input from A0

TimeValue = analogRead(2);  // read voltage on A2               pot. input from A2

 

  timescale = TimeValue * 10;                                                    controls variable delay from pot.

 

if( sensorValue < 200)                                                                  true if correct magnetic pole is present

{

  delay(10000);                                                                              wait 10,000 milliseconds (10 seconds)

  delay(10000);                                                                             

  delay(10000);                                                                             

  delay(10000);                                                                             

  delay(10000);                                                                             

  delay(10000);                                                                             

  delay(10000);                                                                             

  delay(4000);                                                                                 wait 4,000 milliseconds (4 seconds)

  delay (timescale);                                                                       wait value from pot.

  digitalWrite(10,HIGH);                                                               set pin #10 to high (turn on vacuum pump)

 

}

 

while(sensorValue < 200)                                                            keep pin #10 value high as long as sensorValue < 200

{                                                                                                                       (as long as sensor detects magnetic field)

 

sensorValue = analogRead(0);                                                   sets sensorValue to 500 when burner is moved

                                                                                                                        away from hall effect sensor

}

 

digitalWrite(10,LOW);                                                                 set pin #10 to low (turns off vacuum pump)

 

}

Test Boards

Now that the boards are programmed they have to be tested. I wired them up using a 9 volt battery and 110 volt jumper wires.

The light bulb is filling in for the vacuum pump.


smiley face
smiley face

Looking at the ATTiny44 board schematic and board images you will see four 2x2 connectors. These are used to connect all the components together.

Power 2 x 2 --- This connector has a 9 volt battery connected to it. 2 pins connect to ground (GND) and 2 pins are connected in series to the voltage regulator.

The voltage regulator (on the ATTiny44 board) feeds 5 volts (VCC) to the 1uF capacitor, 10k ohm resistor, pin 1 on the Hall 2 x 2, pin 1 on the Pot 2 x 2 and the AVRISPSMD.

Hall 2 x 2 ---- This connector has 1 pin to VCC, 1 pin to GND, 1 pin to Pin 13 on the ATTiny44 and one pin unused.

Pot Timer 2 x 2 ---- 1 pin to VCC, 1 pin to GND, 1 pin to Pin 11 on the ATTiny44 and 1 pin unused.

VAC 2 x 2 ---- 2 pins connected to Pin 2 on the ATTiny44 (PB0  output to terminal on DC side of relay) and  2 pins (GND) to other terminal on DC side of relay. 

                     ----  2 wires to GND and 2 wires to Pin 2 are twisted together.

The AC side of the relay has one wire coming from the hot 110 volt wire and one wire going to one side of the outlet in the blue box.

The other wire (neutral) from AC 110 goes directly to the remaining terminal of the outlet.

The vacuum pump is plugged into the outlet.  It will only come after the programmed delays.

The ATTiny44 board is programmed with a 75 second delay (determined through testing).

Here you can see the test setup.


smiley face

Here you can see the test setup after the hall effect sensor has been manually triggered.

You can see the stopwatch recorded 1 minute and 15 seconds.  75 seconds total.


smiley face


Tim's Week #13 files:

*.c and *.make files

  • hello.servo.44.c
  • hello.servo.44.2.c
  • hello.servo.44.make
  • hello.servo.44.2.make
  • Eagle servo schematic.
  • Eagle servo board.
  • Click here to see Final Project Files
    Back to index