That wasn't implemented, even though it should have been implemented way back in 2009 when GCBASIC first started supporting AVRs. But hopefully that is now corrected, please try the compiler exe at http://gcbasic.sourceforge.net/newfiles/gcbasic.exe and let us know if it helps!
It should work on any AVR faster than 3 MHz, and there will be some inaccuracy depending on the exact speed of the chip (about 12 cycles of extra delay). Tested in AVR Studio 4 with an ATmega328p at 8 MHz, a 100 us delay took 102 us and a 1000 us delay took 1003 us.
There is one specific section of code that handles variable length microsecond delays, which is why everything works on PIC, or when using millisecond delays or constant lengths.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It works now with my tiny85 - thanks for the quick reply. I tested with this code (moving a servo):
#chip tiny85, 16
#define ServoMin 1025
#define ServoMax 1791
#define Servo PORTB.4
Dim DelayTime as Word
Dir Servo Out
Do
'Move servo forward:
For DelayTime = ServoMin to ServoMax
PulseOut Servo, DelayTime uS
Wait 10 ms
Next
'Move servo backward:
For DelayTime = ServoMax to ServoMin Step -1
PulseOut Servo, DelayTime uS
Wait 10 ms
Next
Loop
There is still one difference with the same code for PIC(16f1509). While the servo connected to the PIC moves smooth the whole way back and forth, the servo on AVR has noticeably 'ticks'. Both are running at 16Mhz with the internal oscillator. The 'ticks' seem to occur, when the asm code jumps to the outer loop of the uS delay (two times per direction with the attached code)??
Regards
Steini
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the code Steini! Ran it here, and saw the same ticks. Looking at the compiler code, I left out one instruction when translating the PIC delay code to AVR, which added 256 us to delays that were a multiple of 256 us.
I've updated the compiler exe at the link above, please try again and see if it works smoothly now!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
this code does not work on an AVR (similar with PulseOut ... uS):
This is the 'Wait uS' related asm output:
Everything seems ok, when
- i use a constant value instead a variable,
- i use mS instead uS,
- code is for a PIC.
Is it a bug or simply not implemented for AVR?
Regards
Steini
That wasn't implemented, even though it should have been implemented way back in 2009 when GCBASIC first started supporting AVRs. But hopefully that is now corrected, please try the compiler exe at http://gcbasic.sourceforge.net/newfiles/gcbasic.exe and let us know if it helps!
It should work on any AVR faster than 3 MHz, and there will be some inaccuracy depending on the exact speed of the chip (about 12 cycles of extra delay). Tested in AVR Studio 4 with an ATmega328p at 8 MHz, a 100 us delay took 102 us and a 1000 us delay took 1003 us.
There is one specific section of code that handles variable length microsecond delays, which is why everything works on PIC, or when using millisecond delays or constant lengths.
Hello Hugh!
It works now with my tiny85 - thanks for the quick reply. I tested with this code (moving a servo):
There is still one difference with the same code for PIC(16f1509). While the servo connected to the PIC moves smooth the whole way back and forth, the servo on AVR has noticeably 'ticks'. Both are running at 16Mhz with the internal oscillator. The 'ticks' seem to occur, when the asm code jumps to the outer loop of the uS delay (two times per direction with the attached code)??
Regards
Steini
Thanks for the code Steini! Ran it here, and saw the same ticks. Looking at the compiler code, I left out one instruction when translating the PIC delay code to AVR, which added 256 us to delays that were a multiple of 256 us.
I've updated the compiler exe at the link above, please try again and see if it works smoothly now!
SMOOTHLY here too; great!
Steini