Thursday, July 29, 2010

July 29 Clock Frequency

Lego open source firmware and Lejos both use 48 054 850 for 48Mhz instead of 48 000 000.
The SPI interface uses this value, so I started asking why the difference.
(too curious to just change)
Answer from the nxtasy hardware forum is it must be a multiple of the clock crystal.
The USB will not work if the value is too far off.

In AT91 datasheet p.26 states maximum limits for the crystal are listed for the USB  and debugging to work.

Monday, July 19, 2010

July 19 Started Display

Switched from motor to display while have little time this week

Just a collection of notes:
Started SPI interface to LCD display. There is more specific HW documentation making this easier than motors. However still have open questions at this point.

The SPI initialization for LCD seems straight-forward. (compiled)

Open questions:
Display size - Lego HW specs say 8lines by 100 pixels, but again in Lejos and Lego OS fw their is an option for 128 pixels. So need to test what we have.

Commands:  Where are all commands documented? Device specific?
5A - allow updates - documented.
5E - turn-off updates
other commands?

Questions related to lms eCos implementation:
(eCos implemention is from someone else, so learning code. )

Clock frequency for ARM7 is 48 MHz, which is exactly what is in the eCos include.
But comparing to both Lejos and Lego Open Source firmware includes, they use some slightly larger (48054850L). Need to find out why.

#ifdef includes should be chip related, but for arm7s256 some values needed seem to not be defined. Is this specific to our implementation or eCos?
Just adding what is need currently - but would like to know if left out originally on purpose or assumed not needed?

Background Info:
Serial_Peripheral_Interface_Bus great overview

Wednesday, July 14, 2010

July 13-14 avr clean-up +

avr code clean-up
Moving hardware related code out of avr_cntl and into their own class / source files.
So far: Buttons, Sensor (ports, led), Motor. The Sensors code will also need sub-class code. Generalized code will stay in Sensors.

Clearing out non-avr related code makes it much easier to see what the eCos thread is doing.  And what hardware is being set  or reset by what.

Buttons 

Besides moving existing button functions now

GetButtonVal function decodes the raw button value from avr.
(note: If speed becomes an issue an inline function or define macro can be used.)
 
Motor
- reset motor
- read tacho counts

options:
  • interrupts
  • motor thread
  • polling in avr thead
Which solution works and  is most accurate= right solution?

**Don't  use timer to generate signal because ecos uses it. ..._TC0 and ..._TC2 
That leaves the TC1 and TWI timers.

Sensors

- Moved sensor  functions and port managment out of avr_cntl 
- Consolidated all Led code in under Sensors.Before the led code was duplicated in at least 3 places:  lms main, avr cntl and led FB.
All led code is now in Sensors.c.  Currently #define macros are used since code in now under eCos, but a class method version is commented out under Forte code.






Monday, July 12, 2010

July 12 Tests

VLOW problem (when battery charged): Isolated the problem to how JTAG plugged into LEGO, so be careful how JTAG plugged into LEGO.
 

Sound sensor 
- high values = low noise
- added Sound FB
- idea is can read sensors be generalized

Comment out parallel communication for sensors 

AT91_PMC_PCER_PIOA); // enable parallel io-controller clock
question: Is this motor only related and not needed in port initialization code
result: leds worked, but motor did not





 

PMC and clocks see p.189 AT91SAM7S 

>> here
motor tests

- reset motor - looking for right place and way to reset motors during start-up and when
- read tacho counts - are interrupts needed?

Looking at interrupt controllers, but may be able to use a eCos thread and polling - but how accurate will it be?.

sensor routine

clean-up - move sensor and port initialization into its own area.

July 12 HW Link Collection


HW Link Collection
At moment I am mostly reading hw pdfs. Doesn't fit in with the earlier link collections.
Moved some older HW links here.  This is also to document where documents were found online, if they prove useful.

Firmware /OS
tinyos - see Lejos
LEGO NXT  Mindstorms - an early version is open source and on-line

nxos  French open source OS for NXT and intro to embedded systems
(July 12: either dissappeared or no longer open source since links are now missing.) 
What we are using:
http://blog.gmane.org/gmane.os.ecos.devel 


ARM SPI to LCD display (Ultrachip UC1601 for LMS)
(There are commands like 0xA5=on; 0xA4=off, but where are these command officially documented?)

http://www.artronic.pl/pdf/pl/UC1601.pdf UC1601 looks like the data sheet, but not from Ultrachip


http://www.mikrocontroller.net/topic/125585 has commands in comments for different LCD chip.
Looks like there are standard commands, but have not found where these are documented.


http://www.allshore.com/pdf/Avanti%20SBN1661G.pdf datasheet of SBN1661


Interfacing LCD via SPI Might be interesting.




July 12 Sound FB added

Added Sound FB
Less sound is higher value. 
For example was 940 with low room noise, and 550 when keys were jiggled.
The FB is the exact same ltSensor.rd FB, so may be able to generalize read -only sensors.

Thursday, July 8, 2010

July 7 Code / HW notes

Next goal is turning the tacho motor to turn by degrees.
Need I2C communication to the Tacho motor.
Following is mostly unrelated to motor:
what is learned + code clean-up finished or documented during the process. 
Needed in part because it was not clear which functions were motor related by their names specifically set and get functions did not specify, if they are for the motor or sensor. (Have already been renamed when unclear.)

Applications:
Need to initialize sensors and turn-off actuators=motors
 
In General:
When sending HW info do following in eCos:
    if (avr_state==e_READY)
      avr_state=e_COMMAND_PENDING;
Then in receive_thread it will be sent to the AVR 
Similiarly to recieve data from AVR add to the function:
      if (avr_state==e_READY)
          avr_state=e_COMMAND_PENDING;
clean-up all:
rename functions (set/get) so HW affected is reflected. But keep names small.
Examples:
  • GetOutputPower(PORT);  has been renamed to: Motor_AVR_GetPwr
  • SetInputPower to Sensor_AVR_SetInPwr  - sensors can are usually just read so was not clear.
General Problems :
Real LMS FORTE problem: no way to leave an application and reset all H: Other handle this by having a file system.  Is a file system appropriate for FORTE LMS? 

Open Questions: 
> Is a file system appropriate for FORTE LMS? in general or as part of a solution to solve the reset problem. 
> Timers used, sampling rates, clock frequency: Using HW or SW timers at the moments - what code indicates this?  think HW via eCos, but haven't found sampling rate in code yet

> LinkInitAVR function is never used, so why is it there?
> GetFirmwareVersion function returns the firmware version of what and via what? The battery is referenced.

Motor:
LMS NXT HW Developer Kit V.1 p.5  6 "The TACHOA0 and TACHOA1 are input ports that have a Schmitt trigger mounted between the ports and the input pins on the ARM7 processor. These two signals allow the possiblity of having a quadrature detector within the system. Within the standard firmware these two signals are used to count the number of tacho pulse from the motors and detect whether the motor is running clockwise or counterclockwise."



from Lego Education FAQ: HW questions:
"Q: What is a servo motor?
A: An electric motor whose speed or position is controlled by a closed loop feedback circuit that can sense its position. The speed of the motor is measured by a tachometer. The tachometer produces a voltage that is proportional to the speed. This voltage is compared to a reference point and the difference, or error, is used to adjust the speed of the motor, either up or down. "



How Lejos reads/ turns by degrees:



I2C interface used by motors is initialized via : at91sam7sxxx_i2c_init( )
io/i2c.h
http://ecos.sourceware.org/docs-latest/ref/i2c-porting.html porting to new HW incl.s bit banging info

Open Problem: Motors not reset to when booting
Solution: create a reset_all function

Applications: need to turn motors off when finished
don't  use timer to generate signal because ecos uses it. ..._TC0 and ..._TC2
   timers  TC0 and TC2  ..   see at91sam7s_misc.c
use any other ones


http://www.philohome.com/nxtmotor/nxtmotor.htm Motor insides

Motor Pins: tachoA0 (Motor) =INTA (motor wiring& connection to ARM7) = PA15/PGM3 (written on the INTA pin connection)  so pin 15 = MA0
Motor Pins: MA0/MA1= 15/1; MB0/MB1= 26/9; MC0/MC1= 0/8;  more exactly:

TachoA0
  = INTA0 = Pin 20 = PA15/PGM3
  = INTB0 = Pin 26 = PA26/PGMD14
  = INTC0 = Pin 48 = PA0/PGMEN0
TachoA1
  = DIRA = DIRA = Pin 47 = PA1/PGMEN1
  = DIRB = DIRB = Pin 30 = PA9/PGMM1
  = DIRC = DIRC = Pin 31 = PA8/PGMM0

Ultrasound:
 see twi.c two wire code for ultrasound

Color Sensor:
Can set power to european setting via FORTE using:
SetInputPower to Sensor_AVR_SetInPwr
  
Buttons:
clean-up needed:  
  • rename fns so button first
  • button pressed values included chorded
  • make clear what code is for debounce
ButtonState is: debounce right after a button changes values
ButtonVal    is: value of the buttons
http://www.rentron.com/Myke6.htm debouncing explained

Battery:
By testing the battery seems to run out too quickly. Then even plugged in it takes 15-30minutes before its charged enough to test. 
  • Short-term solution is to have the recharable battery plugged-in while testing. 
  • Long-term need to test what is eating up so much power so fast and correct the real problem.
Symptoms: 
  • LMS does not turn on  
  • Low Voltage message from openocd cmd
Timing:
The following appears in eCos recieve_thread function:

       cyg_thread_delay( 2 ); // 2 ... every 2 ms ?
It would be nice to know exactly how long between delays, rather than hoping its 2ms so...
In eCos Reference Manual under thread control  the 2 is clarified to be 2 clock cycles:
  • So what clock is used?
  • And how long is 2 cycles?