and '3' comes from the datasheet in the ADCON1 register setting (register 11-2, page 128) ADCS2 table
and '3' comes from the datasheet in the ADCON1 register setting (register 11-2, page 128) ADCS2 table
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Thanks to all the reply.
I really appreciated it. I will try it at lab.
Actually, I would like to receive A/D input from solar PV and after that there are 2 things to be done.
First, IF the A/D input is less that 2 volt then stop the motor ELSE the motor activated.
Secondly, at the same time A/D input from the solar pv is sent to the computer for processing and collected the data for every 15 minute. The result will be calculated and show in graph.
It would need some knowledge of the visual basic as database and link between vb and ms excel.
Somebody can guide me thru this?? Thank and please give advice.
Hi,
Just compare the value you get from the ADC with the value that corresponds to 2V, if higher then run the motor, if lower then stop it, you can figure that out. You may need to introduce some hysteresis around the threshold.
Then send the value to the PC using the PBP's SEROUT command, or even better use the USART, a MAX232 level shifter and the HSEROUT command, see the manual. There's many examples on the forum.
For the PC/VB side have a look here: http://www.rentron.com/VisualBasic.htm
Just send the raw value from the PIC and use VB to scale it to volts if you like.
/Henrik Olsson.
I had try the program that you gave me. It is work.Thank.
Some problem has finding out....
***********'Produce squarewave on PortB.0 period~4.32s, 50% dutycycle.
Loop var Word
Main:
High PortB.0
For Loop = 0 to 2160 'Loop here for ~2.16s, tweak to match.
PauseUs 1000
Next
Low PortB.0
For Loop = 0 to 2160 'Loop here for ~2.16s, tweak to match.
PauseUs 1000
Next
Goto Main**********
The above is the code that you posted to me. Thanks to you again.
I had modify it like the code below:-
********'Produce squarewave on PortB.0 period~4.32s, 50% dutycycle.
Loop var Word
SolarVoltage var word
ADCON1 = %10001110
Main:
High PortB.0
For Loop = 0 to 2160 'Loop here for ~2.16s, tweak to match.
PauseUs 1000
ADCIN 0,SolarVoltage
LCDOUT $FE,$1,#SolarVoltage
If SolarVoltage = 300 then
high motor ' motor stop
ELSE
low motor ' motor run
ENDIF
If update = 1 then
LCDOUT $FE,$C0,DEC2 Hour,":",DEC2 Minute,":",DEC2 Second
ENDIF
Next
Low PortB.0
For Loop = 0 to 2160 'Loop here for ~2.16s, tweak to match.
PauseUs 1000
ADCIN 0,SolarVoltage
LCDOUT $FE,$1,#SolarVoltage
If SolarVoltage = 300 then
high motor ' motor stop
ELSE
low motor ' motor run
ENDIF
If update = 1 then
LCDOUT $FE,$C0,DEC2 Hour,":",DEC2 Minute,":",DEC2 Second
ENDIF
Next
Goto Main
ON INTERRUPT
'
'Time calculation
'
'
Update = 1 'update diaplay after 1 second*************
The display: ****************
0 ' when increase the A/D input, the value
00:00:00 'increase to 0 then 1 then 2 then
**************** 'maximum is 3
Hi,
Yes, you are correct, that will never work.
A couple of things.
1) The timing to produce the pulses to the motor is depending on the For Next loop and the PauseUS. When you insert a whole lot of other commands in there the timing will be WAY off. For example, the ADCIN alone will take at least 50uS, remember the DEFINE ADC_SAMPLEUS 50 then comes the LCDOUT which will take a "lot" of time also.
Do you need the LCD to update 1000 times / second? That is what it's trying to do since you put it inside the FOR-NEXT loop.
2) It is the For Next loop that pulses the step line to the motor. What are you trying to do with the high motor, low motor? Do you have an enable signal to the motordriver that is mapped to motor
3) There's code missing in the INTERRUPT routine and the ON INTERRUPT statement should be at the beggining of the program with a LABEL telling it where to jump when an interrupt occurs.
4) The ADC DEFINES are missing.
5) The TRIS register set-up are missing.
6) The motor variable(??) declaration is missing.
7) You are checking if the SolarVoltage varible is equal to 300, so even if all the rest where OK the motor would only run when the value was exacly 300. You need to check if it's higher than 300.
This is probably not the best way to this now that you are adding more and more stuff to it but it may get you going if you have decided to go this route instead of the interrupt and tick counting we also showed you.
Again, this is completely untested! You will probably need to tweak the 2160 value in the For Next loop a little bit to get the correct timing.
When you post code please include comments so that it's easier for us to understnad what you're trying to do. Also, please see the vbCode page here: http://www.picbasic.co.uk/forum/misc.php?do=bbcode for how to post code so that it shows in a window like above.Code:Loop var Word 'Loop variable for the FOR-NEXT loop SolarVoltage var word 'Raw value from ADC RunMotor var bit 'Enable bit for step pulse routine. DEFINE ADC_BITS 10 'Set ADC to produce 10bits DEFINE ADC_CLOCK 3 'Set ADC clock to internal RC DEFINE ADC_SAMPLEUS 50 'Set conversion time to 50uS TRISA.0 = 1 'Set RA0 (pin2) to input. TRISB.0 = 0 'Set RB0 as output, step pulse to motor. ADCON1 = %10001110 'Set RA0 to analog, internal Vref, result right justified. (See datasheet) RunMotor = 0 'Do NOT run motor Main: '//The IF statement here checks the flag to determine if the motor should be run or not. '// If it should be run the For-Next loop is executed. If RunMotor = 1 then 'Produce pulses ONLY if supposed to.... High PortB.0 For Loop = 0 to 2160 'Loop here for ~2.16s, tweak to match. PauseUs 1000 Next Low PortB.0 For Loop = 0 to 2160 'Loop here for ~2.16s, tweak to match. PauseUs 1000 Next Endif ADCIN 0, SolarVoltage 'Get value from solarPV LCDOUT $FE,$1,#SolarVoltage 'Display value on LCD '// Here you can insert the code for sending to PC // '// and the LCD code for the time, if that's what your doing // If SolarVoltage > 300 then 'We are over the thershold RunMotor = 1 'so lets enable the step pulses Goto Main 'and start over Else RunMotor = 0 'disable the ste pulses. '// Since the For-next loop that produces the step pulses is not running now we insert a pause here. '// Otherwise the ADCIN and LCDOUT statements will execute VERY often. For Loop = 1 to 1000 PauseUs 1000 Next Goto Main
/Henrik Olsson.
Last edited by HenrikOlsson; - 14th December 2006 at 08:57.
If I doesnt want to use external eeprom and I had used up all the internal eeprom space. As I know there was a way to store the data in the program like below:-
asm:
da:1,2,23
endasm
I do not familiar with this could any one one lead me thru this method? Thank
I just want to store 200 data in there.
Thanks
Bookmarks