Sorry to ask, I have tried to setup adc in free running mode with mega328p and use on interrupt ADCReady to store data in an array that looped.
Using #define ADReadPreReadCommand I tried to set up ADCSRB Bits 2:0 – ADTSn: ADC Auto Trigger Source [n = 2:0] 000 Free Running mode from data sheet.
Point is I couldn't sort it. To save time an example for 328p, oninterrupt adcread and any info on setting adc register bits would be useful to me.I can do more with a working example than figureing things out for myself and making errors. We're all busy so I appreciate any help. I do try to sort things myself first but sometimes get nowhere.
I have looked at the online help for latest info. In the mean time I'll start again and test the interrupt with a scope and build up logically. moi,logical,ha
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Untested but the basis of free running ADC for AVR Mega328p - will require debugging and validating.
Anobium
'
#chip mega328p
' THIS CONFIG OF THE SERIAL PORT WORKS WITH A MAX232 (or equiv) THEN TO PC
' Ports are defined in datasheet or by PPS
' USART settings
#define USART_BAUD_RATE 9600
#define USART_BLOCKING
#define USART_BLOCKING
' You change the usart delay value. Uncomment next line
' #define USART_DELAY 5 ms
' Let USART settle down
wait 500 ms
Dim LLADResult As Word Alias ADCH, ADCL 'this will contain the ADC result
readFlag = 0
ADATE = 1 'enable auto-triggering.
ADTS0 = 0 'Clear ADTS0 in ADCSRB to set trigger mode to free running.
ADTS1 = 0 'Clear ADTS1
ADTS2 = 0 'Clear ADTS2
on Interrupt ADCReady call HandleADC
'Use the GCB method set up the ADC
ADVal = ReadAD10( An0 )
Do
if readFlag = 1 then
HSerPrint LLADResult
HSerPrintCRLF
readFlag = 0
end if
Loop
sub HandleADC
' Done reading
readFlag = 1
End Sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
From the data sheet and this link..and others https://www.instructables.com/id/Girino-Fast-Arduino-Oscilloscope/
I did mention it to you. I tried implementing it in GCB but it's worth clarifying..for me anyway.
;
data sheet says-
Bits 2:0 – ADTSn: ADC Auto Trigger Source [n = 2:0]
If ADATE in ADCSRA is written to one, the value of these bits selects which source will trigger an ADC
conversion. If ADATE is cleared, the ADTS[2:0] settings will have no effect. A conversion will be triggered
by the rising edge of the selected Interrupt Flag. Note that switching from a trigger source that is cleared
to a trigger source that is set, will generate a positive edge on the trigger signal. If ADEN in ADCSRA is
set, this will start a conversion. Switching to Free Running mode (ADTS[2:0]=0) will not cause a trigger
event, even if the ADC Interrupt Flag is set.
Table 28-6. ADC Auto Trigger Source Selection
ADTS[2:0] Trigger Source
000 Free Running mode
001 Analog Comparator
010 External Interrupt Request 0
011 Timer/Counter0 Compare Match A
100 Timer/Counter0 Overflow
101 Timer/Counter1 Compare Match B
110 Timer/Counter1 Overflow
111 Timer/Counter1 Capture Event
PS It's supposed to be a faster way of reading adc so I thought, 1st sample 25us then subsequent 13us...at certain clock prescale...doh
Last edit: stan cartwright 2017-07-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Does not matter,it didn't work so logically irrellevant and want working code example as first post because no point in me posting my failed efforts..I reckon. Scratch pad ideas gone anyway.
@William posted a frequency counter program which was very useful. Helped me a lot. ps cheers.
Often on this forum a "try this code" solves everything.
If there was an example in help I wouldn't impose on others time but not everything is in help..yet.
Give me an example and I'll try it and report results.
I don't think this is not normal use of GCB for using uchips,as the link,seems it's what people try.
Someone else might try this in GCB and have the same problems..or not
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I searched for my attempt thinking it was commented out code but can't find it.
It's like interrupt on pinchange...you need to add PCINT0 = 1
On Interrupt PinChange0 Call portb0change
It is not shown in help and not untill @William posted code did I get to use it.I wouldn't have figured PCINT0 = 1 out myself.
On Interrupt PinChange0 Call portb0change
Same with oninterrupt adcread finished. Does it check all ad channels?
I don't like asking for advice but for GCB, the forum is the only source of info for GCB specific keywords, etc.and seems more mega328p data sheet type words have been added.
A this is how to do it example would be like a picture says...etc.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I will share a good strategy to understand the Great Cow BASIC keywords the IDE contains a list of the keywords, the attachment is part of the IDE.
However, I think you mean the microcontroller registers and registers bits. These are not under our control as these come from the external sources including datasheets and only microcontroller specific source files. A strategy. Look at the microcontroller specific data file, for the mega328p it is called the mega328p.dat (all the chip files are in the chipdata folder. In this file you will see the registers and the register bits. If you then look at the datasheet you will see a direct correlation. The Great Cow BASIC dat file is our way specifing the database of the microcontroller.
An example. PCINT0. We call that PinChange0. This is shown in the Help. PinChange0 is the Logic level of PCINT0 pin has changed and is specific to the AVR range of microcontrollers.
There may be errors or omissions in these dat files. We correct when folks report errors but we mostly find the source information provided to be at fault. We do have very robust methods to manage the .dat files including auto correction of known issues and very good parsing routines - but, these dat files can be incorrect.
But, if this does not answer your question - let me know.
Thank you for replying, an example is what I need though.
Here's another example of me checking data sheet for GCB not obvious method use.
;Inittimer1 (EXT, PRE0_1) ; THIS IS NOT EXPLAINED IN HELP
;TCCR1B = TCCR1B or 0B00000111 ;set CS12, CS11 and CS10 to "1" port d.5 input
cs12=1:cs11=1:cs10=1
On interrupt Timer1Overflow Call CountOverflows
3 ways to do the same thing. It was interesting...but I didn't want to refer to data to use a GCB method.
It's just all new to me, a seasoned user would just be implementing ideas using GCB rather than learning pics using GCB.
It's only an experiment anyway. I know adc is slow and using a fast adc chip needs different hardware.
The Due board I just got off ebay is much faster. Got to use arduino ide and amtel studio for first time :(
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I tried with GLCD ili9341 and it stops the display as I posted before using hardware spi and interrupts but problem not acknowledged.
Here is a working test rig display until I add the interrupt. A timeroverflow interrupt stops display also.
Is GLCD_RESET necessary and cause of problem? I tie it hi and normally ok
#chip mega328p,16#option explicit#include<glcd.h>;#define GLCD_TYPE GLCD_TYPE_ILI9341'PinmappingsforSPI-thisGLCDdriversupportsHardwareSPIandSoftwareSPI#define GLCD_DC portb.2 ; DIGITAL_10 'HW Data command line DC#define GLCD_CS portd.7 ; DIGITAL_7 ' Chip select line CS#define GLCD_RESET portd.4 ; DIGITAL_4 ' Reset line Tie high..not needed ...or is it#define GLCD_DO portb.3 ; DIGITAL 11 'HW Data out | MOSI SDI#define GLCD_SCK portb.5 ; DIGITAL_13 'HW Clock Line SCK;#define ILI9341_HardwareSPI ' remove/comment out if you want to use software SPI.'GLCDselectedextensionfontset.ASCIIcharacters31-254,theextendedfontuses1358bytesofprogrammemory#define GLCD_EXTENDEDFONTSET1GLCDfntDefaultsize=1dirportc.3outdirportc.0indimArray_ptrasworddimsampleArray1(1024)asbyte;**********Thisasisstopsdisplay************DimLLADResultAsWordAliasADCH,ADCL'thiswillcontaintheADCresultADATE=1'enableauto-triggering.ADTS0=0'ClearADTS0inADCSRBtosettriggermodetofreerunning.ADTS1=0'ClearADTS1ADTS2=0'ClearADTS2;onInterruptADCReadycallHandleADC;*************************************************wait10ms;dimvoltasbytedimptr1asworddimptr2asworddimbuffer1(60)dimbuffer2(60)dimxpos_newasworddimypos_newasbytedimxpos_oldasworddimypos_oldasbytedimxpos1_newasworddimypos1_newasbytedimxpos1_oldasworddimypos1_oldasbyte;volt=readad(an0)GLCDRotate(Portrait_Rev)GLCDfntDefaultsize=3GLCDCLSILI9341_BLUEfilledbox0,0,239,257,ILI9341_BLACKbox0,0,239,257,ILI9341_YELLOW;forptr1=1to60;read60samplesvolt=sampleArray1(ptr1)buffer1(ptr1)=255-voltbuffer2(ptr1)=buffer1(ptr1)nextptr1;do;startofmainloopptr1=1ptr2=1dountilptr1=60;eraseoldscreendataandredrawnewypos_old=buffer2(ptr1);olddataypos_new=buffer2(ptr1+1)xpos_new=ptr2+4;ypos1_old=buffer1(ptr1);newdataypos1_new=buffer1(ptr1+1)xpos1_new=ptr2+4;lineptr2,ypos_old+1,xpos_new,ypos_new+1,ILI9341_BLACK;eraselastdatalineptr2,ypos1_old+1,xpos1_new,ypos1_new+1,ILI9341_cyan;drawnewdata;ptr1=ptr1+1;datapointerptr2=ptr2+4;xpositionforstartandendlinexpositionsloop;plotingdonenowredrawcursorline1,127,239,127,ILI9341_GREEN;Drawcursorline119,1,119,254,ILI9341_GREEN;afterploting;forptr1=1to60;getnewsamplesvolt=sampleArray1(ptr1)buffer2(ptr1)=buffer1(ptr1);newdatatoolddatabuffer1(ptr1)=255-volt;set0,0topleftscreenandupdatenewdatanextptr1;loop;endofmain;subHandleADC;testportc.3=!portc.3'sampleArray1(array_ptr)=ADCH'array_ptr=Array_ptr+1'ifArray_ptr=1023then'Array_ptr=1'endifEndSub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Please have a look,best way to explain it https://youtu.be/JxhCXlDKgiA
this line alone stops display init.
ADTS0 = 0 'Clear ADTS0 in ADCSRB to set trigger mode to free running
Last edit: stan cartwright 2017-07-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry to ask, I have tried to setup adc in free running mode with mega328p and use on interrupt ADCReady to store data in an array that looped.
Using #define ADReadPreReadCommand I tried to set up ADCSRB Bits 2:0 – ADTSn: ADC Auto Trigger Source [n = 2:0] 000 Free Running mode from data sheet.
Point is I couldn't sort it. To save time an example for 328p, oninterrupt adcread and any info on setting adc register bits would be useful to me.I can do more with a working example than figureing things out for myself and making errors. We're all busy so I appreciate any help. I do try to sort things myself first but sometimes get nowhere.
I have looked at the online help for latest info. In the mean time I'll start again and test the interrupt with a scope and build up logically. moi,logical,ha
What do you mean by a free running mode?
Untested but the basis of free running ADC for AVR Mega328p - will require debugging and validating.
Anobium
From the data sheet and this link..and others https://www.instructables.com/id/Girino-Fast-Arduino-Oscilloscope/
I did mention it to you. I tried implementing it in GCB but it's worth clarifying..for me anyway.
;
data sheet says-
Bits 2:0 – ADTSn: ADC Auto Trigger Source [n = 2:0]
If ADATE in ADCSRA is written to one, the value of these bits selects which source will trigger an ADC
conversion. If ADATE is cleared, the ADTS[2:0] settings will have no effect. A conversion will be triggered
by the rising edge of the selected Interrupt Flag. Note that switching from a trigger source that is cleared
to a trigger source that is set, will generate a positive edge on the trigger signal. If ADEN in ADCSRA is
set, this will start a conversion. Switching to Free Running mode (ADTS[2:0]=0) will not cause a trigger
event, even if the ADC Interrupt Flag is set.
Table 28-6. ADC Auto Trigger Source Selection
ADTS[2:0] Trigger Source
000 Free Running mode
001 Analog Comparator
010 External Interrupt Request 0
011 Timer/Counter0 Compare Match A
100 Timer/Counter0 Overflow
101 Timer/Counter1 Compare Match B
110 Timer/Counter1 Overflow
111 Timer/Counter1 Capture Event
PS It's supposed to be a faster way of reading adc so I thought, 1st sample 25us then subsequent 13us...at certain clock prescale...doh
Last edit: stan cartwright 2017-07-27
What did you use for ADReadPreReadCommand?
Does not matter,it didn't work so logically irrellevant and want working code example as first post because no point in me posting my failed efforts..I reckon. Scratch pad ideas gone anyway.
@William posted a frequency counter program which was very useful. Helped me a lot. ps cheers.
Often on this forum a "try this code" solves everything.
If there was an example in help I wouldn't impose on others time but not everything is in help..yet.
Give me an example and I'll try it and report results.
I don't think this is not normal use of GCB for using uchips,as the link,seems it's what people try.
Someone else might try this in GCB and have the same problems..or not
OK
I searched for my attempt thinking it was commented out code but can't find it.
It's like interrupt on pinchange...you need to add PCINT0 = 1
On Interrupt PinChange0 Call portb0change
It is not shown in help and not untill @William posted code did I get to use it.I wouldn't have figured PCINT0 = 1 out myself.
On Interrupt PinChange0 Call portb0change
Same with oninterrupt adcread finished. Does it check all ad channels?
I don't like asking for advice but for GCB, the forum is the only source of info for GCB specific keywords, etc.and seems more mega328p data sheet type words have been added.
A this is how to do it example would be like a picture says...etc.
I will share a good strategy to understand the Great Cow BASIC keywords the IDE contains a list of the keywords, the attachment is part of the IDE.
However, I think you mean the microcontroller registers and registers bits. These are not under our control as these come from the external sources including datasheets and only microcontroller specific source files. A strategy. Look at the microcontroller specific data file, for the mega328p it is called the mega328p.dat (all the chip files are in the chipdata folder. In this file you will see the registers and the register bits. If you then look at the datasheet you will see a direct correlation. The Great Cow BASIC dat file is our way specifing the database of the microcontroller.
There may be errors or omissions in these dat files. We correct when folks report errors but we mostly find the source information provided to be at fault. We do have very robust methods to manage the .dat files including auto correction of known issues and very good parsing routines - but, these dat files can be incorrect.
But, if this does not answer your question - let me know.
Thank you for replying, an example is what I need though.
Here's another example of me checking data sheet for GCB not obvious method use.
;Inittimer1 (EXT, PRE0_1) ; THIS IS NOT EXPLAINED IN HELP
;TCCR1B = TCCR1B or 0B00000111 ;set CS12, CS11 and CS10 to "1" port d.5 input
cs12=1:cs11=1:cs10=1
On interrupt Timer1Overflow Call CountOverflows
3 ways to do the same thing. It was interesting...but I didn't want to refer to data to use a GCB method.
It's just all new to me, a seasoned user would just be implementing ideas using GCB rather than learning pics using GCB.
It's only an experiment anyway. I know adc is slow and using a fast adc chip needs different hardware.
The Due board I just got off ebay is much faster. Got to use arduino ide and amtel studio for first time :(
Ok
I tried with GLCD ili9341 and it stops the display as I posted before using hardware spi and interrupts but problem not acknowledged.
Here is a working test rig display until I add the interrupt. A timeroverflow interrupt stops display also.
Is GLCD_RESET necessary and cause of problem? I tie it hi and normally ok
Please have a look,best way to explain it https://youtu.be/JxhCXlDKgiA
this line alone stops display init.
ADTS0 = 0 'Clear ADTS0 in ADCSRB to set trigger mode to free running
Last edit: stan cartwright 2017-07-30