I've got a chip with BP3 as input this input is connected via a 4.7k resistor to 5Vdc (high)
and a tact switch is connected from BP3 to 0V (Low) or GND
when I press the tact SW, BP3 to Low the led stop pulsing
any clue,
Thank's for all reply
#definebuttonportb.3dirportb.0outdirportb.1outdirportb.2outdirbuttonin
#chiptiny10,8Dowhilebutton=0; led are pulsing when BP3 = high or 1Wait200msPulseOutPortB.0,500msWait200msPulseOutPortB.1,500msWait200msPulseOutPortB.2,500msLoop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can create a project and use the ASM produced by GCBASIC as your source. Then, debug in the AS6 simulator.
For your program the LEDS flash whilst the switch is Low, then, the program ends when the switch goes High. If the switch is High at the start... then, the LEDs do not flash.
The program as written is odd.
Maybe you where thinking of this ?
Do Forever
Wait While button = 0
Flash LEDs
Loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It depends on your hardware but most switches are connected via a Resistor to Vcc and the switch is open circuit. Then when the button or switch is activated it connects to ground this diverts the Vcc on the switch to ground, hence when you press the button the signal on the port pin goes from high to low, not low to high.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The Good
Yes Anobium,* Chris are 100% right 0=low and 1=high*
and Yes here's my mistake:
First the button was connected to PB3 (Reset) pin, according to Atmel datasheet the reset pin can also be used as a (weak) I/O pin.
As inputs, the port pins that are externally pulled low will source current *if pull-up resistors
are activated.
The Bad
cannot find any ways to setup the pull-up resistors even with AVRdude GUI.
my programmer USBtinyISP work fine to program the chip, but cannot detect
the chip from AVRdudeGUI.
The Ugly
I have left 3 out of 4 I/O pins.
Is there a way to get PB3 working, let me know.
Here's my code and circuit test below.
Thank's again
Always add `#option explicit' This will ensure you dimension all your variables. Variables like WORD, INTEGER and other need to be dimensioned but by using #option explicit it will ensure your registers all exist ( a register a chip byte/bit). It is easy to have a typo and get frustrated when not using the #option.
As a newbee to GCBASIC, another you should always set the DIR on line per port.
Below is the code I have posted to the GitHub
'''A demonstration program for GCBASIC.'''--------------------------------------------------------------------------------'''This program controls three LEDs via a switch.'''Seethephotoandtheschematicinthesamefolderasthissourceprogram.''''''@authorJB'''@license GPL'''@version1.00'''@date 2024-03-17'''********************************************************************************#chiptiny10,8#optionExplicit/* ------------PORTB---------------- Bit#: -7---6---5---4---3---2---1---0--- IO: ----------------SW--LED-LED_LED-- IO: ---------------------------------*///Defineportsoutputstatedirportb.0outdirportb.1outdirportb.2out//Defineportsinstatedirportb.3in//RepeatwhileswitchstateisLow,elseexitloopandentersleepstateDowhileportb.3=0//PulseOutwillsettheportasanoutput,setthestateandthendelayPulseOutPortB.0,500msPulseOutPortB.1,500msPulseOutPortB.2,500msLoop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My advice regarding DIR on a separate line .... the command you use dir portb.0,1,2 out would have actually not set the direction but would have done something else.
However, dir portb.0,1,2 out is a actually what I called a 'silent failure' where the compiler accepts commands and generates ASM but not what you expected. I will update the compiler to trap this syntax.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello everyone,
just a simple question:
I've got a chip with BP3 as input this input is connected via a 4.7k resistor to 5Vdc (high)
and a tact switch is connected from BP3 to 0V (Low) or GND
when I press the tact SW, BP3 to Low the led stop pulsing
any clue,
Thank's for all reply
Is the programmer attached?
All LEDS?
That is a very strange loop. If the button is high then the loop will not be executed and the chip will go to end (a continuous loop),or sleep.
Rewrite the loop.
If you want to see what your program is doing there a number of simulators but I would recommend ATMEL Studio 6 for this chip.
See here for the installers. https://sourceforge.net/projects/gcbasic/files/Support%20Files/ATMELCompilers/
You can create a project and use the ASM produced by GCBASIC as your source. Then, debug in the AS6 simulator.
For your program the LEDS flash whilst the switch is Low, then, the program ends when the switch goes High. If the switch is High at the start... then, the LEDs do not flash.
The program as written is odd.
Maybe you where thinking of this ?
Do Forever
Wait While button = 0
Flash LEDs
Loop
Many thank's I'll make changes
Hello, I edited the code and still when PB3 = 1 or high the led is flashing when I close the switch to low then the led stop flashing.
I re-wrote the code
and if pb3=1 or high led is flashing, when pb3=0 or low the led stop flashing
here's the scope traces.
The scope is doing what the program is told to do.
Go back to your first post.
I'm sorry to ask again but this make no sense to me
(I'm use to 1=high or VCC and 0=low or gnd)
that's mean , if button = 0 (zero will mean = high) as the scope show, then led are flashing
and when button=1 (will mean low) then no flashing led.
is this correct?
1 is the same as On equates to High.
0 is the same Off equate to Low
You are used to using PICs.
This an AVR.
Read the page in the Help. This is the way the AVR architecture is, not, an GCBASIC thing.
https://gcbasic.sourceforge.io/help/_inputs_outputs.html specially the ATMEL specifics for read/write operations section ... then, change your code.
Last edit: Anobium 2024-03-14
It depends on your hardware but most switches are connected via a Resistor to Vcc and the switch is open circuit. Then when the button or switch is activated it connects to ground this diverts the Vcc on the switch to ground, hence when you press the button the signal on the port pin goes from high to low, not low to high.
Hello, everyone and many thank's for the reply.
Here's the Good the Bad and the Ugly:
The Good
Yes Anobium,* Chris are 100% right 0=low and 1=high*
and Yes here's my mistake:
First the button was connected to PB3 (Reset) pin, according to Atmel datasheet the reset pin can also be used as a (weak) I/O pin.
As inputs, the port pins that are externally pulled low will source current *if pull-up resistors
are activated.
The Bad
cannot find any ways to setup the pull-up resistors even with AVRdude GUI.
my programmer USBtinyISP work fine to program the chip, but cannot detect
the chip from AVRdudeGUI.
The Ugly
I have left 3 out of 4 I/O pins.
Is there a way to get PB3 working, let me know.
Here's my code and circuit test below.
Thank's again
also ATmel datasheet
I have memory that you have to change the fuses and they are write once.
The ATTINY10 is a very odd chip along with the others in this chip family.
There is not a lot of experience across the internet.
But, look at changing the fuse setting.
Thank's Anobium
Hello,
finaly I was able to get 4 port from attiny10 ( PB0,1,2 as I/O, and PB3 as Input only)
switches circuit was modified to access all ports.
So PB0,1,2 can be access as 1=high, 0 =low PB3 as input can be read as high only with the line of code as : if portb.3=0 (0 is high from the switch).
(see circuit)
Excellent. If you have a working program please post. I would like to add to the Demonstrations with your diagram.
Hello,
here's a simple PB3 high input test code.
@JB
Thank you. I will add to the demonstrations. See https://github.com/GreatCowBASIC/Demonstration_Sources/tree/main/ChipFamily121_AVRrc_Specific_Solutions/Tiny4_5_9_10/Multiple_LEDs_and_Switch for the folder.
Some advice:
Always add `#option explicit' This will ensure you dimension all your variables. Variables like WORD, INTEGER and other need to be dimensioned but by using #option explicit it will ensure your registers all exist ( a register a chip byte/bit). It is easy to have a typo and get frustrated when not using the #option.
As a newbee to GCBASIC, another you should always set the DIR on line per port.
Below is the code I have posted to the GitHub
You've been a great help
Pleasure.
My advice regarding DIR on a separate line .... the command you use
dir portb.0,1,2 out
would have actually not set the direction but would have done something else.However,
dir portb.0,1,2 out
is a actually what I called a 'silent failure' where the compiler accepts commands and generates ASM but not what you expected. I will update the compiler to trap this syntax.I found out about how many I/O port a attiny10 has.
3 I/O PB0,1,2
PB3 (RESET/PCINT3,ADC3)
PB3 is mostly use as a Reset and can be use as INT3 or ADC3
see reference at:
http://www.technoblogy.com/show?1YQY