Main Menu
Counter
This page today ...
total: 0
unique: 0

This page ever ...
total: 221
unique: 152

Site ...
total: 4291
unique: 2470
Online
  • Guests: 1
  • Members: 0
  • Newest Member: ole
  • Most ever online: 170
    Guests: 170, Members: 0 on Sunday 15 January 2023 - 07:39:26
Chatbox
You must be logged in to post comments on this site - please either log in from the Login box or from here.If you are not registered click here to signup.


bullet Kim
5 years ago
test
Royalsystems blog

MCS Electronics Forum

  • BASCOM-AVR XTINY/MEGAX/AVRX : ADC in AVR128DB48 : REPLY



    also make sure you use the right pin : ain0 is portd.0 pin 20.

  • BASCOM-AVR XTINY/MEGAX/AVRX : ADC in AVR128DB48 : REPLY



    EDC : $SIM cheesey


    But the posted sample should work. I see no reason why not.
    Only thing i never tried is using vdd as reference. try some other reference setting.

  • BASCOM-AVR XTINY/MEGAX/AVRX : ADC in AVR128DB48 : REPLY



    You should check with Bascom IDE->Help->Update if you have the latest Xtiny Addon

    [img:a4fb96d839]https://www.mcselec.com/userpix/22760_update_1.jpg[/img:a4fb96d839]

    I test this code with my AVRX128DB32 and it works fine (with one strange issue that I will describe below later). Start ADC is not needed. This probably is done with config parameter "Adc = Enabled".

    Notice that my 32 pin uC dont have AIN0 so Im using AIN1 here.
    Code is working. I touch PIN11 of my uC and value fluctuate.


    [code:1:a4fb96d839]
    '--------------------------------------------------------------------------------
    'name : adc-DB.bas
    'copyright : (c) 1995-2021, MCS Electronics
    'purpose : demonstrates ADC
    'micro : AVR128DB28
    'suited for demo : no
    'commercial addon needed : yes
    '--------------------------------------------------------------------------------
    $regfile = "AVRX128db32.dat"
    $crystal = 24000000
    $hwstack = 64
    $swstack = 64
    $framesize = 64
    $sim

    'The AVRX series have more oscillator options
    Config Osc = Enabled , Frequency = 24mhz
    'set the system clock and prescaler
    Config Sysclock = Int_osc , Prescale = 1

    Config Com1 = 115200 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1


    'configure the internal reference to be 1v024 for the ADC
    Config Vref = Dummy , Adc0 = 1v024

    'configure the ADC0 to read the DAC
    Config Adc0 = Single , Resolution = 10bit , Adc = Enabled , Prescaler = 32 , Sample_len = 1 , Mux_neg = Gnd , Mux_pos = Ain1

    'dimension a variable
    Dim W As Word , B As Byte

    Print "Test ADC"


    Do
    'when getadc() does not have parameters, it will use the current mux setting
    'other options are : getadc(channel) and getadc(adc0 | adc1 , channel)
    W = Getadc(1) : Print "W:" ; W
    'output should be 512
    Waitms 1000
    Wait 1

    Loop[/code:1:a4fb96d839]


    Strange is than Waitms and Wait command seems to not working. My loop is working at full uC speed cheesey
    I dont know why. Maybe one more coffe form is needed here cheesey

  • BASCOM-AVR XTINY/MEGAX/AVRX : ADC in AVR128DB48 : REPLY



    Didn't work with AVR128DB48 yet, but maybe:
    [code:1:3062d83804]start adc[/code:1:3062d83804]

  • BASCOM-AVR XTINY/MEGAX/AVRX : ADC in AVR128DB48 : NEWTOPIC



    Hello,
    I am quite helpless with ADC in AVR128DB48.
    I am using downloaded .dat file:
    https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=15106

    The first part of code is ok. (the selection of the I2C for LCD display).
    But the ADC part doesnt work. I copied it from sample file adc-db.bas. When compiled, it doesnt report any error, but it does nothing. It obviously stops at getadc().
    Then I tried many, many config parameters, but without success. Not any error, but it doesnt work.
    Maybe, I am missing something fundamental. Any help welcomed.

    [code:1:ae31d24ee5]
    $programmer = 26 'MCS UPDI programmer
    $regfile = "avrx128db48.dat"
    $hwstack = 100
    $swstack = 100
    $framesize = 100

    $crystal = 18432000 '18.432 MHz
    'select oscillator and frequency with external HF crystal
    Config Osc = Enabled , Xoschf = Enabled , Xoschf_ext_src = Ext_xtal , Xoschf_range = Max_24mhz
    'set the system clock and prescaler
    Config Sysclock = External , Prescale = 1

    '************************************************************************
    'Library PCF8574-I2C-LCD by O-Family.
    'I2C_select switches I2C_0 , I2C_1 or sw_i2c
    '
    ' * PCF8574 I2C LCD Adapter settings (For XTINY) *
    Const I2c_select = 2
    #if I2c_select = 0
    'For I2C_0:
    Dim Twi_start As Byte ' Variables used in the TWI library.
    Const Twi_adr = Twi0_ctrla ' TWI port. TWI_ADR = TWI0_CTRLA:(TWI0)
    Const Twi_ch = 1 ' TWI channel. TWI_CH = 1:(TWI0), 2:(TWI1)
    Config Twi0 = 100000 ' TWI clock frequency. (100KHz) (* Maximum 100KHz)
    I2cinit ' Initialize the TWI bus.
    #elseif I2c_select = 1
    'For I2C_1:
    Dim Twi_start As Byte ' Variables used in the TWI library.
    Const Twi_adr = Twi1_ctrla ' TWI port. TWI_ADR = TWI0_CTRLA:(TWI0)
    Const Twi_ch = 2 ' TWI channel. TWI_CH = 1:(TWI0), 2:(TWI1)
    Config Twi1 = 100000 ' TWI clock frequency. (100KHz) (* Maximum 100KHz)
    I2cinit ' Initialize the TWI bus.
    #else
    'SW I2C
    Const Twi_adr = Twi0_ctrla : Const Twi_ch = 1 ' [Dummy in library]
    $forcesofti2c ' Force use of software I2C/TWI library.
    $lib "i2c.lbx" ' Overwrite the library for software I2C.
    Config I2cdelay = 5 ' SCL clock frequency = approx 90KHz。(At AVR clock 20MHz) (* Maximum 100KHz)
    Config Scl = Porta.7 ' Set the port pin to connect the SCL line of the I2C bus.
    Config Sda = Porta.6 ' Set the port pin to connect the SDA line of the I2C bus.
    I2cinit ' Initialize the I2C bus.
    #endif

    'I2C LCD
    Dim Pcf8574_lcd As Byte : Pcf8574_lcd = &H4E ' PCF8574 slave address. (&H40,&H42,&H44,&H46,&H48,&H4A,&H4C,&H4E)
    Dim Backlight As Byte : Backlight = 1 ' LCD backlight control. (0: off, 1: on)
    $lib "lcd_i2c_PCF8574.LIB" ' Incorporate the library of I2C LCD PCF8574 Adapter.
    Config Lcd = 16x2 ' Set the LCD to 16 characters and 2 lines.
    Initlcd ' Initialize the LCD.
    Cursor Off

    Locate 1 , 1 : Lcd "Test ADC:"

    '**** Here the problem starts **************
    'configure the internal reference to be 1v024 for the ADC
    Config Vref = Dummy , Adc0 = Vdd

    '*** configure the ADC0 to read the DAC ***
    'Config Adc0 = Single , Resolution = 10bit , Adc = Enabled , Prescaler = 32 , Sample_len = 1 , Mux_neg = Gnd , Mux_pos = Ain0
    'Config Adc0 = Free , Resolution = 10bit , Adc = Enabled , Prescaler = 32 , Sample_len = 1 , Mux_neg = Gnd , Mux_pos = Ain0
    Config Adc0 = Single , Resolution = 12bit , Conv_mode = Single_ended , Adc = Enabled , Prescaler = 32 , Sample_len = 1 , Mux_pos = Ain0


    Dim Adc_w As Word

    Do
    'Adc_w = Getadc()
    Adc_w = Getadc(0)
    'Adc_w = Getadc(adc0)
    Waitms 200

    Locate 2 , 1 : Lcd Spc(16)
    Locate 2 , 1 : Lcd Adc_w

    Waitms 1000
    Loop


    End
    '******************************************************************************
    [/code:1:ae31d24ee5]

  • BASCOM-AVR : ILI9341 8-bit parallel port + hardware SPI : REPLY



    [quote:18ef4770b3="EDC"]Maybe this answear not satisfy you to.[/quote:18ef4770b3]
    Very likely, as the TO - in case his hardware matches exactly the shown - uses a LCD-shield with 8bit-bus only, the SPI-connector is only for the SD-card.

    As I found the topic - not so much the TO cheesey - interesting, I've looked up the linked library from user Netzman.

    If nothing is user-configured for the lib, defaults using XMega are:
    PortC for control
    PortF for data

    Default control port bits are as follows:
    LCD_RST <--- Lcd_reset_pin = 0 ---> PortC.0
    LDD_WR <--- Lcd_pin_wr = 1 ---> PortC.1
    LCD_RD <--- Lcd_pin_rd = 5 ---> PortC.5
    LCD_RS <--- Lcd_pin_dc = 7 ---> PortC.7
    LCD_CS <--- Lcd_pin_cs = 4 ---> PortC.4
    NC <--- Lcd_pin_backlight = 0 ---> PortC.0 ' collision

    It is odd that in https://mat.midlight.eu/images/5/5c/Lcd-connections.jpg LCD_RD is not shown to be connected in 8 or 16 bit parallel mode, however Lcd_pin_rd finds use within the lib.
    Thus I'd add this wire between LCD_RD and PortC.5

    A critical, and maybe the TO's problem is, that [b:18ef4770b3]Lcd_enable_backlight_pwm[/b:18ef4770b3] is enabled by default, which in turn drives the default pin 0 on the control port, line 134 to 136 from ILI9341.inc.
    Driving the display's reset pin with a PWM will create a mess.

    For setting up sample code, I'd use the lib's default settings by removing any configuration for the lib, 8 bit parallel mode will be set as default.
    This goes well with the hardware, besides the enabled PWM by timer TCC0, this needs to be shut off:
    [code:1:18ef4770b3]Lcd_enable_backlight_pwm = False[/code:1:18ef4770b3]
    or redirected to a free pin.

  • BASCOM-AVR : MODBUS master on XMEGA : REPLY



    Thank you very much again.
    It's really simple smile.
    The best solutions are always simple.

  • BASCOM-AVR : MODBUS master on XMEGA : REPLY



    that has been asked before. it is simple :
    [code:1:b44109efd2]Dim L As Long
    Dim Sn As Single At L Overlay
    L = &H43618A75
    print sn
    [/code:1:b44109efd2]

  • BASCOM-AVR : MODBUS master on XMEGA : REPLY



    How must be set parameters in MAKEMODBUS statement that controller send on serial port this?

    [quote:9d5a377310]01 04 00 00 00 02 71 CB[/quote:9d5a377310]

    I did so:
    [code:1:9d5a377310]Printbin &H01 ; &H04 ; &H00 ; &H00 ; &H00 ; &H02 ; &H71 ; &HCB;[/code:1:9d5a377310]
    Response is correct.

    ... but I think, that all this is possible with MAKEMODBUS statement. I red help but I'm sorry, I don't understand this.



    One question more:
    On response data I get value

    [quote:9d5a377310]&H43618A75[/quote:9d5a377310]

    How to calculate a floating point from a hexadecimal value in Bascom
    In this case, [quote:9d5a377310]&H43618A75 is 225,541[/quote:9d5a377310]
    Maybe some advice.

  • BASCOM-AVR : MODBUS master on XMEGA : REPLY



    you send too many parameters.
    please check makemodbus in the help. only 4 are allowed. and you specify the start address.

    i think that your device is not compatible with modbus. only the crc is.

| Date published: not known
Back to newsfeed list
Welcome
Username or Email:

Password:




[ ]
[ ]
Headlines

»BASCOM-AVR XTINY/MEGAX/AVRX : ADC in AVR128DB48 : REPLY
also make sure you use the right pin : ain0 is portd.0 pin 20.
»BASCOM-AVR XTINY/MEGAX/AVRX : ADC in AVR128DB48 : REPLY
EDC : $SIM :D But the posted sample should work. I see no reason why not. Only thing i never tried is using vdd as refer...
»BASCOM-AVR XTINY/MEGAX/AVRX : ADC in AVR128DB48 : REPLY
You should check with Bascom IDE->Help->Update if you have the latest Xtiny Addon [img:a4fb96d839]https://www.mcselec.com/userp...
»BASCOM-AVR XTINY/MEGAX/AVRX : ADC in AVR128DB48 : REPLY
Didn't work with AVR128DB48 yet, but maybe: [code:1:3062d83804]start adc[/code:1:3062d83804]
»BASCOM-AVR XTINY/MEGAX/AVRX : ADC in AVR128DB48 : NEWTOPIC
Hello, I am quite helpless with ADC in AVR128DB48. I am using downloaded .dat file: https://www.mcselec.com/index2.php?option=c...
»BASCOM-AVR : ILI9341 8-bit parallel port + hardware SPI : REPLY
[quote:18ef4770b3="EDC"]Maybe this answear not satisfy you to.[/quote:18ef4770b3] Very likely, as the TO - in case his hardware m...
»BASCOM-AVR : MODBUS master on XMEGA : REPLY
Thank you very much again. It's really simple :). The best solutions are always simple.
»BASCOM-AVR : MODBUS master on XMEGA : REPLY
that has been asked before. it is simple : [code:1:b44109efd2]Dim L As Long Dim Sn As Single At L Overlay L = &H43618A75 prin...
»BASCOM-AVR : MODBUS master on XMEGA : REPLY
How must be set parameters in MAKEMODBUS statement that controller send on serial port this? [quote:9d5a377310]01 04 00 00 00 0...
»BASCOM-AVR : MODBUS master on XMEGA : REPLY
you send too many parameters. please check makemodbus in the help. only 4 are allowed. and you specify the start address. i t...


Date published: not known
Details

»UART-Senden-Empfangen mit 2 MC
Ich probiere die serielle Übertragung zwischen zwei MC aus und bin leider nicht erfolgreich.An MC1 sind 4 Taster angeschlossen, die bei Betätigung ...
»Nach langer Pause...
Hallo Welt! Ja, ich lebe noch und schau' demnächst wieder öfter vorbei - sofern ich kann und es zeitlich passt. Lesestoff hab ich ja reichlich und...
»Strom am A4988 einstellen ?
Hi ihr, Ich versuche gerade etwas mit einem Nema17 Stepper und einem A4988 Treiber. Am Treiber habe ich jetzt erst mal nur 12v an VMot und GND ang...
»Power Down wecken mit PinChange?
Hallo in die Runde! Stecke da gerade über einen Schaltplan den ich gerade zusammen stricke. Allerdings meine etwas leichtsinnige Vorstellung der A...
»Bauteil gesucht
Hallo zusammen, wer kennt das nicht: beim Vekabeln einer neuen Bastelei wird der Platz an der GND-Klemme plötzlich ziemlich eng... Neulich habe ic...
»CMOS-Dezimal-Counter- bzw. -Teiler-Kaskade in Bascom umsetzen
Hallo in die Runde, ich bin ganz neu hier und hoffe auf Hilfe und Tipps durch die Forummitglieder. Kurz zu mir: Ich bin schon etwas älter, bastel ...


Date published: Mon, 21 Oct 2024 15:47:14 +0000
Details

»4 January 20244 January 2024
»93c46 editor programmer bascom &amp; vb93c46 editor programmer bascom &amp; vb
»93c46 Bascom &amp; VB693c46 Bascom &amp; VB6
»Analog clock on SSD1289 3.2" 240x320 lcdAnalog clock on SSD1289 3.2" 240x320 lcd
»Nextion HMI lcd with KaraDio the best webradio esp8266Nextion HMI lcd with KaraDio the best webradio esp8266
»Adding 240x320 lcd to the WifiWebRadioAdding 240x320 lcd to the WifiWebRadio


Date published: not known
Details

»Bascom Can Bus Sniffer
»R.I.P Ben Zijlstra
Remembering Ben Zijlstra We hope that people who love Ben will remember and celebrate his life. more info at MCS www.mcselec.com/index2.ph...
»KaRadio webradio ESP8266
The Dimitris board is available at https://github.com/dsaltas/WiFi-WebRadio  This is a hardware project for Ka-Radio
»93C46
small tool to edit 93C46 eeprom written in BascomAVR & VB  Bascom control the 93C46 so we sent data via comport from VB code will be added later ...
»nRF24L01+ RC Controller
This is a RC controller TX & RX unit with nRF24L01+ nRF24L01+ / with PA and LNA for longer range facts: TX 1 x potmeter for servo ...
»RAW lcd
Connecting RAW lcd to atmega8 the lcd is 6 digit + time glass LCD Hour Meter for  tractor ,air compressor, ect the lcd have 4 com pins  & 14...


Date published: not known
Details


Proudly powered by e107 which is released under the terms of the GNU GPL License.