OpenPLC-with-LDmicro/C3/A-to-D-Converter-Read-Instruction/English
Visual Cue | Narration |
Slide 1: | Welcome to the spoken tutorial on A to D Converter Read |
Slide 2: Learning Objectives
|
In this tutorial we’ll learn about the working of
|
Slide 3: System Requirements
|
To record this tutorial I am using:
|
Slide 4: Pre-requisites
If not, please refer to the relevant tutorials from Home | spoken-tutorial.org |
|
Slide 5: Prerequisites - Hardware setup
hardware-prerequisite.jpg |
Connect SMPS and USBasp to the Mainboard as shown in the picture.
Keep these connections throughout this tutorial. |
Slide 6: A/D Converter Read
|
This instruction reads the data collected by ADC built within a microcontroller.
The data collected will be stored in a variable. This ADC variable can be manipulated using Compare and Arithmetic operations. The ADC of ATmega16 is of 10-bit resolution i.e. it outputs values from 0 to 1023. |
We will learn about the working of this instruction using a simple analog example. | |
Slide: Example
Conditions:
Output: fan is ON and heat is OFF* If ADC value > 900, Output: fan is OFF and heat is ON |
In this tutorial we will control the temperature of the resistor.
That is, the heating element of the OpenPLC Heater module. We will have the conditions as follows. If the ADC value is less than 800, turn on the fan and turn off the heating element. If the ADC value is greater than 900, turn off the fan and turn on the heating element. You can set the limit values according to your requirements. |
Recall that the temperature sensor used in the Heater module is a NTC thermistor.
Thus, the resistance of the thermistor is inversely proportional to the temperature. | |
Open the LDmicro from the launcher bar | Let us open LDmicro. |
Click Instructions -> Analog Operations -> Insert A/D converter read | Insert a A/D converter read instruction as shown. |
Double click on Read ADC >> Type ‘temp’ in the destination column >> Click OK button | Double-click on Read ADC.
We can see a box to enter the destination variable. Type ‘temp’ and click the OK button. |
Highlight Atemp in I/O list | We can see that the name ‘temp’ is prefixed by A.
In the I/O list we can see its type as ‘adc input’. |
Click Edit -> Insert rung after | Now insert a rung below. |
Place the cursor in the new rung >> Click on Instructions -> Comparison Operators -> Insert GRT | Insert a greater than compare instruction in the new rung as shown. |
Double-click on GRT >> Type ‘Atemp’ in the first column >> Type 900 in the second column | Double click on it.
Set the variable to Atemp and compare it to 900. Click the OK button. |
Place cursor to the right of GRT >> Click on Instructions -> Insert Coil | To the right of it, insert a Coil. |
Double-click on Ynew >> Type ‘heat’ in the name box >> Select ‘SET-only’ in type >> Click OK button | Rename the Coil as ‘heat’ and configure it as SET-only Coil. |
Place the cursor parallel to Yheat >> Click on Instructions -> Insert Coil | Now, parallel to Yheat insert another Coil. |
Double-click on Ynew >> Type ‘fan’ in the name box >> Select ‘RESET-only’ in type >> Click OK button | Rename it as ‘fan’ and configure it as RESET-only Coil. |
Click Edit -> Insert rung after | Insert one more rung below. |
Place the cursor in the new rung >> Click on Instructions -> Comparison Operators -> Insert LES | Place a less than compare instruction in the new rung as shown. |
Double-click on LES >> Type ‘Atemp’ in the first column >> Type 900 in the second column | Double click on it.
Set the variable as Atemp and compare it to 800. Click the OK button. |
Place cursor to the right of GRT >> Click on Instructions -> Insert Coil | To the right of it insert a Coil. |
Double-click on Ynew >> Type ‘heat’ in the name box >> Select ‘RESET-only’ in type >> Click OK button | Rename the Coil as ‘heat’ and configure it as RESET-only Coil. |
Place the cursor parallel to Yheat >> Click on Instructions -> Insert Coil | Now, parallel to Yheat insert another Coil. |
Double-click on Ynew >> Type ‘fan’ in the name box >> Select SET-only’ in type >> Click OK button | Rename it as ‘fan’ and configure it as SET-only Coil. |
We will now check the working of this logic. | |
Click Simulate -> Simulation mode >>
Click Simulate -> Real-time simulation |
Let us turn on the simulation mode.
For that, click Simulate and then on Simulation mode. Next, start real-time simulation as shown. |
Highlight the state of Yheat, Yfan and Atemp in the I/O list | We can observe initially the value of Atemp is 0 i.e less than 800.
So the state of Yheat is 0 and Yfan is 1. |
Double click on Atemp in the I/O list | Double-click on Atemp in the I/O list. |
Highlight the value changer | A slider bar appears.
We can change the ADC value by scrolling the pointer. |
ADC reading 0 represents the minimum resistance value of the thermistor.
ADC reading 1023 represents the maximum resistance value of the thermistor. | |
Increase the value of Atemp
Highlight the states of Yheat and Yfan |
Slowly increase the value of Atemp.
We can observe the states of Yheat and Yfan will be the same until it reaches 900. |
Decrease the value of Atemp
Highlight the states of Yheat and Yfan |
Once it goes above 900 the state of Yheat will be 1 and Yfan will be 0.
These states will be the same until the ADC value goes below 800. |
Click Simulate -> Halt simulation >> Click Simulate -> Simulation Mode | Now, turn off the simulation mode.
For that, click Simulate and then on Halt Simulation. Then click Simulate and Simulation Mode. |
Now let us compile the logic.
The detailed steps on how to compile and save the logic are explained in the earlier tutorials. | |
Click on Settings >> Click on Microcontroller >> Select AVR ATmega16 40-PDIP
Click on Settings >> Click on MCU parameters >> Change Crystal frequency to 16 |
Click on Settings and select the microcontroller AVR ATmega16 40-PDIP.
Adjust its parameters as shown here. |
Double-click on Yfan in I/O list >> Select PC6 >> Click OK button
Double-click on Yheat in I/O list >> Select PC7 >> Click OK button |
Assign pin PC6 to Yfan and PC7 to Yheat as shown.
And PC7 to Yheat. |
Double-click on Atemp in I/O list >> Select PA7 >> Click OK button | Double-click on Atemp in the I/O list.
I/O pin dialog box opens. We can see there are only Port A pins as they are the ADC pins. Select PA7 and click the OK button. |
Click on Compile >> Click on Compile >> Go to Desktop/LDmicro folder >> Rename it as ‘adc.hex’ >> Click on Save.
Click OK button |
Compile the logic as adc.hex |
Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘adc.ld’ >> Click on Save | Then save the ladder diagram as adc.ld. |
We will now see the working of this logic on hardware. | |
Connect Mainboard to PC using USBasp
laptop-usbasp.jpg |
Connect the Mainboard to your laptop using USBasp.
Turn on the power supply. |
Open terminal >> Type cd Desktop/LDmicro >> Press ENTER >> type ‘avrdude -c usbasp -p m16 -U flash:w:adc.hex’ >> Press ENTER | Open the Terminal by pressing CTRL+ALT+T keys simultaneously.
Go to the folder where you have saved the hex file. Type the command as shown to upload the hex file to the Mainboard. |
Remove the USBasp connection from the laptop. | Turn off the power supply.
Remove the USBasp connection from the laptop. This will prevent any hardware damage. |
adc.png - connect as explained in the narration | Let us see the connection details now. |
adc.png - connect as explained in the narration | Power the Heater module through relimate connectors from the Mainboard.
Connect pin PA7 of the Mainboard to temp MCU pin of the Heater module. Connect pin PC7 of the Mainboard to heat MCU pin of the Heater module. Connect pin PC6 of the Mainboard to fan MCU pin of the Heater module. Make the connections as shown in the picture. |
Turn on the power | After making all the connections properly, turn on the power supply. |
Point as explained in the narration | Depending on the initial temperature either the fan or resistor starts heating up.
For the first time we can observe that Heaton LED is turned ON. This is because its temperature of the heating element is low. |
Point to FanOn LED | After sometime when the resistor gets heated up, the fan will turn ON.
It is also indicated by FanOn LED. |
Again when the resistor cools down, the resistor starts heating up. | |
Thus the process continues depending on the temperature of the resistor. | |
Note that initially the fan might turn on if the resistor is already heated up. | |
Turn off the power | Turn off the power supply. |
This brings us to the end of this tutorial.
Let us summarize. | |
Slide 8: Summary
|
In this tutorial we learnt about working of A/D converter read instruction. |
Slide : Assignment
Change the limit values :
Output: fan is ON and heat is OFF
Output: fan is OFF and heat is ON |
As an assignment, change the limit values and repeat the experiment.
If ADC value < 750, the fan should turn on and the heating element should turn off. If ADC value > 950 , the fan should turn off and the heating element should turn on. |
Slide 9:
About Spoken Tutorial project |
The video at the following link summarises the Spoken Tutorial project.
Please download and watch it |
Slide 10:
Spoken Tutorial workshops |
The Spoken Tutorial Project team:
For more details, please write to us |
Slide 11:
Forum for specific questions: |
Please post your timed queries in this forum. |
Slide 12:
Forum for specific questions: |
Do you have any general / technical questions on OpenPLC?
Please visit the FOSSEE forum and post your question. |
Slide 13:
Acknowledgement |
Spoken Tutorial Project is funded by MHRD, Government of India. |
Slide 14:
Thank you slide |
This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, IIT Bombay.
And this is Harsha Priyanka from FOSSEE team, signing off. Thanks for watching. |