Home
Prox / RFID
Verichips
Ladder Logic
[interfacing] †
Tube Joints
Key Code From Photo
SolveSpace (3d CAD)
SketchFlat (2d CAD)
Photographs
Miscellany
Resume / Consulting
Contact Me

LDmicro Forum - How to access CPU registers from ladder ?

(you are viewing a thread; or go back to list of threads)

How to access CPU registers from ladder ? (by Oguz)
I am using ldmicro to run small programs on my AVR ( AT90USB647 ) board and it works well but I can not set my I/O pins as outputs because the I/O needs to be initialized as outputs using data direction register.

Is there a way to access CPU registers using ldmicro ?

For example, how can I assign 0xFF to DDRD ( data direction register for Port D ) ?

Thanks

Oz
Thu Aug 27 2009, 23:25:59
(no subject) (by David R)
Have you tried going to the bottom of the of the screen and double clicking on the name of the coil that you want to
use and selecting the pin-out you want see the Tutorial.
Regards
David.
Fri Aug 28 2009, 16:20:41
More information on outputs (by Oguz)

I single stepped through the ldmicro-generated hex file in AVR Studio using the built-in AVR simulator. The ladder compiler indeed generates correct code to program the Data Direction registers.

Unfortunately, upon comparing the datasheets, I found out that the register map of AT90USB devices do not match those of ATMEGA devices.

I will have to add AT90USB support myself.

Thanks

Oz
Fri Aug 28 2009, 22:46:28
Strange behaviour of I/O on AT90USB647 (by Oguz)

I added support for AT90USB647 by editing mcutable.h and recompiling ldmicro. I then created a single rung ladder program that only has a negated coil tied to PD7. So PD7 is supposed to be always 0. I have a LED on this pin with pullup to 5 Volts on my board.

The LED does NOT turn on using the ladder program. If I do the same thing ( i.e. Reset PORTD.7 ) in BASCOM-AVR, the LED turns on.

I compared ldmicro hex to BASCOM-AVR hex in AVR Studio simulator. They both do the same thing: Set DDRD to 0x80 and leave PORTD as 0x00. However, BASCOM-AVR does this using I/O instructions ( IN and OUT ) and ldmicro does this using LDI, ST instructions. The outcome is the same in the simulator but not on the real board.

Any ideas ???

Few words on compiling under Windows:

- make.bat has reference to D=LDLANG_PT; I had to change this to D=LDLANG_EN

- Perl is needed; Strawberry Perl worked fine.

- Makefile has references to @cp and @mv; these could not be found. I had to change these to @copy

- Microsoft Windows 2003 Server Platform SDK had to be downloaded and installed. You need to do Start->Programs->Microsoft Platform SDK->Visual Studio Registration->Register PSDK Directories with Visual Studio for the first time before running ldmicro's make file.

Oz
Sat Aug 29 2009, 03:50:15
(no subject) (by Jonathan Westhues)
Have you checked whether any other registers need to be set to configure that pin as a GPIO (instead of an A/D pin, other peripheral pin, etc.)?

It may also be necessary to change some of the peripheral register definitions in avr.cpp, to make stuff like the UART and the PWM (and maybe even the timer, which determines the cycle time) work.
Sat Aug 29 2009, 04:49:15
Success, finally ! (by Oguz)

Finally it worked. AT90USB registers are quite different than ATMEGA. Even bit positions inside the same named registers are different. I had to make changes for timer registers and UART registers. I have not touched ADC or EEPROM yet so I m sure that they will not work.

I made

static DWORD REG_OCR1AH;
static DWORD REG_OCR1AL;
static DWORD REG_TCCR1A;
static DWORD REG_TCCR1B;

variables instead of #define's.

I have attached my latest files. Now there are 14 supported microcontrollers. The latest is AT90USB647 ( AT90USB646 should also work but I do not have hardware to test ).

I have also attached a test ladder program that blinks the LED's connected to PD6 and PD7 on my board.

Oz
Sat Aug 29 2009, 12:18:47, download attachment ldmicro.zip
Post a reply to this comment:
Your Name:
Your Email:
Subject:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):