I'm way behind here, still trying to figure out how to do ZOOM calls. Microphone doesn't work because... well... "It's a Dell".
Anobium Said:"the DAT file in GCBASIC has historically ( before today ) has the register and register bits defined .... not register bit masks"
From "m4809def.inc"
; ADC_CTRLC masks
.equ ADC_PRESC_gm = 0x07 ; Clock Pre-scaler group mask
.equ ADC_PRESC_gp = 0 ; Clock Pre-scaler group position
.equ ADC_PRESC_0_bm = (1<<0) ; Clock Pre-scaler bit 0 mask
.equ ADC_PRESC_0_bp = 0
Here is my oppinion... and I may be dead wrong:
To me, as an asm guy, all these are is numbers. 1 shift left 0 times = 1 as in bm (bitmask)
bm, bp, gm is a concept of a programmer/SW engineer @ microchip. It used to be _BV or something like that.
at the end of the day you usually have one number coming out of any .equ value on the register definitions sheet(m4809def.inc).
BUT, if you want to insert .asm in with your basic these definitions are the common reference you have to work with.
It's not uncommon to redefine registers or bits in your code. with the new avr-0 chips, I like using sreg to save context in my ISR.
The "m4809def.inc" says that you must use CPU_SREG. I just make another .equ and make an alias I guess? I could change the definition back to SREG on the "m4809def.inc" file but I instead add this:
E.G.
.equ sreg = CPU_SREG
now I can use sreg wherever I want.
Not sure I'm understanding correctly what you are trying to convey.
In the C language,(USART1_CTRLB.TXEN) the dot method used quite a bit.
If it comes down to whether _bm, _bp, _gm ... maybe a conversion include file to "alias" these as _bm? ...I don't know
I'm halfway through your posts please be patient, I'm slow. Get back to you soon, Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As GCBASIC is a high level language the language is prefined and this is a guiding princple. That means the code is portable across PICs, AVRs, AVRDXs and LGT. So, I can rename whatever we need to but the process of renaming has to consistent applied across all of a CHIPFAMILY like all AVRDx, but, renaming is not something I we have done in the past.
The art here is exactly what you are doing. Create ASM that works and I can integrate that into the GCBASIC libraries. At the heart of the work today is your ASM ( I had no idea about the BPS calculation being diffevent from all previous chips).
The libraries do digitise knowledge. From your USART1 example that has been expanded to have all 5 usarts.
There is a huge amount of condition logic around the core operation but this is what GCBASIC need. They will not need to know how the ASM works ... it should just work for them.
Re USART1_CTRLB.TXEN: For this specific example TXEN is not defined ( along with all other register bits ) that I can find. It is not I the Inc file. Is it somewhere else ? If I reliably source the information then I can put in the DAT file. The DAT file is a representation of the INC plus a lot more information ( each chip family is DAT is sourced from different sources loke XML etc.)
Thanks for this help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anobium said :" I think ( please verify ) that we have to ignore the datasheet. As there is NO method to make AVRASM2 compile."
Atmel data sheets are notoriously less than great for errors and omissions. I think Microchip just cut and pasted Atmel's data sheet text into their own data sheets. I always go by the (m4809def.inc) Definitions file and cryptic error messages that the assembler/compiler gives. Data sheet is good for explaining(most of the time) what the bits do. Error messages can be looked up on the internet and sometimes give clues.
Anobium said: "For AVRDx then the _bp needs to be supported."
like I said earlier, there may be a work around for that as it can be converted and equated to something else.
.equsreg=CPU_SREG
Anobium said: " 3. The compiler needs to support AVRDx bit masks ( as sourced from the INC file )."
I think this would be easiest... but that does not mean that I am right.
Not sure this matters but I use standalone AVR-0 / 1 chips soldered to a breakout board with a separate USB to Serial bridge.
Yor compiled ASM code:
Loaded the compiled GC basic TX code onto my 4809 and it says:
"GCBASIC is supporting AVRDx with Serial operations" returns and repeats
Well done!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have will let you have all I have done today in my morning. The Serial send works across the different USARTs.
Question: With all previous AVRs had a 16-Bit BRG registercalled UBRR so this meant we used high speed/ double speed mode. Do AVRDx have something similar? This would explain the difference in the BPS calcs.
Or, do you have any other insights that would explain this to me? Is this the a clock divider? Or, is there a register.bit where we can set double speed mode ?
Evan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
PG 287 on my 4809 data sheet says:
23.3.3.2.4 Double-Speed Operation
Double-speed operation allows for higher baud rates under asynchronous operation with lower peripheral clock frequencies. This operation mode is enabled by writing the RXMODE bits in the Control B (USARTn.CTRLB) register
to 0x01
Here's a Free Running ADC example, with TCA PWM and TCB periodic interrupt.
You will probably have to comment out the [move_vectors] code
Greg
I have not dealt with double speed before. I will look into it a bit. Were you having issues with USART speed , or just wanting to implement it?
The next example is the ADC interrupt which feeds the ADC to the PWM.
Dont worry about Double Speed - I have added a new range check. Users can complaint later if they want double speed. This is probable needed when low chip mHz used and fast BPS are needed. Can be added later.
Thank for the ADC!
I still need the RX ASM. The RX ASM posted is 0 bytes long file. :-(
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hmmm... sorry, I will try to get code on the page before I send next time.
Resending MEGA4809_USART_RX_TX _ECHO.asm.
Got the video, Thanks it is good to have some context for my own understanding. A lot of information, Need to wrap my head around it.
Was thinking about doing receive and transmit interrupts... What is priority for you?
some of what we're doing will be new ground for me so please bear with me.
That info doesn't reflect the compiler architecture.
To check your compiler version (and architecture), on the IDE press F4, and then type "version" to filter and then click on "GC BASIC Compiler Version".
On the bottom of the window you will get something like this: 2024.08.15 (Windows 64 bit) : Build 1409
Angel
Last edit: Angel Mier 2024-08-20
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
To @evanvennn
If you send a compiler binary to cribcat, send it with the name "gcbasic32.exe" or "gcbasic64.exe" other wise the compiler will be reverted to the release version if cribcat doesn't change the option of the compiler architecture to "developer" in the options.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, I have the 32 bit version:
2024.08.15 (Windows 32 bit) : Build 1409
My computer is 64 bit but the 32 bit version is what the link on the Sourceforge download gave me.
running windows 11 ... if that matters.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Greg the TX code and a bit of RX code. Thank you again.
Send serial characters will return the characters. This program checks the USART interrupt flag, then send the received data via the HSerSend( data, usart ) routines. All very simple.
The program below can be compiled and programmed into the Mega4809 using Build 1414 ( DEV or Mainstream ) for the AVRDx chips.
#chip mega4809
#option Explicit
#DEFINE USART3_BAUD_RATE 9600
#DEFINE USART3_TX_BLOCKING
#DEFINE USART3_DELAY OFF
// This assumes you are using a serial PC terminal.
// Main program
// Wait for terminal to settle
wait 1 s
HSerPrintStringCRLF "GCBASIC serial loop back"
HSerPrintStringCRLF "Data received will be sent back"
Do
If USART3HasData Then
HSerSend ( USART3_RXDATAL, 3) // HserSend needs to be told which USART to use, this will be fixed when only one USART is defined in program
End If
Loop
Shows
I uploaded a text file to the terminal- I did not type all this!!
To change to USART1
Change to USART1. Change all instants of USART3 to USART1 and change the HserSend second parameter to 1.
HSerSend needs a tweak to automatically support the default USART when only one USART is selected. A job for another day.
HSerReceive is next to be implemented, then implement USART interrupts. I will write a demo for a serial buffer ring to show HSerReceive and HserSend with the use of the USART interrupts - what fun.
:-)
Last edit: Anobium 2024-08-20
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anobium: --It would be good to get PWM using OSC internal frequency at 20mHz
I will write it for the PWM only, but if you need it now, the Timer Counter A 16Bit PWM @ 20 MHz should be in the [MEGA4809_ADC__INTERRUPT] Demo. The ADC interrupt feeds the PWM .
G
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm way behind here, still trying to figure out how to do ZOOM calls. Microphone doesn't work because... well... "It's a Dell".
Anobium Said:"the DAT file in GCBASIC has historically ( before today ) has the register and register bits defined .... not register bit masks"
From "m4809def.inc"
; ADC_CTRLC masks
.equ ADC_PRESC_gm = 0x07 ; Clock Pre-scaler group mask
.equ ADC_PRESC_gp = 0 ; Clock Pre-scaler group position
.equ ADC_PRESC_0_bm = (1<<0) ; Clock Pre-scaler bit 0 mask
.equ ADC_PRESC_0_bp = 0
Here is my oppinion... and I may be dead wrong:
To me, as an asm guy, all these are is numbers. 1 shift left 0 times = 1 as in bm (bitmask)
bm, bp, gm is a concept of a programmer/SW engineer @ microchip. It used to be _BV or something like that.
at the end of the day you usually have one number coming out of any .equ value on the register definitions sheet(m4809def.inc).
BUT, if you want to insert .asm in with your basic these definitions are the common reference you have to work with.
It's not uncommon to redefine registers or bits in your code. with the new avr-0 chips, I like using sreg to save context in my ISR.
The "m4809def.inc" says that you must use CPU_SREG. I just make another .equ and make an alias I guess? I could change the definition back to SREG on the "m4809def.inc" file but I instead add this:
E.G.
.equ sreg = CPU_SREG
now I can use sreg wherever I want.
Not sure I'm understanding correctly what you are trying to convey.
In the C language,(USART1_CTRLB.TXEN) the dot method used quite a bit.
If it comes down to whether _bm, _bp, _gm ... maybe a conversion include file to "alias" these as _bm? ...I don't know
I'm halfway through your posts please be patient, I'm slow. Get back to you soon, Thanks
As GCBASIC is a high level language the language is prefined and this is a guiding princple. That means the code is portable across PICs, AVRs, AVRDXs and LGT. So, I can rename whatever we need to but the process of renaming has to consistent applied across all of a CHIPFAMILY like all AVRDx, but, renaming is not something I we have done in the past.
The art here is exactly what you are doing. Create ASM that works and I can integrate that into the GCBASIC libraries. At the heart of the work today is your ASM ( I had no idea about the BPS calculation being diffevent from all previous chips).
The libraries do digitise knowledge. From your USART1 example that has been expanded to have all 5 usarts.
There is a huge amount of condition logic around the core operation but this is what GCBASIC need. They will not need to know how the ASM works ... it should just work for them.
Re USART1_CTRLB.TXEN: For this specific example TXEN is not defined ( along with all other register bits ) that I can find. It is not I the Inc file. Is it somewhere else ? If I reliably source the information then I can put in the DAT file. The DAT file is a representation of the INC plus a lot more information ( each chip family is DAT is sourced from different sources loke XML etc.)
Thanks for this help.
Anobium said :" I think ( please verify ) that we have to ignore the datasheet. As there is NO method to make AVRASM2 compile."
Atmel data sheets are notoriously less than great for errors and omissions. I think Microchip just cut and pasted Atmel's data sheet text into their own data sheets. I always go by the (m4809def.inc) Definitions file and cryptic error messages that the assembler/compiler gives. Data sheet is good for explaining(most of the time) what the bits do. Error messages can be looked up on the internet and sometimes give clues.
Anobium said: "For AVRDx then the _bp needs to be supported."
like I said earlier, there may be a work around for that as it can be converted and equated to something else.
Anobium said: " 3. The compiler needs to support AVRDx bit masks ( as sourced from the INC file )."
I think this would be easiest... but that does not mean that I am right.
Not sure this matters but I use standalone AVR-0 / 1 chips soldered to a breakout board with a separate USB to Serial bridge.
Yor compiled ASM code:
Loaded the compiled GC basic TX code onto my 4809 and it says:
"GCBASIC is supporting AVRDx with Serial operations" returns and repeats
Well done!
OK. I will look at this method.
Done. All the masks are now available.
I have extended the DAT file model and the compiler internals to handle the INC file format. Works ok.
Great news!!!
I have will let you have all I have done today in my morning. The Serial send works across the different USARTs.
Question: With all previous AVRs had a 16-Bit BRG registercalled UBRR so this meant we used high speed/ double speed mode. Do AVRDx have something similar? This would explain the difference in the BPS calcs.
Yours:
BPSCalcResult = INT(( 64 * ( ChipMHz * 1000000 ))/( 16 * USART_BAUD_RATE )+0.5)
Existing for legacy AVRs
BPSCalcResult = ChipMHz * 1000000 / (16 * USART_BAUD_RATE) - 1
Or, do you have any other insights that would explain this to me? Is this the a clock divider? Or, is there a register.bit where we can set double speed mode ?
Evan
PG 287 on my 4809 data sheet says:
23.3.3.2.4 Double-Speed Operation
Double-speed operation allows for higher baud rates under asynchronous operation with lower peripheral clock frequencies. This operation mode is enabled by writing the RXMODE bits in the Control B (USARTn.CTRLB) register
to 0x01
Here's a Free Running ADC example, with TCA PWM and TCB periodic interrupt.
You will probably have to comment out the [move_vectors] code
Greg
I have not dealt with double speed before. I will look into it a bit. Were you having issues with USART speed , or just wanting to implement it?
The next example is the ADC interrupt which feeds the ADC to the PWM.
Dont worry about Double Speed - I have added a new range check. Users can complaint later if they want double speed. This is probable needed when low chip mHz used and fast BPS are needed. Can be added later.
Thank for the ADC!
I still need the RX ASM. The RX ASM posted is 0 bytes long file. :-(
USART Operations
With the help of Cribcat/Greg I have added USART operations to GCBASIC.
The video shows:
Hardware USART
Software USART
Enjoy
A deep dive into the USART library
Greg - this is for you. https://1drv.ms/u/s!Ase-PX_n_4cvhPxg06utnSsx-XiDbg?e=JRb1m3
I will delete once you tell me to delete it.
To make this work. You need a new USART.h, new DAT file, updated compiler. Are you using the 64bit or 32bit GCBASIC compiler?
Let me know what version I need to share.
Hmmm... sorry, I will try to get code on the page before I send next time.
Resending MEGA4809_USART_RX_TX _ECHO.asm.
Got the video, Thanks it is good to have some context for my own understanding. A lot of information, Need to wrap my head around it.
Was thinking about doing receive and transmit interrupts... What is priority for you?
some of what we're doing will be new ground for me so please bear with me.
USART interrupts would be the next to add. So, yes please.
will do... USART Interrupts.
Here is TCB PWM 8bit
My oscilloscope is out of calibration, so I can not check frequency but clearly it does PWM.
Evan, You can take down the video... thanks for the info.
Have the main RX,TX interrupts attached. Let me know if i missed something
thanks
Greg
I think my version is the 32bit GCBASIC compiler.
This was on the about tab:
OS: Windows_NT ia32 10.0.22631 ... does that help?
That info doesn't reflect the compiler architecture.
To check your compiler version (and architecture), on the IDE press F4, and then type "version" to filter and then click on "GC BASIC Compiler Version".
On the bottom of the window you will get something like this:
2024.08.15 (Windows 64 bit) : Build 1409
Angel
Last edit: Angel Mier 2024-08-20
To @evanvennn
If you send a compiler binary to cribcat, send it with the name "gcbasic32.exe" or "gcbasic64.exe" other wise the compiler will be reverted to the release version if cribcat doesn't change the option of the compiler architecture to "developer" in the options.
Yes, I have the 32 bit version:
2024.08.15 (Windows 32 bit) : Build 1409
My computer is 64 bit but the 32 bit version is what the link on the Sourceforge download gave me.
running windows 11 ... if that matters.
Tomorrow build 1414 will be available ( likely before midnight London time). Use that version as it is the latest build I have.
I have in my backlog. I have ASM from you on all of these !! Remarkable1
It would be good to get PWM using OSC internal frequency at 20mHz
Most grateful.
Evan
Here is the PWM with TCB in 32K internal OSC ULP.
Example USART loopback
Thanks Greg the TX code and a bit of RX code. Thank you again.
Send serial characters will return the characters. This program checks the USART interrupt flag, then send the received data via the HSerSend( data, usart ) routines. All very simple.
The program below can be compiled and programmed into the Mega4809 using Build 1414 ( DEV or Mainstream ) for the AVRDx chips.
Shows
I uploaded a text file to the terminal- I did not type all this!!
To change to USART1
Change to USART1. Change all instants of USART3 to USART1 and change the HserSend second parameter to 1.
HSerSend needs a tweak to automatically support the default USART when only one USART is selected. A job for another day.
HSerReceive is next to be implemented, then implement USART interrupts. I will write a demo for a serial buffer ring to show HSerReceive and HserSend with the use of the USART interrupts - what fun.
:-)
Last edit: Anobium 2024-08-20
Thrilled to see the progress!
Anobium: --It would be good to get PWM using OSC internal frequency at 20mHz
I will write it for the PWM only, but if you need it now, the Timer Counter A 16Bit PWM @ 20 MHz should be in the [MEGA4809_ADC__INTERRUPT] Demo. The ADC interrupt feeds the PWM .
G
I think you may need to comment out the move vectors code to run on your boards... my fuses are wrong so I need that code.
Ok, updated TCA 20MHz PWM.
Here is Timer Counter A Splitmode PWM. Splits the 16bit timer to function as two 8 bit PWMs.