BasicMicro - Forums

www.basicmicro.com
It is currently Tue Feb 07, 2012 3:09 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: ultrasonic sensor controlling PWM output for paving truck
PostPosted: Sat Aug 21, 2010 1:16 am 
Offline
Citizen

Joined: Tue Aug 10, 2010 3:42 pm
Posts: 15
I've got an interesting challenge for the nano18 series processor.

1) I have an ultrasonic range sensor that reads distances from 6 inches to 35 feet, however I only need a range of 20 " due to sensor switching reflective wave return is 1 foot per 0.9 ms
2) also I have a pwm deadband, span adjust controlled through two 5k potentiometers, This sets the duty cycle ranges on a linear scale. ranges 6 " to 20 " The PWM controls the amount of cement to pour as per the sensor readings.


this is the gist of the project it is a real world application that if it works will generate considerable sales.

so here is my issues

1) I've read the syntax manuals of several processors however the syntax manual posted on this site does not include interupt handling. I need this for the timing events of the reflective wave. I set the initialization of the sensor and wish to start a timer with a microsecond degree of accuracy. (one change in timer value = 1 micro second.) Does the nano18 support interupt handling with the same syntax as the pro series??? Also can any pin be used? and how does one set up a timer event on that interupt at a scale of microseconds???
2)I need to maintain a 5 volt output on the pwm I believe a change on the duty cycles will affect the average voltage however the individual pulses will still be 5 volts. However I have never programmed PWM to desired voltage levels and the syntax manual does not cover how to calculate what % of duration and duty cycle will yield a desired voltage\amperage level at a scaleble range.
as far as calculating the potentiometers deadband and span adjust this is fairly simple.
The sensor distance calculations are straight forward. to adjust to inches.

3) due to critical timing issues I also need an exact listing of number of clock cycles each instruction will take to execute. I recognize most of the common clock cycles to execute is 4 however could not find the number of clock cycles to execute a gosub or interupt handler to interupt sub routine. (enable interupt?
goto interupt subroutine? resume?) Is there a more detailed listing for the nano18??????

A major problem I have found for all the documentation is the assumption that these details will never be needed all the example I have come across in all the manuals I have read are limited. Trust me I have been an electronics\automation engineer for 22 years, that has worked with more name brands of products from PLC's to circuit and processor programming at assembly level than I care to mention. The main reason why we are using the basic Micro processors is several reasons.
1) programmmable in basic rather than assembly.
2) internal clock
3) switchable pin usage.
4) cost factor.

for the most part I am impressed in the basic micro series on its simplicity as compared to other programmable processors, there is a huge potential with this series of chips that makes developent for smaller companies cost effective,
The main issue our Company is having is the details of the documentation. We love the possible flexibility, However all the miniscule details are missing that are required to detailed engineering of advanced sysltems.
All the manuals give a simple example working with the manufacturer hardware such as LCD or serial and development board without any details to describe external or other name brand hardware. In some way it seems the processor and documentation is only geared for the hobbyist rather than the real world possible flexibilities. Every manual I've looked over goes from development board for input, outputs then an example of an LCD to an example of serial. Essentailly thats It. 1 example of setting a single range of PWM to linear voltage scale without any true description on how to calculate a desired PWM to desired voltage range to simulate a non linear waveform such as a sinusoidal waveform. or a varied waveform due other values such as this project. Any help on better documentation or examples related to this project would be greatly appreciated.


Top
 Profile  
 
 Post subject: Re: ultrasonic sensor controlling PWM output for paving truc
PostPosted: Mon Aug 23, 2010 9:08 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 788
Location: Temecula, CA
Send an email to nathan@basicmicro.com and I'll try to give you the info you want. However this is not easy. You will need to write your interrupt handler in PICmicro assembly code. If you don't think you can do that then I suggest moving to the AtomPro processors where you can write your entire interrupt handler in basic.

_________________
Nathan Scherdin
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: ultrasonic sensor controlling PWM output for paving truc
PostPosted: Wed Aug 25, 2010 12:53 pm 
Offline
Citizen

Joined: Tue Aug 10, 2010 3:42 pm
Posts: 15
main

init_signal var bit
counter var long
distance var word
deadband var word
span var word
duty var byte
duration var byte
distance_pulse var bit
range var word
dutypercentage var word
timer var word





israsm{
T1CON.BIT2=1
T1CON.BIT3 =1
T1CON.BIT4 =1
T1CON.BIT6 =1
BSF PIE1, TMR1IE ; Enable Timer1 interrup
bsf INTCON,7 ;GIE – Global interrupt enable (1=enable)
BANKSEL TMR1H
MOVLW 65535; Preload TMR1 register pair
BANKSEL TMR1L
MOVLW 2000
PIE1.bit0 = 1 ;unmask timer1 int
T1CON.bit0 = 1 ;timer1 starts counting
bcf PIR1,0 ;clear Timer1 interrupt flag

}
GIE = 1 ;enable all unmasked interrupt



looper;
init_signal = p0
pause 1000
adin p8,deadband
adin p9,span

high init_signal
if PIR1,0 =1 then
counter=counter+1 ;????? is this do-able????
PIR1,0 =0
endif

pause 700 ;hold init_signal for 700 ms
low init_signal
if in1=1 then
distance = TOINT (TOFLOAT(counter)/0.075);0.9 ft/ms return 0.075 per inch
gosub duty_calc
endif
duration =5000
pwm p12,255,duty,duration

duty_calc
deadband=deadband/16 ; convert deadband to inches
span=span/16 ;convert span to inches
if span<deadband then
range=0
endif
if deadband<span then
range=(span-deadband)
endif
if (distance < span+6) & (distance >deadband +6) then
dutypercentage = (distance/range)
duty=(255*(dutypercentage/100))
endif
endsub
goto looper
end

having trouble with this lol not only am I learning Mbasic with studio, many of the example codes I've come across on this forum do not work with the nano18, In particular with setting up a timer and running an interupt routine. we purchased the " programming the basic atam microcontroller. A large number of the commands do not function in regards to this problem.

Anyways neither here or there at this point.....

my problem here is how to get an interupt routine to work with the timer setup. I can see how to start the timer, how to prescale the timer to overflow. but where I am stuck on is how to go from the isram{} on interrupt and switch from asm to basic to increment.

There is probably lots of mistakes in this code still learning both lanquages but have been giving it a good shot. Any help would be appreciated.


Top
 Profile  
 
 Post subject: Re: ultrasonic sensor controlling PWM output for paving truc
PostPosted: Thu Aug 26, 2010 10:31 pm 
Offline
Master

Joined: Mon Jul 17, 2000 10:00 am
Posts: 155
Acidtech will get you squared away, so hang in there. We are working on a new manual. Take a look under Syntax Manual. Make sure you're on the latest Studio. The interrupts are the very next thing I'm about to document.

Also some of the code is old on the forums and changes have been made. At some point we are going to fix the code that we can and purge the rest.

Funny thing, I started off in the paving business, working on Basic Micro at night in my spare time.

_________________
Servo Controller - ARC32!


Top
 Profile  
 
 Post subject: Re: ultrasonic sensor controlling PWM output for paving truc
PostPosted: Wed Sep 08, 2010 3:12 pm 
Offline
Citizen

Joined: Tue Aug 10, 2010 3:42 pm
Posts: 15
Basic Micro wrote:
Acidtech will get you squared away, so hang in there. We are working on a new manual. Take a look under Syntax Manual. Make sure you're on the latest Studio. The interrupts are the very next thing I'm about to document.

Also some of the code is old on the forums and changes have been made. At some point we are going to fix the code that we can and purge the rest.

Funny thing, I started off in the paving business, working on Basic Micro at night in my spare time.



no problem Nathan is looking over the latest revision I beleive I almost have it set up and the customer is happy with the progress thus far, also recognizes that we have a large quantity of projects on the go.


Top
 Profile  
 
 Post subject: Re: ultrasonic sensor controlling PWM output for paving truc
PostPosted: Thu Sep 09, 2010 9:54 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 788
Location: Temecula, CA
yes, I got an email on this, but it went to my spam folder. it had no subject which apparently makes it look like spam. So in the future anyone emailing me make sure there is a subject.

I'll be working on an example for ISRASM as soon as I finish the new release.

_________________
Nathan Scherdin
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: ultrasonic sensor controlling PWM output for paving truc
PostPosted: Thu Sep 09, 2010 8:27 pm 
Offline
Citizen

Joined: Tue Aug 10, 2010 3:42 pm
Posts: 15
Acidtech wrote:
yes, I got an email on this, but it went to my spam folder. it had no subject which apparently makes it look like spam. So in the future anyone emailing me make sure there is a subject.

I'll be working on an example for ISRASM as soon as I finish the new release.



no problem thanks for taking the time.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO