Hello experts,
ATmega 644, 82% Flash used, 16 Mhz, long term projekt house control.
I use cnt1 as running parameter for all time decisions: Cnt1 = 1200 *_hour + 20* _min + 1/3 _sec (summary)
Now I need a 90 Minute sequence, so I calculate Z_sch = cnt1 / 1800, but result is always wrong and changing.
A work around Z_sch = shift cnt1,right,8 : Z_sch = Z_sch/7 works, but this is not the same (/256/7=1792 not 1800).
All parameters are word. Who can help?
Best regards KSRM
[b:bd3bca0007][color=red:bd3bca0007](BASCOM-AVR version : 2.0.7.8 , Latest : 2.0.7.8 )[/b:bd3bca0007][/color:bd3bca0007]
↧
BASCOM-AVR : Division problem : NEWTOPIC
↧
BASCOM-AVR : Division problem : REPLY
you should post a sample that demonstrates this problem.
you can best debug your code :
- insert a print with the value you want to divide
- do the division
- print the result
- show the results
↧
↧
BASCOM-AVR : Xmega256A3BU ADCA vs. ADCB : REPLY
[quote:ee0f6e0f08]But I see that that was not enough since sample files have been subject to changes[/quote:ee0f6e0f08]
that is not the only problem : when you do not edit the file correct, we can search for hours. That is why it is important one shows the code!
[quote:ee0f6e0f08]the ADCs are not indentical [/quote:ee0f6e0f08]
yes they are. only one had no SCAN registers in the def file, but these are not used. And i did compare with the original atmel definition file and the file is ok. I did not check the errata of this chip.
[quote:ee0f6e0f08]But still I am curious why ADCB was used [/quote:ee0f6e0f08]
The original sample uses ADCA. The one using ADCB was modified to perform a test, but it was just for a quick hardware test, not intended to be distributed so comments were not changed.
↧
BASCOM-AVR : Xmega256A3BU ADCA vs. ADCB : REPLY
Hi Mark,
things have been sorted out.
-The Xplained Xm256 Hardware Users Guide is confusing.
That led me to the assumption that ADCA and ADCB on that board use the same Jumper pins which turns out to be not the case by looking into the circuit diagrams.
Additionally, the Jumper numbering (1-8 vs. 0-7 for the port pins) is confusing. Better they had omitted the Jumper numbering on the board since the CPU pin functions are printed correctly.
Now using the correct pins for ADCA your sample works using a battery and reversing polarity
[b:0bfff204b4]- provided we add [/b:0bfff204b4]
[code:1:0bfff204b4]Disable Interrupts[/code:1:0bfff204b4]
prior to the printing loop. Otherwise, not so much is printed. I had to add debugging prints to find out.
I had used the code posted by Mark above.
I wonder why that was not included in the sample file.
[b:0bfff204b4]Had the printing routines been changed between versions?[/b:0bfff204b4]
I have not checked ADCB since for that I would need to take out the board and to cut Jumper strips on the back side
but now I am confident (hm...) that it will work.
Thanks for your help.
Regards, Meister
[code:1:0bfff204b4] '-----------------------------------------------------------
' AD_Free_run_2_channel_8-bit_mode.bas
' (c) 1995-2011 MCS Electronics
' sample provided by MAK3
'-----------------------------------------------------------
' Configure the ADC of Port A to use 2 Channels with differential Input and with Gain
' Pina 0 (+) and Pina 4 (-) is used for Channel 0
' Pina 1 (+) and Pina 5 (-) is used for Channel 1
' In this Example we use 8-Bit Mode
' Bit 7 of the Result Byte is the Sign-Bit !
$regfile = "xm256a3budef.dat"
$crystal = 32000000 '32MHz
$hwstack = 64
$swstack = 40
$framesize = 40
Config Osc = Enabled , 32mhzosc = Enabled
Config Sysclock = 32mhz '--> 32MHz
'Serial Interface to PC
Config Com1 = 57600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Open "COM1:" For Binary As #1
Config Dp = comma 'comma is used as a separator (for FUSING function)
'Config Dp = "." 'dot is used as a separator (for FUSING function). You also need to change this "###.#" in the fusing funtion
Print #1 , "-----------------START-------------------"
'Config Interrupts
Config Priority = Static , Vector = Application , Lo = Enabled
Config Eeprom = Mapped 'when using EEPROM , add this config command
'For 12-Bit
Const Mv_per_adc_step = 1.007 'Vref = 3,3Volt/1,6 = 2,0625/2048 ADC Steps = 1.007 mV
'For 8 Bit
Const Mv_per_adc_step_8_bit = 16.11 'Vref = 3,3Volt/1,6 = 2,0625/128 ADC Steps = 16.11328 mV
Const Sample_count = 311
Dim Channel_0(sample_count) As Byte 'Measurement Array for Channel 0
Dim Channel_1(sample_count) As Byte 'Measurement Array for Channel 1
dim milli_volt as single
Dim Channel_0_ready_bit As Bit
Dim Channel_1_ready_bit As Bit
Dim Channel_0_sample_count As Word
Dim Channel_1_sample_count As Word
Dim X As Word
Set Adca_ctrla.1 'Flush the ADC Pipeline
'Configure ADC of Port A in FREE running mode
Config Adca = Free , Convmode = Signed , Resolution = 8bit , Dma = Off , _
Reference = Intvcc , Event_mode = None , Prescaler = 256 , Sweep = Ch01 , _
Ch0_gain = 1 , Ch0_inp = Diffwgain , Mux0 = &B00000000 , _
Ch1_gain = 1 , Ch1_inp = Diffwgain , Mux1 = &B00001001
' Ch2_gain = 1 , Ch2_inp = Diffwgain , Mux2 = &B00001001 _
' Ch3_gain = 1 , Ch3_inp = Diffwgain , Mux3 = &B00001001 _
' With MuxX you can set the 4 MUX-Register
' ADCA_CH0_MUXCTRL (for Channel 0)
' ADCA_CH1_MUXCTRL (for Channel 1)
' ADCA_CH2_MUXCTRL (for Channel 2)
' ADCA_CH3_MUXCTRL (for Channel 3)
' Mux0 = &B00000000 means:
' MUXPOS Bits = 000 --> Pin 0 is positive Input for Channel 0
' MUXNEG Bits = 00 --> Pin 4 is negative Input for Channel 0 (Pin 4 because of Differential with gain)
' Mux1 = &B00001001 means:
' MUXPOS Bits = 001 --> Pin 1 is positive Input for Channel 1
' MUXNEG Bits = 01 --> Pin 5 is negative Input for Channel 1 (Pin 5 because of Differential with gain)
' Reference Voltage = 3,3 Volt/1.6 = 2.06Volt
' Prescaler = 256 --> 32MHz/256 = 125KHz
' Prescaler = 128 --> 32MHz/128= 250KHz
' 12-Bit Mode:
' RES = ((Measurement_Value - Vin Neg)/Reference Voltage )* GAIN * 2048 = z.B. (400mv-0mV)/2062mV)* 1 * 2048 = 397
Print #1 , "ADCA_PRESCALER = " ; Bin(ADCA_PRESCALER)
Print #1 , "ADCA_CTRLB = " ; Bin(ADCA_CTRLB)
'Channel 0 Interrupt
On Adca_ch0 Channel_0_ready
'Channel 1 Interrupt
On Adca_ch1 Channel_1_ready
Enable Adca_ch0 , Lo
Enable Adca_ch1 , Lo
Enable Interrupts
Do
!nop
Loop Until Sample_count = Channel_1_sample_count 'Loop unitl the second Channel is ready
Disable Interrupts
Print #1 , " 300 Sample READY"
'Print Results to COM1
For X = 10 To 310 'We don't use the first 10 samples
Print ": ";
Print #1 , Channel_0(x).7 ; " / " ; 'print sign Bit in 8-Bit mode
If Channel_0(x).7 = 1 Then 'Sign Bit
Milli_volt = Channel_0(x) * Mv_per_adc_step_8_bit
Milli_volt = Milli_volt - 4096 'Additional calculation in 8-Bit Mode (Bit 7 is Sign Bit)
Print #1 , "A " ; X ; " ";
Print #1 , Fusing(milli_volt , "###,#") ; " " ;
Else
Milli_volt = Channel_0(x) * Mv_per_adc_step_8_bit
Print #1 , "A " ; X ; " ";
Print #1 , Fusing(milli_volt , "###,#") ; " " ;
End If
Print #1 , "B " ; X ; " ";
Milli_volt = Channel_1(x) * Mv_per_adc_step_8_bit
Print #1 , Fusing(milli_volt , "###,#")
waitms 1
Next
End 'end program
'Channel 0 conversion complete INTERRUPT SERVICE ROUTINE
Channel_0_ready:
Incr Channel_0_sample_count
Channel_0(channel_0_sample_count) = ADCA_CH0_RESL 'Low Byte of ADC Result
Return
'Channel 1 conversion complete INTERRUPT SERVICE ROUTINE
Channel_1_ready:
Incr Channel_1_sample_count
Channel_1(channel_1_sample_count) = ADCA_CH1_RESL 'Low Byte of ADC Result
Return[/code:1:0bfff204b4]
↧
KokkeKat FAT-free SD card lib : Porting KokkeKat to XMEGA : REPLY
Thanks again for thinking along Mark; much appreciated!
[quote:5a3270a375="albertsm"]sending 10 bytes is indeed sufficient. maybe you can show your circuit? [/quote:5a3270a375]
Testing with sending out 10 bytes had no response either; there's a nice 80 pulse from clock, but no reply to the subsequent CMD0 reset. (Tested with two SD cards.)
Please find attached the main schematic of my project.
[quote:5a3270a375] I think with SPIOUT the MOSI line remained at the last bit state[/quote:5a3270a375]
[quote:5a3270a375="albertsm"]the mode you chose has impact on this. have a look in the pdf at the various modes.
maybe you need mode 1?[/quote:5a3270a375]
I have not gone too deep into the KokkeKat Bascom code, but i changed the mega initialization to xmega code. The mega initialization has 'Polarity = Low, Phase = 0' which i figured to be equal to Mode 0?
What is troublesome is that the SD protocol while using SPI is a little different from ordinary SPI. To start with, you need to send the 74 clocks with CS not-asserted to get the SD going. (Which is a no-no in any regular SPI application.)
[quote:5a3270a375="albertsm"]also, how do you create those pulses? with a for next loop?
Maybe you can send an array() of 10 bytes instead. this also means that you do not need to alter the lib.[/quote:5a3270a375]
It's handled in the KokkeKat library (KokkeKat_FAT-free_SD_lib_code.bas); here's the relevant section:
[code:1:5a3270a375]Sdinit:
Sdstatus = 9 ' Minimum initialization detail unspecified error 2
Set Sd_cs ' Pull CS high
Sdcommand = &HFF ' Send at least 74 clock cycles with cs high
For Sdtempb = 1 To 74
Gosub Sdcommand1
Next Sdtempb
Reset Sd_cs
Gosub Sdcommand1 ' Send 8 additional clock cycles with cs low
Sdcommand = &H40 ' Send CMD0: &H40 &H00 &H00 &H00 &H00 &H95
Gosub Sdcommand1
Sdcommand = &H00
Gosub Sdcommand1
Gosub Sdcommand1
Gosub Sdcommand1
Gosub Sdcommand1
Sdcommand = &H95
Gosub Sdcommand1
Gosub Sdresponseloop
.....
[/code:1:5a3270a375]
and with Sdcommand1 defined as:
[code:1:5a3270a375]
'-------------------------------------------------------------------------------
Sdcommand1:
'Spiout Sdcommand , 1
Print #10 , Sdcommand ; 1 'BvD: Changed 14-04-2015 for xmega use
Return
[/code:1:5a3270a375]
And indeed, it is not good practice to alter the library code for xmega.lib. Might be good to have a replacement statement for SPImove and/or have a parameter in Config SPIx to set the code to be clocked out on using the Input statement; like with the mega initialization (like the 'SPIIN = 255' statement).
Are there alternative SD card routines for working with xmega? I don't think AVR-DOS has xmega support, has it?
Best thanks!
Bas
[/code][/quote]
↧
↧
Share your working BASCOM-AVR code here : ILI9341 with SW/HW SPI, 8/16 Bit parallel mode : REPLY
Hi,
it seems that Bascom tries to evaluate these #if statements:
[code:1:c8f8b88d55]#if Varptr( "Lcd_ctrl_port") = Varptr( "Portc")[/code:1:c8f8b88d55]
which are enclosed in an #if block which evaluates to false:
[code:1:c8f8b88d55]#if _xmega = True[/code:1:c8f8b88d55]
so normally the compiler should ignore these lines. I did not found this error, I've only tested if it compiles for the ATmega 128, which also has the Ports E and F, the Mega328 doesn't.
To get it to work, you need to comment out the lines 234-241:
[code:1:c8f8b88d55] #elseif Varptr( "Lcd_ctrl_port") = Varptr( "Porte")
Const Lcd_spi_ctrl = Spie_ctrl
Lcd_spi_status Alias Spie_status
Lcd_spi_data Alias Spie_data
#elseif Varptr( "Lcd_ctrl_port") = Varptr( "Portf")
Const Lcd_spi_ctrl = Spif_ctrl
Lcd_spi_status Alias Spif_status
Lcd_spi_data Alias Spif_data[/code:1:c8f8b88d55]
and the lines 374-385:
[code:1:c8f8b88d55] #elseif Varptr( "Lcd_backlight_port") = Varptr( "Porte")
#if Lcd_pin_backlight < 4
Const Lcd_pwm_ctrla = Tce0_ctrla
#else
Const Lcd_pwm_ctrla = Tce1_ctrla
#endif
#elseif Varptr( "Lcd_backlight_port") = Varptr( "Portf")
#if Lcd_pin_backlight < 4
Const Lcd_pwm_ctrla = Tcf0_ctrla
#else
Const Lcd_pwm_ctrla = Tcf1_ctrla
#endif[/code:1:c8f8b88d55]
or you could also just delete the #if _xmega = True code parts.
br
↧
BASCOM-AVR : Xmega256A3BU ADCA vs. ADCB : REPLY
- it is not my sample !
- print did not change but when you run the int all the time, there is little time for print. And why this change since it worked for xm128a1 as you tested before?
↧
KokkeKat FAT-free SD card lib : Porting KokkeKat to XMEGA : REPLY
- avr-dos does support xmega. and it supports sd and sdhc cards. 11 bit and 32 bit fat.
have a look in the MMCSD_HC.LIB from avr-dos. it might have a clue on how you can change the code.
- yes it is odd that MMC/SD uses spi like that. I had problems with a board which had a driver chip using CS to put the board in hi-z. It should also work when you make CS low. (in the lib you find code for SHIELD)
- i wonder if you tried using a mega with the same SD cards?
↧
BASCOM-AVR : Xmega256A3BU ADCA vs. ADCB : REPLY
Hi Mark,
[quote:5b86be112a]- it is not my sample ! [/quote:5b86be112a]
I meant that you had posted it.
[quote:5b86be112a]And why this change since it worked for xm128a1 as you tested before?[/quote:5b86be112a]
No, it was the same problem. I had disabled interrupts prior to printing also in the xm128a1 sample.
Since the Mak3 code certainly had been tested before publishing, that problem must have been seen. Why not?
Shouldn't the print routine better disable (and re-enable) disturbing interrupts?
I need to run the ADC-sample code repeatedly, like in an oscilloscope, and to print the data to the UART.
Do I actually need to disable all of the interrupts (by "disable Interrupts") or does it suffice to disable some low-level interrupts for printing?
And then, which interrupts need to be re-enabled to have the code running repeatedly after printing?
Does "Enable Interrupts" leave those interrupt settings intact that had been made at the beginning of the code?
Regards, Meister
↧
↧
BASCOM-AVR : OLED Display : REPLY
Hi,
Yes,it was a print mistake. 8x2 LCD --->8x2 Oled. I tried to modify my code. Added Initlcd and LCDCMD &H17 (before Do ...loop)but the result is always the same,no improvement. Oled display is showing something mostly strange characters and not stable charcters,always changing. Sometimes the correct characters displaying. Code is working proper with LC Display.
Here an exerpt of my code:
..........
[/code]
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
'Config Lcd = 16 * 2
Config Lcd = 16x2 ,
Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , E = Portb.4 , Rs = Portb.5
Config Lcdbus = 4
Initlcd
Lcdcmd &H17
Many Thanks for your good support.
Kind Regards
Hubert
↧
KokkeKat FAT-free SD card lib : Porting KokkeKat to XMEGA : REPLY
[quote:6613a3984b="albertsm"]- avr-dos does support xmega. and it supports sd and sdhc cards. 11 bit and 32 bit fat.
have a look in the MMCSD_HC.LIB from avr-dos. it might have a clue on how you can change the code.
- yes it is odd that MMC/SD uses spi like that. I had problems with a board which had a driver chip using CS to put the board in hi-z. It should also work when you make CS low. (in the lib you find code for SHIELD)
- i wonder if you tried using a mega with the same SD cards?[/quote:6613a3984b]
Hi Mark; life has become much simpler. Today i tested the AVR-DOS example and that works! AVR-DOS will surely serve my application and i'll switch it around to use AVR-DOS.
In the example i did have to change the SPI port; the example used SPID and my application has SPIC.
For future reference, here's what needs to be changed in Config_MMCSD_HC.INC:
[code:1:6613a3984b]
....
--------- Start of Section for HW-SPI ----------------------------------------
'Port C of ATXMEGA is used in this example as SPI Interface to SD-Card
'Portc_pin6ctrl = &B00_011_000 'Enable Pullup for MISO Pin << I commented this line out. I have a resistor on MISO already
' Define here Slave Slect (SS) Pin of Hardware SPI
Config PinC.4 = Output ' define here Pin for CS of MMC/SD Card << Change PIND/PORTD to PINC/PORTC
Mmc_cs Alias PortC.4
Set Mmc_cs
' Define here Slave Slect (SS) Pin of Hardware SPI
Config PinC.4 = Output ' define here Pin of SPI SS << Change PIND/PORTD to PINC/PORTC
Spi_ss Alias PortC.4
Set Spi_ss ' Set SPI-SS to Output and High por Proper work of
'FOR XMEGA DEVICES
#if _xmega = 1
'SPI Configuration for XMEGA
'Used Library = $LIB "MMCSD_HC.LIB"
'Portc.4 SS --> SD-Card Slave Select
'Portc.5 MOSI --> SD-Card MISO
'Portc.6 MISO --> SD-Card MOSI
'Portc.7 CLK --> SD-Card Clock
Config Spic = Hard , Master = Yes , Mode = 0 , Clockdiv = Clk2 , Data_order = Msb '<< Spid > Spic
Open "SPIC" For Binary As #14 '<< Spid > Spic
Const _mmc_spi = Spic_ctrl '<< Spid_ctrl > Spic_ctrl I missed this one at first!
...
[/code:1:6613a3984b]
The old 16Mb Canon card is detected (as 'SDSC Spec. 1.x'), but the file system can't be accessed. (Error 20) It does run well on my Windows PC and in a Rogue Robotic rMP3 Arduino shield (ATmega644P based)
The new SanDisk SD-HC 16Gb runs very well. (Reported as 'SDHC Spec. 2.0 or later') All functions give repeated valid results. (SanDisk type SDSDU-016G-U46)
My application needs the 16GB anyhow.. :wink:
Best kind thanks!
Bas
↧
BASCOM-AVR : OLED Display : REPLY
ok, this is 8x2. it is not clear from the datasheet (i found one here : http://www.lcd-module.com/fileadmin/eng/pdf/doma/olede.pdf ) what the address is for the data lines.
So selecting 16x2 is a good idea.
I found they use &H17 too. After that you need to use a CLS. And also DISPLAY ON.
I assume you checked if you connected properly? When you say a normal lcd works, i assume you use exact the same pins and hardware?
V0 is not connected.
it is probably a small issue but hard to 'debug' from here.
↧
BASCOM-AVR Old versions : Lin-bus : REPLY
Thank you Peter. I manage to addapt your rutine's with small change's to my need. :D
↧
↧
BASCOM-AVR : BOD under software control : REPLY
Hello all,
In Everts Asm code, is "sleep" the same as MCS BASCOM "Powerdown"?
If not, can anyone tell me how to modify Everts asm code to emulate the Powerdown command of MCS BASCOM?
Thank you,
Tim
↧
BASCOM-AVR Old versions : Lin-bus : REPLY
Ghitab
Maybe post a sample incase others are interested in experimenting with LIN?
↧
BASCOM-AVR Old versions : Lin-bus : REPLY
Here it is. :D
↧
BASCOM-AVR : Division problem : REPLY
Hello Mark,
thanks for the answer. I work with a QVGA display, so I see, what I do. It was difficult for me to ask such a silly question as a dummy, but I struggle many days with this problem. Hundreds of other calculations work, but not this. I doubled Stack and frame, no effect. As i mentioned, the program is large (54584 dec). Could there be any problem in the compiler?
best regards
KSRM
P.S. For the moment I have also problem to log in with my new password BCprivatier2015. I saw wrong road sign, but then log in works, as you see.
↧
↧
BASCOM-AVR : Need debounce help : NEWTOPIC
Hi. First time on the forum. I am an avr and bascom newbie. I know bas com has a debounce statement, but I would like some help in making one of my own and wonder if this approach is valid. Is my logic ok. I am not exactly sure what happens in nested if statements. Thank you.
do
if pinb.4 = 0 then 'check pinb.4
waitms 25 'wait 25ms
if pinb.4 = 0 then 'check pinb.4 again
led = 1 ' if button was held down at least 25 continuous ms then turn led on
end if
end if
loop
[b:81276b6a53][color=red:81276b6a53](BASCOM-AVR version : 2.0.7.8 )[/b:81276b6a53][/color:81276b6a53]
↧
BASCOM-AVR : Need debounce help : REPLY
welcome.
yes that is a good approach : check if the key is 0, then wait some time, and check again if it is still 0. it is simple to test too.
↧
BASCOM-AVR : Division problem : REPLY
- you should not post passwords on a public forum. i advise to change it. especial if you use it for other accounts as well. problem with account/pwd : send an email to support. Also remember : this is a forum, it is NOT the MCS support system.
- there can always be a problem. but we can speculate a lot and it is a waste of time. Just do as i told : show the info on the LCD or serial port. Some times a problem is caused by another problem. (Problem behind problem).
you could start to eliminate if an ISR is the problem : disable interrupts before the operation and enable after wards.
↧