Author Topic: LGT8F328P - clone of ATMega328 with lots of extras!  (Read 13750 times)

0 Members and 2 Guests are viewing this topic.

Offline FungusTopic starter

  • Super Contributor
  • ***
  • Posts: 16562
  • Country: 00
LGT8F328P - clone of ATMega328 with lots of extras!
« on: June 02, 2022, 06:30:38 am »
Given the rocketing price of AVR Aduinos, I've just been looking at these things...

https://www.aliexpress.com/wholesale?SearchText=LGT8F328P

The extra features are very interesting for a project I have in mind, both for the DAC and for the extra ALU.

I ordered a few (some purple, some green) and so far so good. They work just like Arduinos in the Arduino IDE.

Information on the extra features is very sparse though. There's the original datasheet that's been machine-translated by google on a couple of github repositories and very little else.

(FWIW: Google translate has improved, you can re-translate the manual today and google does a much better job)

I'm programming mine in assembly language. I'm particularly interested in the 16-bit ALUs. Has anybody else use them or does everybody simply switch them to 32MHz mode and use them as a faster Arduinos?

The way the new ALU works is not by having extra instructions (there's no bits left in the Atmel instruction set) but by monitoring the bus and seeing what you're doing.

eg. The 2kB of RAM is mapped twice in the address space on these chips. If you access the copy of RAM at 0x2000 then you can load/store 16-bit values in a single clock.

Example problem:

This instruction loads r0 with an 8-bit value from address 0x0100:

Code: [Select]
LDS R0,0x100
This instruction loads the DX register in the new ALU with a 16-bit value at 0x0100 and leaves r0 unchanged:

Code: [Select]
LDS R0,0x2100
(ie. same opcode, different result depending on the RAM address)

Problem:
It doesn't seem to work for any register other than DX. I believe I'm supposed to be able to load any register but it fails:

Code: [Select]
LDS R1,0x2100   ; Supposed to load the DY resister, but the value goes into DX instead!

Conversely, using the STS instruction to store 16-bit numbers works just fine:

Code: [Select]
STS 0x2100,R0   ; Store DX resister to location 0x100
STS 0x2102,R1   ; Store DY resister to location 0x102 - works perfectly!
STS 0x2104,R2   ; Store DAH to location 0x104 - works!
STS 0x2106,R3   ; Store DAL to location 0x106 - works!

 :scared:
« Last Edit: June 02, 2022, 06:44:49 am by Fungus »
 
The following users thanked this post: paf, ledtester

Offline GromBeestje

  • Frequent Contributor
  • **
  • Posts: 276
  • Country: nl
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #1 on: June 03, 2022, 01:11:16 pm »
How do you verify the values in the registers?
I've looked at the Logic Green datasheets way back when, and it mentioned some debugging interface. However, I haven't found a suitable debugger or any information about the debugging protocol. Have you found a suitable debugger to debug this chip?
 

Offline FungusTopic starter

  • Super Contributor
  • ***
  • Posts: 16562
  • Country: 00
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #2 on: June 03, 2022, 02:07:57 pm »
How do you verify the values in the registers?

I read them back (using the instructions that I found to work) and send them to the serial monitor in the Arduino IDE.

"dump_cpu" gives me a printout like this:

Code: [Select]
Program started OK

uDSC test 5
r1:r0 cafe  r9:r8   0000  r17:r16 0000  r25:r24 0135 
r3:r2 cafe  r11:r10 0000  r19:r18 4567       X: 2106
r5:r4 0000  r13:r12 0000  r21:r20 89ab       Y: 05d3
r7:r6 0000  r15:r14 0000  r23:r22 cdef       Z: 210c
DX: dead  DY: beef  DA: cafebabe

 :)

I can send you a copy of the code if you want to fiddle around.
« Last Edit: June 03, 2022, 02:14:29 pm by Fungus »
 

Offline FungusTopic starter

  • Super Contributor
  • ***
  • Posts: 16562
  • Country: 00
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #3 on: June 03, 2022, 08:04:41 pm »
Here's a copy of the code I've been using. Decompress it in your sketches folder.

nb. You don't need to do anything to the Arduino IDE, just connect up your LGT8F328P and select "Pro Mini" in the boards menu. It should work.

 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 1965
  • Country: us
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #4 on: June 03, 2022, 09:09:45 pm »
Is there any information on how deeply they sleep?  A bare bones 328P will sleep at some fraction of a microamp.  Will this one do that too?
 

Offline FungusTopic starter

  • Super Contributor
  • ***
  • Posts: 16562
  • Country: 00
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #5 on: June 04, 2022, 05:40:06 am »
Is there any information on how deeply they sleep?  A bare bones 328P will sleep at some fraction of a microamp.  Will this one do that too?

I imagine it will.

The datasheet I've got doesn't have any hard numbers but it talks a lot about the chip's power saving features. It has all the power saving modes of the 328P plus a few more.

I only have boards with built-in serial chip so it's a bit hard to test bare chip consumption.

« Last Edit: June 04, 2022, 07:17:48 am by Fungus »
 

Offline eblc1388

  • Frequent Contributor
  • **
  • Posts: 393
  • Country: gb
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #6 on: June 04, 2022, 11:14:14 am »
I hated datasheet that doesn't contains bookmarks for sections. Attached is the V1.0.5 document with three levels of bookmarks added for easy reference. It only takes me a few hours of work to do that.


 
The following users thanked this post: oPossum, paf, ralphrmartin, Fungus, ledtester, MK14

Offline FungusTopic starter

  • Super Contributor
  • ***
  • Posts: 16562
  • Country: 00
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #7 on: June 04, 2022, 04:08:53 pm »
I hated datasheet that doesn't contains bookmarks for sections. Attached is the V1.0.5 document with three levels of bookmarks added for easy reference. It only takes me a few hours of work to do that.

I've been doing the same as I go along. Not so systematic/detailed though.  :-+
 

Offline FungusTopic starter

  • Super Contributor
  • ***
  • Posts: 16562
  • Country: 00
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #8 on: June 04, 2022, 07:09:15 pm »
Summing up what I've found so far about the uDSC data transfer instructions:

Works:
Code: [Select]
in DX/DY/DA,address
out address,DX/DY/DA
sts address,DX/DY/DA   ; (via register names r0/r1/r2/r3)
ld DX/DY/DA,X/Y/Z
ld DX/DY/DA,X/Y/Z+
ld DX/DY/DA,-X/Y/Z
ldd DX/DY/DA,Z+q
st X/Y/Z,DX/DY/DA
st DX/DY/DA,X/Y/Z+
st DX/DY/DA,-X/Y/Z
std DX/DY/DA,Z+q

Doesn't work:
Code: [Select]
lds address,DX/DY/DA  ; nb. DX works, the others don't
ldd Rn,Z+q
std Rn,Z+q

(I'm not even sure what the last two are supposed to do, I can't get them to do anything at all... anybody?)

nb. I've tested on different boards (purple ones and green ones) so I don't think it's a faulty chip.

The datasheet goes on and on for two pages about how the "LDD Rn,Z+q" modes update Z after execution but it's the exact opposite of what's needed IMHO. I'd much rather Z stayed where it is so I can access a bunch of variables in a struct using Z as a base. It's made doubly painful by q only being positive so you can't go backwards. I'm predicting a lot of saving/restoring of the Z register!

There's even a half page diagram explaining how "Z+2" can give sequential access ... but if I want sequential data access I can just use "LD Rn,Z+". It works perfectly, changing Z by 2 after execution. :palm:

Meanwhile: The other instructions get almost no coverage at all, eg. The only clue that LDS/STS instructions can be used in this context is in the sentence "LDS/STS in the LGT8XM instruction set can access the 0x2100~0x28FF area, but the LDD/STD Y/Z+q addressing mode is more efficient."

(it's not more efficient if you have to set up Z first, eg. to load a single variable. I'd much rather have a working LDS instruction instead, but that's broken!)



As always, I guess I'll just have to muddle through using the instructions that seem to work... it's still going to be a win without 16-bit LDS.

« Last Edit: June 07, 2022, 02:16:32 pm by Fungus »
 

Offline Kerlin

  • Regular Contributor
  • *
  • Posts: 181
  • Country: au
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #9 on: June 07, 2022, 12:06:58 am »
Thanks for the update.
Interesting to see how other information seems to have been deliberately derailed then locked out.
No such problems here.
Do you know what the thread is about and are Comprehending what has been said ?
 

Offline tepalia02

  • Regular Contributor
  • *
  • Posts: 100
  • Country: bd
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #10 on: June 19, 2022, 02:14:21 pm »
Datasheet available?
 

Offline FungusTopic starter

  • Super Contributor
  • ***
  • Posts: 16562
  • Country: 00
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #11 on: June 19, 2022, 02:40:05 pm »
Datasheet available?

I grabbed the Chinese datasheet and ran it through Google translate.

Datasheet: http://www.lgtic.com/upload/lgt8fx8p/LGT8FX8P_databook_v1.0.4.pdf

Translate it here: https://translate.google.com/?sl=auto&tl=en&op=docs

That's how all the other "English datasheets" on the web have been made, it's worth doing it again because they're mostly three or four years old and google constantly evolves.

There's enough information in there to figure out what you need to know. Don't forget that it's ATMega328 compatible so you can refer to the Atmel datasheet for most things and only use the translated datasheet for LGT-specific features.

There's a few Githubs with other info and system files that are tweaked to fix millis(), serial baud rates, etc. for 32MHz:

https://github.com/dbuezas/lgt8fx

https://github.com/RalphBacon/LGT8F328P-Arduino-Clone-Chip-ATMega328P
« Last Edit: June 19, 2022, 02:43:36 pm by Fungus »
 
The following users thanked this post: paf

Offline tepalia02

  • Regular Contributor
  • *
  • Posts: 100
  • Country: bd
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #12 on: June 25, 2022, 10:22:28 am »
 Thank you so much for all this info and links.
 
The following users thanked this post: Fungus

Offline agarza

  • Newbie
  • Posts: 2
  • Country: mx
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #13 on: July 26, 2022, 11:21:38 pm »
Is there any information on how deeply they sleep?  A bare bones 328P will sleep at some fraction of a microamp.  Will this one do that too?

I imagine it will.

The datasheet I've got doesn't have any hard numbers but it talks a lot about the chip's power saving features. It has all the power saving modes of the 328P plus a few more.

I only have boards with built-in serial chip so it's a bit hard to test bare chip consumption.

The best power consumption on sleep I have achieved is ~170µA, nowhere near the 1µA@3.3V that is mention on the manual
 
The following users thanked this post: Fungus

Offline FungusTopic starter

  • Super Contributor
  • ***
  • Posts: 16562
  • Country: 00
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #14 on: July 27, 2022, 12:17:09 am »
The best power consumption on sleep I have achieved is ~170µA, nowhere near the 1µA@3.3V that is mention on the manual

That seems very high. What's your sleep code?
 

Offline FungusTopic starter

  • Super Contributor
  • ***
  • Posts: 16562
  • Country: 00
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #15 on: July 27, 2022, 12:31:20 am »
Just thought I'd throw this out there...

Does anybody here have a deepl account? Can you translate the datasheet using that and upload it here to see if it's any better?

https://www.deepl.com/translator

 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 1965
  • Country: us
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #16 on: July 27, 2022, 01:53:21 am »
Here's my sleep test code for the 328P.  It produces sleep current less than 1uA if the chip is a genuine 328P (not all are).  It works on a Pro Mini with regulator and LED removed.  I don't know if it's at all appropriate for this new chip.
 
Code: [Select]
#include <Wire.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
int i;

void setup(){

  for (i = 0; i < 20; i++) {          // all pins to one rail or the other
    pinMode(i,OUTPUT);
    digitalWrite(i,LOW);
  }
  ADCSRA = 0;                         // disable ADC for power saving
  wdt_disable();                      // disable WDT for power saving
  set_sleep_mode (SLEEP_MODE_PWR_DOWN); // Deep sleep
  sleep_enable();
  sleep_bod_disable();                // disable brownout detector during sleep
  sleep_cpu();                        // now go to sleep

}

void loop(){
}
 
The following users thanked this post: elecdonia, YurkshireLad

Offline rooppoorali

  • Regular Contributor
  • *
  • Posts: 100
  • Country: bd
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #17 on: July 27, 2022, 09:35:10 am »
Are they interchangeable? Can we write code for LGT8F328P using Atmel Studio and load the hex file using AVRdude? Just like the way we do with ATMega328?
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 1965
  • Country: us
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #18 on: July 27, 2022, 02:41:48 pm »
Ralph Bacon made a very good video on this chip a few years ago.



 
The following users thanked this post: elecdonia

Offline FungusTopic starter

  • Super Contributor
  • ***
  • Posts: 16562
  • Country: 00
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #19 on: July 27, 2022, 03:52:03 pm »
Here's my sleep test code for the 328P.  It produces sleep current less than 1uA if the chip is a genuine 328P (not all are).   I don't know if it's at all appropriate for this new chip.
 
Code: [Select]
#include <Wire.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
int i;

void setup(){

  for (i = 0; i < 20; i++) {          // all pins to one rail or the other
    pinMode(i,OUTPUT);
    digitalWrite(i,LOW);
  }
  ADCSRA = 0;                         // disable ADC for power saving
  wdt_disable();                      // disable WDT for power saving
  set_sleep_mode (SLEEP_MODE_PWR_DOWN); // Deep sleep
  sleep_enable();
  sleep_bod_disable();                // disable brownout detector during sleep
  sleep_cpu();                        // now go to sleep

}

void loop(){
}

Thanks. That doesn't prove it 100% though, there could be a problem in the libraries. Maybe a peripheral is left powered on or something.

It works on a Pro Mini with regulator and LED removed.

The best sort of Pro Mini.  :)
 

Offline FungusTopic starter

  • Super Contributor
  • ***
  • Posts: 16562
  • Country: 00
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #20 on: July 27, 2022, 03:54:35 pm »
Are they interchangeable? Can we write code for LGT8F328P using Atmel Studio and load the hex file using AVRdude? Just like the way we do with ATMega328?

The code is interchangeable, yes.

I can use one by selecting "Pro Mini" in the Arduino IDE so I guess the bootloaders are compatible, too.

The main differences are lack of EEPROM, no fuse bits, no ICSP (it has a JTAG-like interface for programming/debugging).

 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4196
  • Country: us
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #21 on: July 28, 2022, 11:54:00 pm »
Quote
Are they interchangeable?
Some of the instruction timings are slightly different.  (Several traditionally 2-cycle instructions only take one cycle.  Although this is also true of the newer AVRs, though.)
 

Offline FungusTopic starter

  • Super Contributor
  • ***
  • Posts: 16562
  • Country: 00
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #22 on: July 29, 2022, 06:45:59 am »
Quote
Are they interchangeable?
Some of the instruction timings are slightly different.  (Several traditionally 2-cycle instructions only take one cycle.  Although this is also true of the newer AVRs, though.)

And several traditionally 3-cycle instructions only take two cycles.
 

Offline rooppoorali

  • Regular Contributor
  • *
  • Posts: 100
  • Country: bd
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #23 on: July 29, 2022, 08:08:54 am »
Thanks for answering to my questions , dear all.
 

Offline FungusTopic starter

  • Super Contributor
  • ***
  • Posts: 16562
  • Country: 00
Re: LGT8F328P - clone of ATMega328 with lots of extras!
« Reply #24 on: July 29, 2022, 08:21:31 am »
This doc has a comparison of the instructions that are faster.

Some of those will have a big impact on performance, especially the faster push/pop.

« Last Edit: July 29, 2022, 08:25:35 am by Fungus »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf