Sunday, March 21, 2010

Linux Commands

to verify your pci hardwares : /sbin/lspci

Monday, March 8, 2010

PWM speed control (pic18f4550)

here is the ccs code:

#include <18f4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock = 20000000)
void main() {
unsigned int16 value;// Input variable
setup_adc_ports(ALL_ANALOG);// Input combination
setup_adc(adc_clock_internal);// ADC clock
set_adc_channel(0);// Select RA0
setup_ccp1(ccp_pwm); // Select timer and mode
setup_timer_2(T2_DIV_BY_16,248,1); // Clock rate & output period
while(1) {
value=read_adc();//Get input byte
set_pwm1_duty(value);// Set on time
}
}

everything is exactly same as previous post + a simple potentiometer which is connected to pin2.

here is the execution:

Driving a motor (pic18f4550)

you can use the information mentioned in previous post as the pic side program to increase or decrease the speed of a motor as an example. now I want to use ULN2003APG driver to drive a motor.

using ULN2003APG :

pin1 ---> MCU output
pin16 ---> Motor
pin8 ---> Motor GND and MCU GND

and connect vcc to the motor.we use mcu signal to connect gnd to the motor to run with separate vcc but common gnd.


PWM (pic18f4550)

to use pwm here is the ccs code:

#include <18f4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock = 20000000)

void main() {
setup_ccp1(ccp_pwm); // Select timer and mode
set_pwm1_duty(25); // Set on time
setup_timer_2(T2_DIV_BY_16,248,1); // Clock rate & output period
while(1) { } // Wait until reset
}

pin17 ---> pwm output
+ everything was mentioned in previous posts in order to run a 18f pic.

Friday, March 5, 2010

How to make a DVD (Advanced concepts)

sometime you download subtitles which are in sub/idx format which is not supported in DVD-Lab pro so you can do the following :

1. Use dvdsupdecode to convert the .sup file into a .txt file and several .bmp files,
with the -bitmap parameter and either the -pal or -ntsc parameter according to the
original DVD you demuxed the .sup file from

2. Open the .txt file in notepad, remove the lines at the start which are similar to the
following ones:

Code:

;Subpictures_20.sup
FrameRate=29.97
Palette=2010
Alpha=FFF0

and instead add a line like this one (depending on the original value indicated by
"Framerate="):

Code:

{29.97}

Also, do a couple global replaces to get rid of the { and } surrounding the subpicture
names, the easiest way is to replace {Sub with Sub and then bmp} with bmp.
Save the file with the ".sub" extension.

3. Load Subtitle Workshop, and open the .sub file you just save as a MicroDVD
subtitle file.

4. Save the file as a Spruce DVD Maestro .son file.

5. Open the saved .son file in Notepad. By default, the lines at the start will read:

Code:

st_format 2
Display_Start non_forced
TV_Type PAL
Tape_Type NON_DROP
Pixel_Area (0 573)
Directory

For NTSC only, change that to:

Code:

st_format 2
Display_Start non_forced
TV_Type NTSC
Tape_Type NON_DROP
Pixel_Area (2 479)
Directory

Also, further down, you'll find a couple of lines that read

Code:

Color (0 1 2 3)
Contrast (0 15 15 15)

Adjust those to match the original .txt file's "Palette=" and "Alpha=" entries, keeping
in mind that they go backwards. So, for our example

Code:

Palette=2010
Alpha=FFF0
becomes:
Code:
Color (0 1 0 2)
Contrast (0 15 15 15)

Save the .son file again with the changes.

6. Now you can import the .son subtitle file into DVD Lab Pro in the same way you
import .srt subtitles. Be sure to set the vertical margin to 0, and leave the "drop frame"
option unchecked (or the "non-drop frame" option checked, depending on whatever
the checkbox actually reads).

How to make a DVD (DVD-Lab pro)

1.make a new project and select "Normal (VTS Menu + Movie)" and select PAL.
2.Import converted files to your project their bitrates is better to be about 1200kbps.
3.from "connections" select "movie1" and add the imported video and audio which are now separated.
4.add your subtitle remember to choose proper script for its font.
5.sometimes you need to save *.sub as *.son (Spruce DVDMaestro) using subtitle workshop.
6.from menu select movie->Auto-Chapter and set 30 chapters for each movie.
7.now click on the "menu1" then select your background at the bottom of the page in the "background tab" and add some text and then right click on text and link it to first chapter of the movie.
8.you can compile your dvd and then burn it.

Tuesday, March 2, 2010

Hid Demo

finally I could find a library in order to work with usb very easily here is the library itself.
usb hid can be downloaded here which is written in c#.
usb pic side can be downloaded here which is made which ccs.

this code is not complete and is just for learning how to use usbLibrary. In order to use see the result :
pin2 ---> ADC
pin20 ---> led+resistor(470 ohm)
+ everything was mentioned in previous post in order to implement usb.
and this is the hid:

Monday, March 1, 2010

How to import dll C#

make a console project and paste the code.here is the code :

using System;
using System.Runtime.InteropServices;
class Example
{
// Use DllImport to import the Win32 MessageBox function.
[DllImport("user32.dll")]
static extern int MessageBox
(IntPtr hWnd, String text, String caption, uint type);
static void Main()
{
// Call the MessageBox function using platform invoke.
MessageBox(new IntPtr(0), "Hello, World!", "Hello Dialog", 0);
}
}

remeber the name MessageBox is unique entry in this dll.

The extern modifier is used to declare a method that is implemented externally. A common use of the extern modifier is with the DllImport attribute when using Interop services to call into unmanaged code; in this case, the method must also be declared as static

after execution :