From Arduino and Perfboard to PCB With Standalone MCU

2,776

15

This Instructable is a direct successor of THIS ONE. At the end of this build up, my TURNTABLE PROJECT is nearly complete (finally).

The goal is developing a good looking and working PCB with SMD electronic with a working ATtiny85 + software!

So, the starting situation here is a perfboard like shown in the picture. Located on that perfboard is a lightdriven voltage source, converting a PWM signal from the Arduino to a voltage, which drives a motor. Everything is described in my other instructables. The input for the arduino comes from an generator, indicating the current speed. Therefore, the arduino measures the current speed and uses an PID controller to controll the value on the given speed value for the turntable. This speedvalue is again given by a measurement of runtime for one turn of the turntable by a light barrier measurement.

The basic implementation is as follows:

--> measure time for one turn

--> if this time is larger than the normal speed (33.33rpm for a turntable)

-->increase speed value and PID controller regulates on that value very fast

--> if slower do the opposite and if its equal, fine!

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: PCB Design, Routing, Etc

Since the circuit is given in the former instructable, the slightly changed version is modeled in eagle.

Since i want to use in system programming, it is important to connect the ATtiny to the pins for the connector. I use an AVR jtag mk2 to program my microcontrollers.

For now, it is only important to create a proper layout - therefore pay attention on a proper groundplane and split up the voltage sources for the analog circuit and the microcontrollers to avoid any problems with switching (since i only use a 2 layer PCB). Additionally dont forget the 100n capacitors at the Vcc pins from the ICs to decouple against switching processes and source transient currents is its needed.

I placed the heart of my PCB in the middle - the LDR LED combination, which is the basis of my light driven voltage source.

Below the main circuit is a VU meter. This indicates the voltage created by the light controlled source in steps of ca 700mV with LEDs. Its a very cool, simple and cheap way and it also looks really cool later on, because every reaction of the controller is visible here.

Since i use 0805 SMT parts, the PCB is now very small in comparison to the perfboard. I order my PCB in HongKong for just a few dollars (the shipping time is therefore high). The results are really good as you can see on the pic.

Step 2: Soldering, Debugging, First Programming

The soldering was done in one hour and the circuit had no short circuits or something else - everything worked properly after connecting the power supply (except for the fact, that i forgot a pull up resistor at RESET...).

But there is still something missing - the brain. After connecting the ATtiny, i connect the whole board to my programmer and start with simple programs like varying the PWM width with for loops or simple analog read tasks. You can see on the picture that the LED in the middle of the board is on, which indicates that its working.

Step 3: Implementing the Whole Code...

The code is attached at the end.

It consists out of general MCU stuff, like preparing the ADC and Time/Interrupts. The most important part is the control part. The MCU gets the values from the ADC, converts it with the PID controller to a proper motor speed and speeds it up until the given value is reached.

This value isnt exactly the wanted motor speed (33.3 rpm). Therefore light barriers send one signal per sound to the microcontroller, which uses a timer interrupt to calculate the actual speed and changing the set value for the PID controller.

This controlls the speed after the given value. After 10 seconds the speed is exaclty 33.3rpm and the measurement of turning speed stops (otherwise we'll have oscillations due to high system masses and the PID controller).

If the turntablespeed reaches a threshold above or below the given speed value, the measurement starts again.

The actual control voltage and therefore motor speed is shown by the LED voltage meter given on the right side of the PCB. The LED in the middle is controlled by the PWM of the MCU, while its light controlls the voltage output. One can therefore see directly at the LED, if the motor speed changes.

With this device my turntable is controlled exactly to its speed of 33.33 rmp - no matter what happens on the device. With adding a mode for the 44rpm speed my turntable will be complete.