Skip to content

Commit

Permalink
Pongsat update
Browse files Browse the repository at this point in the history
  • Loading branch information
Sol-X committed Jul 22, 2014
0 parents commit abfad9d
Show file tree
Hide file tree
Showing 23 changed files with 432 additions and 0 deletions.
1 change: 1 addition & 0 deletions Anarean AIR.spin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PUB Initialize | OK 'Initializes the Non range exteneded Anarean AIR Rx/Tx module
1 change: 1 addition & 0 deletions CPC1822.spin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PUB Initialize | OK 'Initializes the solar tracking system
Binary file added Clock.spin
Binary file not shown.
Binary file added DeathStar.spin
Binary file not shown.
Binary file added FME.spin
Binary file not shown.
Binary file added GDB Hello World.spin
Binary file not shown.
Binary file added GDB SSW Hello World.spin
Binary file not shown.
Binary file added GDB-API-V0.1.0.spin
Binary file not shown.
Binary file added GDB-SerialMirror.spin
Binary file not shown.
1 change: 1 addition & 0 deletions I2C_ROMEngine.spin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// I2C Electrically Erasable Programmable Read Only Memory Engine//// Author: Kwabena W. Agyeman// Updated: 7/27/2010// Designed For: P8X32A// Version: 1.1//// Copyright (c) 2010 Kwabena W. Agyeman// See end of file for terms of use.//// Update History://// v1.0 - Original release - 8/8/2009.// v1.1 - Added variable pin support - 7/27/2010.//// For each included copy of this object only one spin interpreter should access it at a time.//// Nyamekye,//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// I2C Circuit://// 3.3V// |// R 10KOHM// |// Data Pin Number --- EEPROM SDA Pin.//// 3.3V// |// R 10KOHM// |// Clock Pin Number --- EEPROM SCL Pin.///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////}}PUB readByte(EEPROMaddress) '' 18 Stack Longs'' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////'' // Reads a byte from the EEPROM. It is recommended to read the byte on a byte boundary.'' //'' // Returns the byte on success and false on failure. Could return a byte of value 0.'' //'' // EEPROMaddress - Starting byte address of the data to access.'' //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// result &= readPage(EEPROMaddress, @result, 1)PUB writeByte(EEPROMaddress, value) '' 19 Stack Longs'' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////'' // Writes a byte to the EEPROM. It is recommended to write the byte on a byte boundary.'' //'' // Returns true on success and false on failure.'' //'' // EEPROMaddress - Starting byte address of the data to access.'' // Value - Value to write to the EEPROM.'' //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// return writePage(EEPROMaddress, @value, 1)PUB readWord(EEPROMaddress) '' 18 Stack Longs'' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////'' // Reads a word from the EEPROM. It is recommended to read the word on a word boundary.'' //'' // Returns the word on success and false on failure. Could return a word of value 0.'' //'' // EEPROMaddress - Starting byte address of the data to access.'' //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// result &= readPage(EEPROMaddress, @result, 2)PUB writeWord(EEPROMaddress, value) '' 19 Stack Longs'' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////'' // Writes a word to the EEPROM. It is recommended to write the word on a word boundary.'' //'' // Returns true on success and false on failure.'' //'' // EEPROMaddress - Starting byte address of the data to access.'' // Value - Value to write to the EEPROM.'' //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// return writePage(EEPROMaddress, @value, 2)PUB readLong(EEPROMaddress) '' 18 Stack Longs'' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////'' // Reads a long from the EEPROM. It is recommended to read the long on a long boundary.'' //'' // Returns the long on success and false on failure. Could return a long of value 0.'' //'' // EEPROMaddress - Starting byte address of the data to access.'' //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// result &= readPage(EEPROMaddress, @result, 4)PUB writeLong(EEPROMaddress, value) '' 19 Stack Longs'' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////'' // Writes a long to the EEPROM. It is recommended to write the long on a long boundary.'' //'' // Returns true on success and false on failure.'' //'' // EEPROMaddress - Starting byte address of the data to access.'' // Value - Value to write to the EEPROM.'' //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// return writePage(EEPROMaddress, @value, 4)PUB readPage(EEPROMaddress, RAMaddress, byteCount) '' 14 Stack Longs'' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////'' // Reads bytes from the EEPROM. Uses a 19 bit addressing scheme which can acess multiple EERPOMs on a bus.'' //'' // This rountine can only read from the EEPROM selected. Any reads past that EEPROM will warp arround.'' //'' // It is recommended to use the byte/word/long read rountines used on byte/word/long boundaries respectively.'' //'' // Returns true on success and false on failure.'' //'' // EEPROMaddress - Starting byte address of the data to access.'' // RAMaddress - Starting byte address of the data to write to.'' // ByteCount - Number of bytes to read.'' //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// result := eepromPoll(EEPROMaddress) if(result) stopDataTransfer startDataTransfer result and= transmitPacket(constant((10 << 4) | 1) | ((EEPROMaddress >> 15) & $E)) repeat ((byteCount <# (65_536 - (RAMaddress #> 0))) #> 0) byte[RAMaddress++] := receivePacket(--byteCount) stopDataTransfer clearLockPUB writePage(EEPROMaddress, RAMaddress, byteCount) '' 14 Stack Longs'' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////'' // Writes bytes to the EEPROM. Uses a 19 bit addressing scheme which can access multiple EERPOMs on a bus.'' //'' // This rountine can only write to the page of the EEPROM selected. Any writes past that page will warp arround.'' //'' // It is recommended to use the byte/word/long write rountines used on byte/word/long boundaries respectively.'' //'' // Returns true on success and false on failure.'' //'' // EEPROMaddress - Starting byte address of the data to access.'' // RAMaddress - Starting byte address of the data to read from.'' // ByteCount - Number of bytes to write.'' //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// result := eepromPoll(EEPROMaddress) if(result) repeat ((byteCount <# (65_536 - (RAMaddress #> 0))) #> 0) result and= transmitPacket(byte[RAMaddress++]) stopDataTransfer clearLockPUB ROMEngineStart(dataPinNumber, clockPinNumber, lockNumberToUse) '' 9 Stack Longs'' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////'' // Checks out a lock for the driver and changes the I2C Circuit pins.'' //'' // Returns true on success and false on failure.'' //'' // DataPinNumber - Pin to use to drive the SDA data line circuit.'' // ClockPinNumber - Pin to use to drive the SCL clock line circuit.'' // LockNumberToUse - Lock number to use if sharing the I2C bus (0 - 7). -1 to request a new lock number.'' //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ROMEngineStop dataPin := ((dataPinNumber <# 31) #> 0) clockPin := ((clockPinNumber <# 31) #> 0) if((dataPin <> clockPin) and (chipver == 1)) lockNumber := lockNumberToUse if(lockNumberToUse == -1) lockNumber := locknew result or= ++lockNumberPUB ROMEngineStop '' 3 Stack Longs'' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////'' // Returns the lock used by the driver.'' //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if(lockNumber) lockret(-1 + lockNumber~)PRI eepromPoll(EEPROMaddress) ' 8 Stack Longs setLock startDataTransfer result := cnt repeat until(transmitPacket(constant(10 << 4) | ((EEPROMaddress >> 15) & $E))) stopDataTransfer startDataTransfer if((||(cnt - result)) > (clkfreq / constant(1_000 / 5))) return false result := transmitPacket(EEPROMaddress >> 8) result and= transmitPacket(EEPROMaddress)PRI transmitPacket(value) ' 4 Stack Longs value := ((!value) >< 8) repeat 8 dira[dataPin] := value dira[clockPin] := false dira[clockPin] := true value >>= 1 dira[dataPin] := false dira[clockPin] := false result := not(ina[dataPin]) dira[clockPin] := true dira[dataPin] := truePRI receivePacket(aknowledge) ' 4 Stack Longs dira[dataPin] := false repeat 8 result <<= 1 dira[clockPin] := false result |= ina[dataPin] dira[clockPin] := true dira[dataPin] := (not(not(aknowledge))) dira[clockPin] := false dira[clockPin] := true dira[dataPin] := truePRI startDataTransfer ' 3 Stack Longs outa[dataPin] := false outa[clockPin] := false dira[dataPin] := true dira[clockPin] := truePRI stopDataTransfer ' 3 Stack Longs dira[clockPin] := false dira[dataPin] := falsePRI setLock ' 3 Stack Longs if(lockNumber) repeat while(lockset(lockNumber - 1))PRI clearLock ' 3 Stack Longs if(lockNumber) lockclr(lockNumber - 1)DAT' //////////////////////Variable Array/////////////////////////////////////////////////////////////////////////////////////////dataPin byte 29 ' Default data pin.clockPin byte 28 ' Default clock pin.lockNumber byte 00 ' Driver lock number.' /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////{{///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TERMS OF USE: MIT License///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the// Software is furnished to do so, subject to the following conditions://// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the// Software.//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////}}
Expand Down
142 changes: 142 additions & 0 deletions L298MotorPwm.spin
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{{
L298MotorsPwm.spin
Tom Doyle
25 Feb 2007
Starts a cog to maintain a PWM signal to the L298 chip
The control pins on the L298 are controlled by the forward and reverse procedures
Speed is controlled by the update procedure
In normal use it is not necessary to call any of these procedures directly as
they are called by the SetMotor.spin object
}}

CON

_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000


VAR

long duty, period, pPin, dirM, I1pin, I2Pin ' par access

byte cog

PUB start(EnPin, In1Pin, In2Pin, pulsesPerCycle) : success

' EnPin - L298 Enable Pin
' In1Pin - L298 Input 1 Pin
' In2Pin - L298 Input 2 Pin
' pulsesPerCycle - pulses per PWM cycle = clkfreq/pwmfreq

pPin := EnPin
I1pin := In1Pin
I2pin := In2Pin

duty := 0
period := pulsesPerCycle

reverse ' initialize dirM
success := cog := cognew(@entry, @duty)


PUB stop
{{ set esc PWM pin to off
stop cog }}

waitpeq(0, |< pPin, 0)
dira[pPin] := 0
if cog > 0
cogstop(cog)

PUB forward

dirM := !0

Pub reverse

dirM := 0


PUB update(dutyPercent)

duty := period * dutyPercent / 100


DAT

entry movi ctra,#%00100_000
movd ctra,#0

mov addr, par
add addr, #8 ' L298 Enable (PWM) pin number
rdword _Enpin, addr ' stored in _EnPin
movs ctra,_Enpin

mov temp, #1
shl temp,_Enpin ' L298 Enable (PWM) pin
or dira, temp ' make an output

mov addr, par
add addr, #16 ' L298 In1 pin
rdlong _In1Pin, addr ' stored in _In1Pin
mov temp, #1
shl temp,_In1pin ' L298 In1 pin
or dira, temp ' make an output

mov addr, par
add addr, #20 ' L298 In2 pin
rdlong _In2Pin, addr ' stored in _In2Pin
mov temp, #1
shl temp,_In2pin ' L298 In2 pin
or dira, temp ' make an output


mov frqa,#1

mov addr, par
add addr, #4 ' pulses per pwm cycle
rdlong _cntadd, addr
mov cntacc,cnt
add cntacc,_cntadd

:loop waitcnt cntacc,_cntadd

mov tempDir, outa

mov addr, par
add addr, #12 ' dirM
rdlong _dirM, addr ' store in _dirM

mov tempDir, outa

mov temp, #1
shl temp,_In1Pin ' L298 In1
test _dirM, 1 WZ ' check if direction = 1
muxz tempDir, temp ' set Input 1

mov temp, #1
shl temp,_In2Pin ' L298 In2
test _dirM, 1 WZ ' check if direction = 1
muxnz tempDir, temp ' set Input 2

mov outa, tempDir

rdlong _duty,par
mov temp, par
add temp, #1
rdlong _duty, temp
neg phsa,_duty
jmp #:loop

_dirM res 1 ' motor direction 0 or 1
_In1Pin res 1 ' L298 Input 1 Pin
_In2Pin res 1 ' L298 Input 2 Pin
tempDir res 1 ' temp direction
cntacc res 1
_duty res 1
_cntadd res 1
_Enpin res 1 ' L298 Enable Pin
addr res 1
temp res 1
Loading

0 comments on commit abfad9d

Please sign in to comment.