Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:51 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Picomite Counting Pin

Author Message
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 07:14am 28 Jan 2023
Copy link to clipboard 
Print this post

With a pin set to CIN is it possible to start the count at a certain value. I want to save the count and be able to reinstate it later.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7938
Posted: 07:36am 28 Jan 2023
Copy link to clipboard 
Print this post

Have you tried PIN(countpin)=n? I haven't. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 07:52am 28 Jan 2023
Copy link to clipboard 
Print this post

Setpin (GP9), CIN  
Pin(GP9) = 10
Error: Pin(GP9) is not an input
although technically it is an input, a counting input
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 07:54am 28 Jan 2023
Copy link to clipboard 
Print this post

Yes, that works.

> setpin gp6,cin
> ? pin(gp6)
0
> pin(gp6)=55
> ? pin(gp6)
55
>-------------------------------give it a few pulses
> ? pin(gp6)
66
>

Edit
Could that pin be configured for something else?

OPTION LIST
Edited 2023-01-28 17:58 by phil99
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 07:57am 28 Jan 2023
Copy link to clipboard 
Print this post

  Quote  Setpin (GP9), CIN  


This is incorrect syntax. By using brackets you are making GP9 a variable and it will have the value 0

SETPIN GP9,CIN
PIN(GP9)=10

works perfectly and does what you want

In the absence of a signal PRINT PIN(GP() will then return 10
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 08:10am 28 Jan 2023
Copy link to clipboard 
Print this post

Thanks for that I was very confused obviously.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 08:12am 28 Jan 2023
Copy link to clipboard 
Print this post

OPTION EXPLICIT would have found it
Edited 2023-01-28 18:12 by matherp
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 03:14am 30 Jan 2023
Copy link to clipboard 
Print this post

Yes Peter I must use it, it was old micromite code.
New problem, I bought a new rain sensor (tipping bucket) that used a reed switch, I modified the old sensor to use a photo interrupt.
I did not want to modify the new one but the reed switch is bouncing, is there an easy fix for this.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1003
Posted: 03:45am 30 Jan 2023
Copy link to clipboard 
Print this post

Here is what I used for the tipping bucket to de-bounce it. I probably got it from TBS somewhere.

DIM INTEGER RainPin=15,rain_count,rain_last

Setpin RainPin, Intl,rainguageClick,Pullup
.
.

'rainguage sensor interrupt
Sub rainguageClick
 local thistime
 thistime=Timer-rain_last
 rain_last=Timer
 If thistime>10 Then
   rain_count=rain_count+1
   Print "Rain click "+str$(rain_count)
 End If
 
End Sub

Latest F4 Latest H7 FotS
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 03:52am 30 Jan 2023
Copy link to clipboard 
Print this post

  palcal said  
I did not want to modify the new one but the reed switch is bouncing, is there an easy fix for this.


I put a 100nF capacitor on the input. It also helps stop nasties getting in.

With the capacitor, I don't need any software debounce, but it all helps.

Jim
VK7JH
MMedit
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 04:48am 30 Jan 2023
Copy link to clipboard 
Print this post

Thanks @disco4now but it was easier to try Jim's solution first and it works perfectly

Thanks Jim
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7938
Posted: 12:25pm 30 Jan 2023
Copy link to clipboard 
Print this post

If you are using a cap for debounce on a reed switch it's probably a good idea to put some sort of resistance in series with it. The contacts on a reed are often tiny and discharging even 100nF directly through them isn't good. If you add about 100R in series with the cap it should preserve the life of the contact somewhat.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:08pm 30 Jan 2023
Copy link to clipboard 
Print this post

I usually start with something like this:



Jim
VK7JH
MMedit
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7938
Posted: 09:29pm 30 Jan 2023
Copy link to clipboard 
Print this post

That's the general idea. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 11:55pm 30 Jan 2023
Copy link to clipboard 
Print this post

Thanks I will incorporate in my hardware.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025