Tuesday, April 25, 2006

op-amp

Friday, April 14, 2006

code_working

'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2006 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 4/14/2006 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
DEFINE OSC 4

DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEuS 20

RedLed var portd.1 'to test transmitted data
bluLed var portd.0 'to test received data from pd

measurement VAR BYTE
counter VAR BYTE

outPin var portc.6 'transmitting pin

counter=0

TRISA=%11111111 'to set all portA to analogue input
ADCON1=%00000010

main:

adcin 0, measurement
serout2 outPin, 16468, [DEC measurement,13,10]

high REdLed
pause 50
Low RedLed
counter=counter+1

Pause 100

goto main

code_Analogue In & Serial Out

DEFINE OSC 4

DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEuS 20

‘This is to test if the values were transmitted correctly
‘It will blink once it goes out to Serial Out
RedLed var portd.1
‘This is to test if the values were received correctly
‘It will blink once something comes in from the Serial In
BluLed var portd.0

‘Variable for the measurement
measurement VAR BYTE
‘Variable to count the number of transmission
counter VAR BYTE

'this will be the pin that I transmit from
outPin var portc.6

counter = 0

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify


main:

adcin 0, measurement 'get adc value from channel 0 put in counter

serout2 outPin, 16468, [DEC measurement ]

high RedLed
pause 50
Low RedLed
Counter = Counter + 1

Pause 100

goto main

Tuesday, April 11, 2006

code_test serial

counter var byte
Startcounter VAR BYTE

Startcounter = 0
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify


main:

serout2 PORTC.6, 16468, [DEC counter ]
counter = Startcounter

goto main

Monday, March 20, 2006

w_8_group presentation

refer to
this page

Tuesday, March 07, 2006

w_7_midi




If ASCII is a protocol for text MIDI is for music. MIDI synthesizer decodes binary codes from PIC into musical notes. We can experience more defined sound by plugging it in synthesizer equipped with various sound module.
As I have worked in a place where I can witness developments of digital instruments for music, I can tell how MIDI has been improved. About 10 years ago, keyboard players had to install a separate MIDI box near their keyboards. But after synthesizer with built-in midi (i.e. Yamaha SY-99, musician's longtime favorite) came into world, keyboard players lessened their carriage weight for concerts.

The problem I encountered while wiring this circuit was from wrong configuration settings. I should have changed configuration option to HS. Joseph helped me when I almost gave up after tens of errors.

I found wiring circuit or slodering MIDI connector was basically same as for DB9 serial connector. MIDI is for exchnaging data between PIC and other device as DB9 is between PIC and PC.

I did not have 7404 Hex inverter. I made simple circuit using Michael's code example. Experiment of changing instrument type, note or volume by varying arguments is set aside for future.

w_7_midi_code from Michael

'****************************************************************
'* Name : midi.BAS *
'* Author : Michael Luck Schneider *
'* Notice : Copyright (c) 2006 Michael Luck Schneider *
'* : All Rights Reserved *
'* Date : 2/28/2006 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
define OSC 20 'midi needs a 20 mhz clock

txPin var portc.6
LED var portd.0
Sw1 var portb.7

output led
output txpin
input sw1

x var byte
lastSw1 var byte


for x = 0 to 6
high led
pause 100
low led
pause 200
next

lastsw1 = sw1

main:
if sw1 != lastsw1 then 'if there has been a change of state
pause 10 'debounce
if sw1 = 1 then 'see if the button has been pushed
serout2 txpin, 12, [144, 80, 127] 'noteon channel 1, note 80, full volume
else 'or released
serout2 txpin, 12, [144, 80, 0] 'noeton channel 1, note 80, 0 velocity (same as note off)
endif
lastsw1 = sw1 'for change of state
endif

goto main

w_6_servo motor



Please click the image to start.


I tried this LAb without H-bridge. To my understanding, H-bridge is necessary to change the direction of servor mortor. I borrowed code from Todd and the motor changed it's direction without H-bridge. I vaguely understood that "if" statement in code programming has made it possible. I will give it a try again with H-bridge.

Monday, March 06, 2006

w_6_servo motor_code from Todd

''****************************************************************
'* Name : UNTITLED.BAS *
'* Author : Todd Holoubek *
'* Notice : Copyright (c) 2004 Todd Holoubel *
'* : All Rights Reserved *
'* Date : 6/7/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
DEFINE OSC 4
start:
pulseWidth var byte
'thes values can be vary with different motors
minPulse CON 75
maxPulse CON 250
refreshPeriod CON 5
'pulsewidth = maxPulse
myDir var byte
myDir = 1
main:
low PORTD.2
PulsOut PORTD.2, pulseWidth
pause refreshPeriod
if myDir = 1 then
pulsewidth = pulseWidth + 1
else
pulsewidth = pulseWidth - 1
endif
IF pulseWidth <= minPulse THEN
myDir = 1
ENDIF
IF pulseWidth >= maxPulse THEN
myDir = 0
ENDIF
GOTO main

Sunday, March 05, 2006

w_5_serial out_ascii text



Please click the image to start.


I learned that English characters need to be changed into binary numbers to be exchanged between digital device. ASCII is a protocol, or an agreement, which is setup for this. Call and response worked well. But I failed in making it work with photocell and potentiometer.

w_5_serial out_ascii text_code from Michael

DEFINE OSC 4
myvar var byte

main:

serout2 portc.6, 16468, ["myvar = ", myvar, 13, 10, "mydec = ", dec myvar, 13, 10]
myvar = myvar + 1
pause 200
goto main

w_4_simple pwm_blinking LED



Blinking LED

Please click the image to start.


PWM (Pulse Width Modulation) was understandable conceptually. To implement in the code was another matter.

w_4_simple PWM_code from Michael

'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2005 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 9/29/2005 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
DEFINE OSC 4

output portc.0

arf var byte
duty var byte
counter var byte

for arf = 0 to 3
high portc.0
pause 100
low portc.0
pause 200
next

main:

for duty = 0 to 255
pwm portc.0, duty, 1
next

goto main